From 11a7fa68f646777214a81cddaf3043d642c94c6b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 24 Feb 2021 05:01:06 -0800 Subject: 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 --- testament/lib/stdtest/testutils.nim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'testament') 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 -- cgit 1.4.1-2-gfad0