www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Proposal: static unittest

Since CTFE (Compile-time function evaluation) can only be tested by 
running a program or writing a bunch of static asserts, maybe it would 
be nice, instead of writing lots of static asserts, to be able to write 
a "static unittest" block. The static unittest blocks are executed at 
compile time (if they can't be, isue an error) and allow writing 
"assert" instead of "static assert" inside them (same as in templates 
you can write "foreach" instead of "static foreach").

More explicitly, instead of writing

static assert (myFunc!("bla1") == "ble2");
static assert (myFunc!("bla3") == "ble4");
static assert (myFunc!("bla5") == "ble6");

you could write:

static unittest {
     assert(myFunc!("bla") == "ble2");
     assert(myFunc!("bla3") == "ble4");
     assert(myFunc!("bla5") == "ble6");

Less typing, clearer intention. And the block can contain not only 
asserts, but any code that can be executed at compile time.
Apr 04 2007