Static unittests?

monarch_dodra monarchdodra at gmail.com
Mon Aug 5 10:30:37 PDT 2013


On Monday, 5 August 2013 at 17:13:52 UTC, Dicebot wrote:
> On Monday, 5 August 2013 at 16:50:12 UTC, monarch_dodra wrote:
>> 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.
>
> Considering your, example, you can always do `static 
> assert(to!string(1uL << 62) == "4611686018427387904");`
>
> What is the crucial difference?

Well, the "crucial" difference is that this tests a single 
expression, and not an entire block. For example, the simple test 
that int.init is 0:

static assert({int i; assert(i == 0;});

This doesn't work. You'd have to write:
static assert({int i; assert(i == 0; return 1;}());
or
static assert({int i; assert(i == 0);}(), 1);

Both of which are a bit combersome. "assertCTFEable" allows 
testing that the *block* will actually will compile and ctfe run 
conveniently.


More information about the Digitalmars-d mailing list