tvmops.nim 1.3 KB

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