tunit.nim 701 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import
  2. unittest, macros
  3. var
  4. a = 1
  5. b = 22
  6. c = 1
  7. d = 3
  8. suite "my suite":
  9. setup:
  10. echo "suite setup"
  11. var testVar = "from setup"
  12. teardown:
  13. echo "suite teardown"
  14. test "first suite test":
  15. testVar = "modified"
  16. echo "test var: " & testVar
  17. check a > b
  18. test "second suite test":
  19. echo "test var: " & testVar
  20. proc foo: bool =
  21. echo "running foo"
  22. return true
  23. proc err =
  24. raise newException(ArithmeticDefect, "some exception")
  25. test "final test":
  26. echo "inside suite-less test"
  27. check:
  28. a == c
  29. foo()
  30. d > 10
  31. test "arithmetic failure":
  32. expect(ArithmeticDefect):
  33. err()
  34. expect(ArithmeticDefect, CatchableError):
  35. discard foo()