Unit tests in D

Lutger lutger.blijdestijn at gmail.com
Wed May 5 12:49:48 PDT 2010


Walter Bright wrote:

> bearophile wrote:
>> Walter Bright:
>>> But why? Just use: foo(10);
>> 
>> I think you are missing something important here.
>> 
>> Static asserts (or other implicit errors) inside a template, etc, test
>> that some input types are correct, some template input values are in the
>> correct range, etc.
>> 
>> In this thread we are talking about unittests. The purpose of a unit
>> Inside a unit test is to test that something that can be called Foo works
>> as specified. Working as specified means such Foo must return the correct
>> outputs when the inputs are in its intended range of possible inputs
>> (otherwise the unittest has to fail), and it must produce a compile time
>> assert, run time assert, or throw an exception if the input values are
>> outside the allowed ones (otherwise the unittest has to fail again).
>> 
>> So the purpose of the feature I am talking here is for the group of those
>> unittests, to make sure something asserts at compile time (or otherwise
>> doesn't compile) when the compile-time inputs are wrong.
>> 
>> So I need something that inside the unittest asserts at compile time if
>> Foo does not asserts at compile-time (or otherwise refuses to work).
> 
> I'm sorry, I simply don't understand this. If you want to test that
> something compiles in a unit test, just write the code. The compiler will
> let you know if it doesn't compile.

He wants the opposite: to test that something detects an error correctly, 
making sure his template doesn't silently compile wrong code. 




More information about the Digitalmars-d mailing list