[dmd-internals] changeset 455

Sean Kelly sean at invisibleduck.org
Mon May 3 16:51:56 PDT 2010


On May 3, 2010, at 4:11 PM, Andrei Alexandrescu wrote:
> 
>> 2. many asserts are not meant at all to be unit tests, and there's no reason to think otherwise when they are outside the unittest block
> 
> I guess but I have the feeling you are taking a couple of wrong turns that reflect lack of experience with unittests.
> 
> 1. A failing unittest only prints and continues
> 
> 2. Top-level asserts are different from other asserts
> 
> I'm not claiming to be an expert in unittesting but from what I know from other unittest facilities, I believe the following is the correct behavior:
> 
> 1. A failing unittest means that particular unittest is terminated immediately and counted as "failed" exactly once. A failed unittest has an identity, you can't say "this unittest has failed 3 times in the following places".
> 
> 2. unittest-level assert and any-level assert are the same deal. It's basic (de)composability and what anyone expects since the invention of the stack.
> 
> Please let's not introduce odd behavior unless we're based on something.

I'm unsure about the current behavior with asserts.  On the one hand I agree with you, on the other I see the unittest-level asserts as a way of reporting a case failure, so it may be reasonable to just continue.  However, perhaps "assert" isn't the best candidate for both operations.

What I would like in terms of continuing after a unittest failure is:

    void op() { assert( false ); }

    unittest // test 1
    {
        op(); // terminates the current test    
    }

    unittest // test 2
    {
        // this test is run even though the one above fails
    }

Then I think we'd see a bunch of small unittest blocks per module, each testing an individual thing.  If there are multiple tests in one block then the user is declaring that if any of the tests in the block fail, he doesn't want the rest to be executed.  So you might do:

    unittest
    {
        loadThingToTest();
        runTestIfLoadedA();
        runTestIfLoadedB();
        ...
    }


More information about the dmd-internals mailing list