summary refs log tree commit diff stats
path: root/testament
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-02-24 05:01:06 -0800
committerGitHub <noreply@github.com>2021-02-24 14:01:06 +0100
commit11a7fa68f646777214a81cddaf3043d642c94c6b (patch)
tree16c56f6cf4bf1cdfc8d4b22cb37f7504145bf789 /testament
parent3021252ad44b60a35a58deb4abe4e001146dd09d (diff)
downloadNim-11a7fa68f646777214a81cddaf3043d642c94c6b.tar.gz
fix #17159 items(cstring) works in VM (#17160)
* fix #17159 items(cstring) works in VM

* improve test coverage tests/stdlib/tcstring.nim; add helpers: whenRuntimeJs, whenVMorJs

* document items(cstring)

* address comments
Diffstat (limited to 'testament')
-rw-r--r--testament/lib/stdtest/testutils.nim24
1 files changed, 24 insertions, 0 deletions
diff --git a/testament/lib/stdtest/testutils.nim b/testament/lib/stdtest/testutils.nim
index 50dda22e2..36f951272 100644
--- a/testament/lib/stdtest/testutils.nim
+++ b/testament/lib/stdtest/testutils.nim
@@ -42,3 +42,27 @@ template enableRemoteNetworking*: bool =
   ## process calls, e.g. `testament all` calls itself, which in turns invokes
   ## a `nim` invocation (possibly via additional intermediate processes).
   getEnv("NIM_TESTAMENT_REMOTE_NETWORKING") == "1"
+
+template whenRuntimeJs*(bodyIf, bodyElse) =
+  ##[
+  Behaves as `when defined(js) and not nimvm` (which isn't legal yet).
+  pending improvements to `nimvm`, this sugar helps; use as follows:
+
+  whenRuntimeJs:
+    doAssert defined(js)
+    when nimvm: doAssert false
+    else: discard
+  do:
+    discard
+  ]##
+  when nimvm: bodyElse
+  else:
+    when defined(js): bodyIf
+    else: bodyElse
+
+template whenVMorJs*(bodyIf, bodyElse) =
+  ## Behaves as: `when defined(js) or nimvm`
+  when nimvm: bodyIf
+  else:
+    when defined(js): bodyIf
+    else: bodyElse