safe pure unittest

simendsjo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 13 06:03:14 PDT 2014


On 08/13/2014 02:50 PM, Dicebot wrote:
> On Wednesday, 13 August 2014 at 12:26:02 UTC, simendsjo wrote:
>> This is the first time I've seen attributes on unittests:
>> https://github.com/D-Programming-Language/phobos/pull/2349/files#diff-ba05e420ac1da65db044e79304d641b6R179
>>
>>
>> Has this always been supported? I guess it's good practice to add these
>> on unittests too, but does people even know about this feature? And are
>> there any cons to doing this?
> 
> unittest block is effectively just a special function declaration so all
> function attributes are applicable and act in a similar way.
> 
> It is an extremely important idiom when you wan't to ensure specific
> properties of templated function that may be valid or not depending on
> template arguments. For example, function with output range may be @nogc
> or not depending if used output range type triggers GC. But you can mark
> with @nogc unittest that uses it with dummy output range to ensure that
> _nothing else_ allocated.

Thanks.

The unittest documentation notes that unittests are functions in one of
the sentences, but nothing regarding attributes (except for private) is
mentioned: http://dlang.org/unittest.html


More information about the Digitalmars-d-learn mailing list