www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - unittest

reply Sean Kelly <sean f4.ca> writes:
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.


Sean
Dec 01 2007
parent reply BCS <ao pathlink.com> writes:
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.
 
 Sean
 
an interesting idea, I can't say I'm totally for it, but I'd like to see it considered.
Dec 02 2007
parent Sean Kelly <sean f4.ca> writes:
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
Dec 02 2007