Static unittests?

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Aug 5 07:24:23 PDT 2013


On 8/5/13, Bosak <bosak at gmail.com> wrote:
> Are compile-time unittests possible in D? Maybe something like:
>
> static unittest {
>      assert(2 == 1 + 1);
> }

Nope.

Interestingly, in git-head we now have the getUnitTests trait, however
this won't allow us to call the tests at compile time, I get back:

Error: __unittestL5_1 cannot be interpreted at compile time, because
it has no available source code

This trait is fairly new, so maybe we could expand on this to allow
invoking the tests at compile time.

Note of course that fundamentally not all tests can be executed at
compile-time (e.g. any kind of use of files makes them non-CTFE-able)


More information about the Digitalmars-d mailing list