On Sunday, 18 August 2013 at 16:15:30 UTC, Borislav Kosharov
wrote:
On Saturday, 17 August 2013 at 17:48:04 UTC, Andrej Mitrovic
wrote:
On 8/17/13, Borislav Kosharov <[email protected]> wrote:
I really think that this should be added to the language,
because
it doesn't break stuff and it is useful. And the 'static'
keyword
is already used in many places like module imports and ifs.
Have you tried using the new getUnitTests trait in the git-head
version? If not it will be in the 2.064 release.
Btw such a 'static unittest' feature is certainly going to
break code
because static can be applied as a label, for example:
class C
{
static:
void foo() { }
unittest { /* Test the foo method. */ } // suddenly
evaluated at
compile-time
}
Oh I really haven't tough about that. Maybe, I will try this
new trait. Or another solution is to add a compiler switch that
will try to execute all the tests during compilation or
something.
Well, that assumes all your code is ctfe-able...
I've taken to doing something along the line of:
unittest
{
void dg()
{
BODY OF UNITTEST
}
dg(); //test runtime
assertCTFEable!dg; //test compiletime
}
It's a quick and easy way of testing both code paths, with
minimal duplication and hassle.