It is possible and relatively easy to have unit tests as top level constructs, like:
TEST "some test":
assert(...)
TEST "another test":
...
One implementation is described here: http://forum.nimrod-lang.org/t/653.
But is it somehow possible to add such tests inside regular code, like:
proc foo =
if (x):
...
TEST "testing this branch":
...
else:
...
TEST "testing else branch":
...
...
and have them invoked in the same way as top-level counterparts are? The regular code should act as if these tests do not exist at all.
(I know it may be not always the wisest idea to write code like this.)
@araq: the foo is just an example. These tests should be invoked at the same time when top-level tests run. The idea is to move some tests near the location they check, no additional functionality.
I hoped that perhaps initalizing a global variable (hidden inside the proc) could take address of the test code and register it somehow and then all these adresses could be invoked.
I'll try to figure out.
It is a bit strange feature but if one wants to have thorough test coverage it may be handy. In C++ this is completely impossible, no matter what.
@Demos: not really. The idea is to move some of the tests inside the procs, without any futher interaction.
Say you have 10 unit tests for a complicated function. You move some of the tests into infrequently used branches to give a hint these branches got tested and how.