Unit tests in D
Michel Fortin
michel.fortin at michelf.com
Wed May 5 11:24:25 PDT 2010
On 2010-05-05 14:04:13 -0400, Walter Bright <newshound1 at digitalmars.com> said:
> bearophile wrote:
>> I have to use a syntax like this often enough inside
>> unittests:
>>
>> static assert(!__traits(compiles, foo(10)));
>
> But why? Just use:
>
> foo(10);
To put it more simply than bearophile:
foo(10);
// gives you an error when foo(10) does *not* compile
static assert(!__traits(compiles, foo(10)));
// gives you an error when foo(10) compiles with no error
// (notice the negation operator "!")
It is sometime a good idea to assert that a template cannot be
instantiated with bogus arguments.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list