forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittest.dd
67 lines (52 loc) · 1.41 KB
/
unittest.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Ddoc
$(SPEC_S Unit Tests,
$(GRAMMAR
$(GNAME UnitTest):
$(B unittest) $(GLINK2 function, 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:)
------
unittest {
...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 $(DPLLINK 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 $(D 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; }
unittest
{
Sum sum = new Sum;
assert(sum.add(3,4) == 7);
assert(sum.add(-2,0) == -2);
}
}
------
<h3>Versioning</h3>
$(P The $(DDSUBLINK version, PredefinedVersions, version identifier)
$(B unittest) is predefined if the compilation
is done with unit tests enabled.
)
)
Macros:
TITLE=Unit Tests
WIKI=UnitTests
CATEGORY_SPEC=$0
FOO=