To embed tests in modules there is to use the statement when isMainModule. But how to run the tests?
Is possible run them like in Go/Rust? (go test / cargo test)
(This may not be answering the question you asked, but is for running tests from the /tests suite )
koch tests to run all tests, or koch tests c <testDir> where <testDir> is one of the directories under the /tests directory
You can define any custom commands you want by putting them into config.nims at the root of your project. For example, this is what I have in NimYAML:
task tests, "Run all tests":
--r
--verbosity:0
setCommand "c", "test/tests"
This basically tells Nim to execute nim c -r --verbosity:0 test/tests when I type in nim tests. If you want to run tests in multiple files with one command, you can do:
task tests, "Run all tests":
exec r"nim c -r someFile"
exec r"nim c -r anotherFile"
setCommand "nop"
to compile and run and individual test file in a locally modified nim repo:
nim c --lib:lib -r tests/stdlib/talgorithm.nim