tvmops.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. #[
  5. test for vmops.nim
  6. ]#
  7. import os
  8. import math
  9. import strutils
  10. template forceConst(a: untyped): untyped =
  11. ## Force evaluation at CT, useful for example here:
  12. ## `callFoo(forceConst(getBar1()), getBar2())`
  13. ## instead of:
  14. ## block:
  15. ## const a = getBar1()
  16. ## `callFoo(a, getBar2())`
  17. const ret = a
  18. ret
  19. static:
  20. # TODO: add more tests
  21. block: #getAppFilename, gorgeEx, gorge
  22. const nim = getCurrentCompilerExe()
  23. let ret = gorgeEx(nim & " --version")
  24. doAssert ret.exitCode == 0
  25. doAssert ret.output.contains "Nim Compiler"
  26. let ret2 = gorgeEx(nim & " --unexistant")
  27. doAssert ret2.exitCode != 0
  28. let output3 = gorge(nim & " --version")
  29. doAssert output3.contains "Nim Compiler"
  30. block:
  31. const key = "D20181210T175037"
  32. const val = "foo"
  33. putEnv(key, val)
  34. doAssert existsEnv(key)
  35. doAssert getEnv(key) == val
  36. block:
  37. # sanity check (we probably don't need to test for all ops)
  38. const a1 = arcsin 0.3
  39. let a2 = arcsin 0.3
  40. doAssert a1 == a2
  41. block bitxor:
  42. let x = -1'i32
  43. let y = 1'i32
  44. doAssert (x xor y) == -2
  45. block:
  46. # Check against bugs like #9176
  47. doAssert getCurrentCompilerExe() == forceConst(getCurrentCompilerExe())
  48. if false: #pending #9176
  49. doAssert gorgeEx("unexistant") == forceConst(gorgeEx("unexistant"))