Static unittests?

monarch_dodra monarchdodra at gmail.com
Mon Aug 5 09:50:11 PDT 2013


On Monday, 5 August 2013 at 14:02:06 UTC, Dicebot wrote:
> Use case?

The use case is simply checking that your functions can be 
CTFE'd, and that they produce the correct result.

> Not right now at the very least.

std.exception defines the package "assertCTFEable".

It allows code such as:
unittest
{
     assertCTFEable!(
     {
         assert(to!string(1uL << 62) == "4611686018427387904");
         assert(to!string(0x100000000) == "4294967296");
         assert(to!string(-138L) == "-138");
     });
}

If this code does not run at CTFE, then a static assert triggers.

This is currently "package", but it proves that what you asked 
for is not only possible, it is implemented *and* used in phobos.

So either duplicate locally, or file an ER to make it public I 
guess.


More information about the Digitalmars-d mailing list