Given I have my tests in a separate file to my application code, is there any way to test unexported (private) procs from within my test file?
i.e.
proc private(x: int): int =
without doing
proc private*(x: int): int =
Is there any tip/trick I'm missing, what is the standard practice for testing private functions?
There is not. But I don't think it's correct to be testing private functions, testing the public ones should be enough.
The only way to test them is to put the tests in the same file.
ok, thank you, just needed to confirm.
One thing I'm thinking of is putting my private function tests in my main file under a when testPrivateFuncs: block and building with this symbol, when I need peace of mind.
You may be able to use include instead of import for this purpose.
Note that include and import have different semantics. With include, you have basically textual inclusion. This means that multiple includes will replicate procedures and variables each time. However, if you're only using it for unit tests, that may already be sufficient.
In addition, this allows you to keep separate modules with and without testing and without duplicating code. For example:
Just test the private parts from within its own file. That's a nice way to write some peace-of-mind tests. (Testing an implementation detail is not always a bad idea.)
when isMainModule:
test_private()
Another example:
You might want to exclude the test from compilation to save time, but dead-code elimination can remove it from the shipped code anyway.
To run the test, you will have to build that module as an executable, but then you simply execute it.