static unittest

Atila Neves via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 30 10:17:05 PDT 2014


On Wednesday, 30 April 2014 at 17:03:58 UTC, Atila Neves wrote:
> On Wednesday, 30 April 2014 at 16:57:13 UTC, Meta wrote:
>> On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei 
>> Alexandrescu wrote:
>>> Walter and I also discussed "static unittest" a while ago - 
>>> yes, another use of static :o).
>>>
>>> A static unittest would be evaluated only during compilation, 
>>> and would prove things that fall in the realm of static 
>>> checking but are not verifiable with traditional typesystem 
>>> approach.
>>>
>>> That won't enable things we can't do today (there's always 
>>> assert(__traits(compiles, ...)) but it's instantly 
>>> recognizable, very easy to use, and pushes semantic checking 
>>> to a whole new level.
>>>
>>> Thoughts?
>>>
>>>
>>> Andrei
>>
>> There's also
>>
>> unittest
>> {
>>    static assert(...);
>> }
>
> I've been doing this a lot lately. Since I wrote a unit test 
> library I use that for all my unit tests, but the compilation 
> ones are usually implementation details that don't need 
> external tests. I started adding static asserts to the file 
> that needed them but got lost in what was implementation and 
> what was a test so I started wrapping all the static asserts in 
> unittest blocks. Works for me.
>
>
>
> Atila

Having said that, I did think (and probably will) of writing a 
staticEquals for unit-threaded so at least I don't have to keep 
building up the string to print out for myself every time.

Atila


More information about the Digitalmars-d mailing list