Skip to content

Commit 051150a

Browse files
authored
Merge pull request #2436 from wilzbach/betterc-unittest
Document how to run unittests in -betterC merged-on-behalf-of: Jacob Carlborg <jacob-carlborg@users.noreply.github.com>
2 parents 23d880b + af7ef73 commit 051150a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spec/betterc.dd

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,34 @@ $(H2 $(LNAME2 retained, Retained Features))
8282
$(LI COM classes and C++ classes)
8383
$(LI `assert` failures are directed to the C runtime library)
8484
$(LI `switch` with strings)
85+
$(LI `unittest`)
8586
)
8687

88+
$(H3 $(LNAME2 unittests, Running unittests in `-betterC`))
89+
90+
While, testing can be done without the $(TT -betterC) flag, it is sometimes desirable to run the testsuite in `-betterC` too.
91+
`unittest` blocks can be listed with the $(DDSUBLINK spec/traits, getUnitTests, `getUnitTests`) trait:
92+
93+
---
94+
unittest
95+
{
96+
assert(0);
97+
}
98+
99+
extern(C) void main()
100+
{
101+
static foreach(u; __traits(getUnitTests, __traits(parent, main)))
102+
u();
103+
}
104+
---
105+
106+
$(CONSOLE
107+
> dmd -betterC -unittest -run test.d
108+
dmd_runpezoXK: foo.d:3: Assertion `0' failed.
109+
)
110+
111+
However, in `-betterC` `assert` expressions don't use Druntime's assert and are directed to `assert` of the C runtime library instead.
112+
87113
$(H2 $(LNAME2 consequences, Unavailable Features))
88114

89115
$(P D features not available with $(B BetterC):)
@@ -98,7 +124,6 @@ $(OL
98124
$(LI `final switch`)
99125
$(LI `synchronized` and $(MREF core, sync))
100126
$(LI Static module constructors or destructors)
101-
$(LI `unittest` (testing can be done without the $(TT -betterC) flag))
102127
)
103128

104129

0 commit comments

Comments
 (0)