I'm planning a project with multiple modules, and I was looking for a nice solution to run all existing unit tests in the project at once. I came up with the following idea: I can run nim --define:testing main.nim
and use the following template as a wrapper for all my unit tests.
# located in some general utils module:
template runUnitTests*(code: stmt): stmt =
when defined(testing):
echo "Running units test in ..."
code
This seems to be working well so far.
As a minor tweak, I was wondering if I can actually print out the file name which is calling the runUnitTests
template. Is there any reflection mechanism to get the source file name at compile time?
instantiationInfo().filename
directly in therunUnitTests
template. If I create thisfilename
template in myutils.nim
module and call this second template from therunUnitTests
template, the output is alwaysutils.nim
(looks like nesting templates affects stack line information). – Bluefield