0
|
1 module dmd.UnitTestDeclaration;
|
|
2
|
|
3 import dmd.FuncDeclaration;
|
|
4 import dmd.Loc;
|
|
5 import dmd.Dsymbol;
|
|
6 import dmd.AggregateDeclaration;
|
|
7 import dmd.OutBuffer;
|
|
8 import dmd.HdrGenState;
|
|
9 import dmd.Type;
|
|
10 import dmd.Scope;
|
|
11 import dmd.Global;
|
|
12 import dmd.LINK;
|
|
13 import dmd.TypeFunction;
|
|
14 import dmd.Module;
|
|
15 import dmd.STC;
|
|
16 import dmd.Lexer;
|
|
17 import dmd.Identifier;
|
|
18
|
|
19 /*******************************
|
|
20 * Generate unique unittest function Id so we can have multiple
|
|
21 * instances per module.
|
|
22 */
|
|
23 Identifier unitTestId()
|
|
24 {
|
|
25 return Lexer.uniqueId("__unittest");
|
|
26 }
|
|
27
|
|
28 class UnitTestDeclaration : FuncDeclaration
|
|
29 {
|
|
30 this(Loc loc, Loc endloc)
|
|
31 {
|
|
32 super(loc, endloc, unitTestId(), STC.STCundefined, null);
|
|
33 }
|
|
34
|
|
35 Dsymbol syntaxCopy(Dsymbol s)
|
|
36 {
|
|
37 UnitTestDeclaration utd;
|
|
38
|
|
39 assert(!s);
|
|
40 utd = new UnitTestDeclaration(loc, endloc);
|
|
41
|
|
42 return FuncDeclaration.syntaxCopy(utd);
|
|
43 }
|
|
44
|
|
45 void semantic(Scope sc)
|
|
46 {
|
|
47 if (global.params.useUnitTests)
|
|
48 {
|
|
49 type = new TypeFunction(null, Type.tvoid, false, LINKd);
|
|
50 Scope sc2 = sc.push();
|
|
51 sc2.linkage = LINK.LINKd;
|
|
52 FuncDeclaration.semantic(sc2);
|
|
53 sc2.pop();
|
|
54 }
|
|
55
|
|
56 // We're going to need ModuleInfo even if the unit tests are not
|
|
57 // compiled in, because other modules may import this module and refer
|
|
58 // to this ModuleInfo.
|
|
59 Module m = getModule();
|
|
60 if (!m)
|
|
61 m = sc.module_;
|
|
62 if (m)
|
|
63 m.needmoduleinfo = 1;
|
|
64 }
|
|
65
|
|
66 AggregateDeclaration isThis()
|
|
67 {
|
|
68 assert(false);
|
|
69 }
|
|
70
|
|
71 bool isVirtual()
|
|
72 {
|
|
73 assert(false);
|
|
74 }
|
|
75
|
|
76 bool addPreInvariant()
|
|
77 {
|
|
78 assert(false);
|
|
79 }
|
|
80
|
|
81 bool addPostInvariant()
|
|
82 {
|
|
83 assert(false);
|
|
84 }
|
|
85
|
|
86 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
87 {
|
|
88 assert(false);
|
|
89 }
|
|
90
|
|
91 UnitTestDeclaration isUnitTestDeclaration() { return this; }
|
|
92 } |