By default Testament looks for test files on "./tests/*.nim", you can overwrite this pattern glob using pattern <glob>, the default working directory path can be changed using --directory:"folder/subfolder/".
Testament uses the nim compiler on PATH you can change that using --nim:"folder/subfolder/nim", running JavaScript tests with --targets:"js" requires a working NodeJS on PATH.
This is a minimal example to understand the basics, not very useful for production, but easy to understand:
$ mkdir tests $ echo "assert 42 == 42" > tests/test0.nim $ testament run test0.nim PASS: tests/test0.nim C ( 0.2 sec) $ testament r test0 PASS: tests/test0.nim C ( 0.2 sec) $
$ testament pattern "tests/*.nim"
Generate HTML Reports testresults.html from unittests, you have to run at least 1 test before generating a report:
$ testament html
Example "template" to edit and write a Testament unittest:
discard """ action: "run" # What to do, one of "compile" OR "run". exitcode: 0 # This is the Exit Code the test should return, zero typically. output: "" # This is the Standard Output the test should print, if any. input: "" # This is the Standard Input the test should take, if any. errormsg: "" # Error message the test should print, if any. batchable: true # Can be run in batch mode, or not. joinable: true # Can be run Joined with other tests to run all togheter, or not. valgrind: false # Can use Valgrind to check for memory leaks, or not (Linux 64Bit only). cmd: "c -r $file" # Command the test should use to run. maxcodesize: 666 # Maximum generated temporary intermediate code file size for the test. timeout: 666 # Timeout microseconds to run the test. target: "c js" # Targets to run the test into (C, C++, JavaScript, etc). disabled: "bsd" # Disable the test by condition, here BSD is disabled just as an example. """ assert true assert 42 == 42, "Assert error message"
Expected to fail:
discard """ errormsg: "undeclared identifier: 'not_defined'" """ assert not_defined == "not_defined", "not_defined is not defined"
Non-Zero exit code:
discard """ exitcode: 1 """ quit "Non-Zero exit code", 1
Standard output checking:
discard """ output: ''' 0 1 2 3 4 5 ''' """ for i in 0..5: echo i
JavaScript tests:
discard """ target: "js" """ when defined(js): import jsconsole console.log("My Frontend Project")
Compile time tests:
discard """ action: "compile" """ static: assert 9 == 9, "Compile time assert"
Tests without Spec:
assert 1 == 1
See also: