[dmd-internals] changeset 455
Walter Bright
walter at digitalmars.com
Mon May 3 13:45:12 PDT 2010
Sean Kelly wrote:
>
> I think the current behavior is a good first step, but should probably be modified a bit further. For example:
>
> void fnA()
> {
> assert( false, "fnA 1" );
> assert( false, "fnA 2 ");
> }
>
> unittest
> {
> assert( false, "unittest 1" );
> assert( false, "unittest 2" );
> fnA();
> }
>
> unittest
> {
> assert( false, "unittest 3" );
> }
>
> void main()
> {
>
> }
>
> Running this will print:
>
> test.d(9): unittest 1
> test.d(10): unittest 2
> core.exception.AssertError at test.d(3): fnA 1
>
> So if an assert error occurs inside some code being tested, the app will still exit.
No, if an assert occurs lexically outside of a unittest block, the
regular assert failure code will be called.
> I tried modifying the unit testing code to eat the exception and continue, but then it simply prints:
>
> test.d(9): unittest 1
> test.d(10): unittest 2
>
> So the best we can currently do is move on to test another module--there's no way to execute the remaining unit tests within the module. Could we perhaps have an array of unittests within the ModuleInfo struct instead of just a single function pointer? Or is the rationale really that if implementation code throws, the app should assume it's in an invalid state and exit?
>
It's simpler than that. The idea is if an assert fails within a unittest
block, the unittests should continue. If an assert fails outside, then
the app should stop.
More information about the dmd-internals
mailing list