unittest

Sean Kelly sean at f4.ca
Sun Dec 2 14:12:25 PST 2007


BCS wrote:
> Reply to Sean,
> 
>> Given the dual use of "invariant" in D 2.0, I was thinking it might be
>> useful to do the something similar with "unittest".  Make it
>> equivalent to "version(unittest)" and be enabled when -unittest was
>> specified during compilation.  This seems a rather natural extension
>> of the keyword and the semantics would be nearly identical to how
>> "invariant" works right now:
>>
>> unittest int x; // single declaration enabled on -unittest unittest
>> int fn() {} // function compiled on -unittest
>>
>> unittest // everything in the block compiled on -unittest
>> {
>> import std.stdio;
>> int y;
>> void f2() {}
>> }
>> unittest() // unit test function, similar to invariant()
>> {
>> writefln( "hello" );
>> }
>> As an added bonus, this would regain consistency with the invariant
>> function, which has been bugging me since its adoption for use with
>> const.
> 
> an interesting idea, I can't say I'm totally for it, but I'd like to see 
> it considered.

Right now, Tango uses "version(UnitTest)" for this purpose but it would 
be nice to have some actual language support for this.  Though I'll 
admit my real motivation is to try and regain some consistency with 
"invariant" and "unittest" in D 2.0.  It doesn't seem likely that the 
words used for const features will change, so...


Sean



More information about the Digitalmars-d mailing list