[phobos] Silent failure of std.container unittests
Sean Kelly
sean at invisibleduck.org
Thu Jul 15 19:52:33 PDT 2010
On Jul 15, 2010, at 5:04 PM, Andrei Alexandrescu wrote:
> On 07/15/2010 06:59 PM, Benjamin Shropshire wrote:
>> Beside, I don't now nor will I ever care about ANYTHING after the first
>> failed assert in any given block.
>
> Walter, it would be great if you could substantiate some concrete examples by pasting from your tests. Thanks!
I've been thinking about this, and I realized that I'd really like different behaviors for different types of tests. For testing stateless code, the most convenient thing would be Walter's behavior. For stateful code, throwing on error is preferable, since once the state is invalid further testing is useless. I wondered whether one could argue that with testing stateful code, when something fails an exception would likely be thrown from inside the object and abort the test anyway, but I think this isn't true. For boundary testing, I'd typically want to ensure that AssertErrors were thrown when a contract was violated, etc, so I'm still likely to do something like:
unittest {
auto o = MyObject;
assert(throws!AssertError(o.divide(1,0)));
...
}
It wouldn't be terribly onerous to me to break stateless tests into multiple unittest blocks, but it's probably more readable to simply have:
unittest {
verify(sort("bac") == "abc");
verify(sort("bba") == "abb");
...
}
So I'm really ambivalent beyond thinking that assert should always throw, since this should never result in undesirable behavior (reporting a test failure then a following test segfaulting).
More information about the phobos
mailing list