[phobos] Silent failure of std.container unittests

Leandro Lucarella luca at llucax.com.ar
Fri Jul 16 06:32:03 PDT 2010


Sean Kelly, el 15 de julio a las 19:52 me escribiste:
> 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");
>         ...
>     }

check() check() check()! =)

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
No existiría el sonido del mar si faltara en la vida oreja y caracol.
        -- Ricardo Vaporeso. Cosquín, 1908.


More information about the phobos mailing list