summary refs log tree commit diff stats
path: root/testament/lib/stdtest
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-04-18 15:15:58 -0700
committerGitHub <noreply@github.com>2021-04-19 00:15:58 +0200
commit0a10af5a2ce27638c8298e96866a779928122269 (patch)
tree0a507184bab9d00893c4d1ae50ea4d0ce1c794a1 /testament/lib/stdtest
parentd6c8efa5d444f6849102dca192a199f12c8d55eb (diff)
downloadNim-0a10af5a2ce27638c8298e96866a779928122269.tar.gz
privateAccess now works with ref | ptr (#17760)
Diffstat (limited to 'testament/lib/stdtest')
-rw-r--r--testament/lib/stdtest/testutils.nim20
1 files changed, 20 insertions, 0 deletions
diff --git a/testament/lib/stdtest/testutils.nim b/testament/lib/stdtest/testutils.nim
index 35423de17..44048adbd 100644
--- a/testament/lib/stdtest/testutils.nim
+++ b/testament/lib/stdtest/testutils.nim
@@ -1,5 +1,6 @@
 import std/private/miscdollars
 from std/os import getEnv
+import std/[macros, genasts]
 
 template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) =
   ## API to deal with flaky or failing tests. This avoids disabling entire tests
@@ -89,3 +90,22 @@ template reject*(a) =
 template disableVm*(body) =
   when nimvm: discard
   else: body
+
+template typeOrVoid[T](a: T): type =
+  # FACTOR with asyncjs.typeOrVoid
+  T
+
+macro assertAll*(body) =
+  ## works in VM, unlike `check`, `require`
+  runnableExamples:
+    assertAll:
+      1+1 == 2
+      var a = @[1, 2] # statements work
+      a.len == 2
+  # remove this once these support VM, pending #10129 (closed but not yet fixed)
+  result = newStmtList()
+  for a in body:
+    result.add genAst(a) do:
+      # better than: `when not compiles(typeof(a)):`
+      when typeOrVoid(a) is void: a
+      else: doAssert a