Static unittests?

monarch_dodra monarchdodra at gmail.com
Mon Aug 19 10:44:54 PDT 2013


On Sunday, 18 August 2013 at 20:35:06 UTC, Walter Bright wrote:
> On 8/5/2013 11:27 AM, monarch_dodra wrote:
>> What about, for example:
>>
>> assertCTFEable!({
>>     int i = 5;
>>     string s;
>>     while (i--)
>>         s ~= 'a';
>>     assert(s == "aaaaa");
>> });
>
> I don't believe that is a valid use case because the code being 
> tested is not accessible from anything other than the test.

I'm not sure what that means. Isn't that the case of all unittest?

In any case, I was just saying the above template was enough for 
our needs, and that I don't think a language solution is in 
order. Also, I think the:

//----
unittest
{
     void dg()
     {
         BODY OF UNITTEST
     }
     dg(); //test runtime
     assertCTFEable!dg; //test compiletime
}
//----

usecase makes it useful. Although arguably, you could just:

//----
unittest
{
     bool dg()
     {
         BODY OF UNITTEST
         return true;
     }
     dg(); //test runtime
     enum a = dg();
     or
     static assert(dg);
}
//----

But really, I'm just saying why type that when the template does 
it pretty well for us, while being self-docuenting?


More information about the Digitalmars-d mailing list