summary refs log tree commit diff stats
path: root/tests/vm/tvmops.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2018-12-18 00:07:12 -0800
committerAndreas Rumpf <rumpf_a@web.de>2018-12-18 09:07:12 +0100
commitc4e3c4ca2d0a1f44ed1e3dd9db564b66031f0843 (patch)
tree9aac56357dfbad2ac7bad74ef31670e4d6d99b16 /tests/vm/tvmops.nim
parentbb1160b73cc3410ce7a0949f67d2fa7f5b425ab4 (diff)
downloadNim-c4e3c4ca2d0a1f44ed1e3dd9db564b66031f0843.tar.gz
add `getCurrentCompilerExe` to vmops (eg allows to get nim compiler at CT); add tests for vmops (#9925)
Diffstat (limited to 'tests/vm/tvmops.nim')
-rw-r--r--tests/vm/tvmops.nim47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/vm/tvmops.nim b/tests/vm/tvmops.nim
new file mode 100644
index 000000000..c9caaf32b
--- /dev/null
+++ b/tests/vm/tvmops.nim
@@ -0,0 +1,47 @@
+#[
+test for vmops.nim
+]#
+import os
+import math
+import strutils
+
+template forceConst(a: untyped): untyped =
+  ## Force evaluation at CT, useful for example here:
+  ## `callFoo(forceConst(getBar1()), getBar2())`
+  ## instead of:
+  ##  block:
+  ##    const a = getBar1()
+  ##    `callFoo(a, getBar2())`
+  const ret = a
+  ret
+
+static:
+  # TODO: add more tests
+  block: #getAppFilename, gorgeEx, gorge
+    const nim = getCurrentCompilerExe()
+    let ret = gorgeEx(nim & " --version")
+    doAssert ret.exitCode == 0
+    doAssert ret.output.contains "Nim Compiler"
+    let ret2 = gorgeEx(nim & " --unexistant")
+    doAssert ret2.exitCode != 0
+    let output3 = gorge(nim & " --version")
+    doAssert output3.contains "Nim Compiler"
+
+  block:
+    const key = "D20181210T175037"
+    const val = "foo"
+    putEnv(key, val)
+    doAssert existsEnv(key)
+    doAssert getEnv(key) == val
+
+  block:
+    # sanity check (we probably don't need to test for all ops)
+    const a1 = arcsin 0.3
+    let a2 = arcsin 0.3
+    doAssert a1 == a2
+
+block:
+  # Check against bugs like #9176
+  doAssert getCurrentCompilerExe() == forceConst(getCurrentCompilerExe())
+  if false: #pending #9176
+    doAssert gorgeEx("unexistant") == forceConst(gorgeEx("unexistant"))