Unit tests in D

Walter Bright newshound1 at digitalmars.com
Wed May 5 11:15:05 PDT 2010

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.

More information about the Digitalmars-d mailing list