Skip to content

Commit 7fbdbb6

Browse files
authored
Improve checkpoint output at comptime (#60)
1 parent 8b51e99 commit 7fbdbb6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

unittest2.nim

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ var
270270
## immediately on fail. Default is false,
271271
## or override with `-d:nimUnittestAbortOnError:on|off`.
272272

273+
checkpointsVm {.compileTime.}: seq[string]
273274
checkpoints {.threadvar.}: seq[string]
274275
formatters {.threadvar.}: seq[OutputFormatter]
275276
testsFilters {.threadvar.}: HashSet[string]
@@ -1010,10 +1011,8 @@ template checkpoint*(msg: string) =
10101011
##
10111012
## outputs "Checkpoint A" once it fails.
10121013
when nimvm:
1013-
when compiles(testName):
1014-
echo testName
1015-
1016-
echo msg
1014+
{.cast(gcsafe).}:
1015+
checkpointsVm.add msg
10171016
else:
10181017
bind checkpoints
10191018

@@ -1035,6 +1034,11 @@ template fail* =
10351034
## outputs "Checkpoint A" before quitting.
10361035
when nimvm:
10371036
echo "Tests failed"
1037+
{.cast(gcsafe).}:
1038+
for msg in items(checkpointsVm):
1039+
echo(" ")
1040+
echo(msg)
1041+
echo("\n")
10381042
quit 1
10391043
else:
10401044
testStatus = TestStatus.FAILED
@@ -1067,7 +1071,8 @@ template skip* =
10671071
## if not isGLContextCreated():
10681072
## skip()
10691073
when nimvm:
1070-
discard
1074+
{.cast(gcsafe).}:
1075+
reset checkpointsVm
10711076
else:
10721077
bind checkpoints
10731078

@@ -1177,6 +1182,8 @@ template staticTest*(nameParam: string, body: untyped) =
11771182
echo "[Test ] ", nameParam
11781183
body
11791184
echo "[", TestStatus.OK, " ] ", nameParam
1185+
{.cast(gcsafe).}:
1186+
reset checkpointsVm
11801187

11811188
template dualTest*(nameParam: string, body: untyped) =
11821189
## Similar to `test` but run the test both compuletime and run time, no

0 commit comments

Comments
 (0)