A light Nim testing framework
Find a file
Joey faec4affb0
Merge pull request #1 from jyapayne/wip
Add better testing experience and fix compiler bugs
2019-11-05 09:39:54 -07:00
src Add test discovery for easy test writing 2019-11-05 09:37:38 -07:00
tests Add test discovery for easy test writing 2019-11-05 09:37:38 -07:00
.gitignore Initial testing framework 2019-02-20 21:17:31 -07:00
LICENSE Initial commit 2019-02-20 18:38:54 -07:00
README.md Add basic usage docs 2019-02-27 20:49:50 -07:00
tani.nimble Initial testing framework 2019-02-20 21:17:31 -07:00

tani

A light Nim testing framework

Usage

Simply sprinkle the test macro anywhere in your code and call the runTests macro once from the main module to run all tests. Tests that are in private procs (outside of the main module) will be skipped due to how the macros are implemented.

import tani

proc doSomething(): string =
  test "test do something":
    let testValue = "the value"
    check doSomething() == testValue

  return "the value"

when defined(test):
  runTests()

Limitations

Due to implementation details, the test macro cannot run tests contained within private procs from a different module. For example, when nim c -r test2.nim is called on the below files, privateProc will not run, but privateProc2 will. privateProc will not be counted towards the final tests run and the tests will pass. Tani is smart enough to detect what the not run tests are and will show you a warning when they do not run.

# test1.nim

import tani

proc privateProc(): int =
  test "test private":
    check privateProc() == 3

  # Do something here

  return 3
# test2.nim
import tani
import test1

proc privateProc2(): int =
  test "test private2":
    check privateProc2() == 6

  # Do something here

  return 6

runTests()

Output (nim c -r test2.nim):

[Running] tests in test1.nim

[Not run] test private
  Test code contains private or non accessible symbols:
    check privateProc() == 3
  Location: test1.nim; line 7; col: 4


[Running] tests in test2.nim
[OK]     test private2

[1/1] tests passed for test2.nim.

[Summary]

  [1/1] tests passed.