Unit tests called multiple times?

John Colvin john.loughran.colvin at gmail.com
Sat Apr 13 02:01:05 PDT 2013


On Friday, 12 April 2013 at 23:01:55 UTC, Steven Schveighoffer 
wrote:
> On Fri, 12 Apr 2013 18:52:50 -0400, William 
> <squidkidsignup at gmail.com> wrote:
>
>> I'm compiling a medium-sized project written in D with the 
>> -unittests flag.  I have some writeln statements in my unit 
>> tests, for debug purposes, and I've noticed that certain unit 
>> tests are being run more than once.  Sample output is along 
>> these lines:
>>
>> DEBUG: unit test started...
>> DEBUG: loop found whatever
>> DEBUG: iteration successful
>> DEBUG: bar is equal to bar
>> DEBUG: unit test passed...
>> DEBUG: unit test started...
>> DEBUG: loop found whatever
>> DEBUG: iteration successful
>> DEBUG: bar is equal to bar
>> DEBUG: unit test passed...
>> DEBUG: unit test started...
>> DEBUG: loop found whatever
>> DEBUG: iteration successful
>> DEBUG: bar is equal to bar
>> DEBUG: unit test passed...
>>
>> is this standard behavior for DMD?  Is it documented anywhere?
>>  It's not much of a problem, but it strikes me as rather odd, 
>> and makes the debug output difficult to read.
>
> Are your unit tests inside templates?  If so, they are 
> instantiated once per template.  To fix, move outside the 
> template.
>
> This actually can be a nice feature, and at the same time 
> horrible.  It's nice because you can parameterize your unit 
> tests!  It's horrible because you have to be careful your unit 
> tests are valid for all possible instantiations!
>
> -Steve

That's a really nice feature. By running the unittests a 
developer could verify that there isn't a latent bug in the 
library code revealed by their particular types (or a bug in 
their types of course). If we could leverage this more then bugs 
in phobos could be identified quicker.


More information about the Digitalmars-d mailing list