Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (57 sloc) 1.53 KB
$(GNAME UnitTest):
$(B unittest) $(I FunctionBody)
$(P Unit tests are a series of test cases applied to a module to determine
if it is working properly. Ideally, unit tests should be run every
time a program is compiled.
$(P Unit tests are a special function defined like:)
...test code...
$(P There can be any number of unit test functions in a module,
including within struct, union and class declarations.
They are executed in lexical order.
Stylistically, a unit test for a function should appear immediately
following it.
$(P A compiler switch, such as $(LINK2 dmd-windows.html#switches, $(B -unittest))
for $(B dmd), will
cause the unittest test code to be compiled and incorporated into
the resulting executable. The unittest code gets run after
static initialization is run and before the $(TT main())
function is called.
$(P For example, given a class Sum that is used to add two values:)
class Sum
int add(int x, int y) { return x + y; }
Sum sum = new Sum;
assert(sum.add(3,4) == 7);
assert(sum.add(-2,0) == -2);
$(P The $(LINK2 version.html#PredefinedVersions, version identifier)
$(B unittest) is predefined if the compilation
is done with unit tests enabled.
TITLE=Unit Tests
GLINK=$(LINK2 #$0, $(I $0))
GNAME=<a name=$0>$(I $0)</a>