I don't get it. version(unittest) can't seem to use local variable

dysmondad via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 12 19:35:11 PDT 2014


.....
>
> try:
>
> unittest {
>       Velocity v = new Velocity( 2.0f, 5.0f );
>       v *= 5.0f;  // <- line 110
>       printf( "v = %s\n", to!string(v) );
> }
>
> instead. Basically version is like static if, it doesn't 
> indicate its a function. Instead it changes what code gets 
> compiled.
> Where as a unittest block, is essentially just a function that 
> gets called at a special time, that is only compiled as if 
> version(unittest) was also used.

Thank you very much. That was quite helpful.

So, what is the generally accepted way include unit testing? TDD 
is all the rage these days and I though I would try my hand at it 
as well as D.


More information about the Digitalmars-d-learn mailing list