Skip to content

Commit ff17fb1

Browse files
committed
support nested comptime test
1 parent 8b51e99 commit ff17fb1

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

tests/tunittest.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ suite "bug #5784":
184184
var obj: Obj
185185
check obj.isNil or obj.field == 0
186186

187+
suite "PR #59":
188+
staticTest "Nested test":
189+
test "inner test":
190+
checkpoint "foobar"
191+
check 1 == 1
192+
193+
staticTest "Nested static test":
194+
staticTest "inner test":
195+
checkpoint "foobar"
196+
check 1 == 1
197+
198+
dualTest "Nested dual test":
199+
dualTest "inner test":
200+
checkpoint "foobar"
201+
check 1 == 1
202+
187203
type
188204
SomeType = object
189205
value: int

unittest2.nim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,6 @@ template checkpoint*(msg: string) =
10101010
##
10111011
## outputs "Checkpoint A" once it fails.
10121012
when nimvm:
1013-
when compiles(testName):
1014-
echo testName
1015-
10161013
echo msg
10171014
else:
10181015
bind checkpoints
@@ -1181,12 +1178,14 @@ template staticTest*(nameParam: string, body: untyped) =
11811178
template dualTest*(nameParam: string, body: untyped) =
11821179
## Similar to `test` but run the test both compuletime and run time, no
11831180
## matter the `unittest2Static` flag
1184-
staticTest nameParam:
1185-
when not unittest2ListTests:
1186-
body
1187-
runtimeTest nameParam:
1188-
when not unittest2ListTests:
1189-
body
1181+
when nimvm:
1182+
staticTest nameParam:
1183+
when not unittest2ListTests:
1184+
body
1185+
else:
1186+
runtimeTest nameParam:
1187+
when not unittest2ListTests:
1188+
body
11901189

11911190
template test*(nameParam: string, body: untyped) =
11921191
## Define a single test case identified by `name`.
@@ -1207,9 +1206,10 @@ template test*(nameParam: string, body: untyped) =
12071206
staticTest nameParam:
12081207
when not unittest2ListTests:
12091208
body
1210-
runtimeTest nameParam:
1211-
when not unittest2ListTests:
1212-
body
1209+
else:
1210+
runtimeTest nameParam:
1211+
when not unittest2ListTests:
1212+
body
12131213

12141214
{.pop.} # raises: []
12151215

0 commit comments

Comments
 (0)