Hi guys,
How are you guys testing your code? I've seen some references to a "unittest" module, but I haven't seen any documentation on the module. There don't appear to be any testing modules in the Nimrod Standard Library. As I'm sure you're all aware, testing is a critical part of modern dev, so availability of good testing tools seem to me to be very important to the future of Nimrod, especially if you hope to gain users in industry. The Go language has a separate testing facility "go test" command; Haskell has awesome support via the QuickCheck library, which can automate a lot of testing (Go has something similar); and D has the built-in "unittest" keyword, so users can declare unit tests directly and then have the test run automatically by the compiler, immediately learning if a test fails. All of these are interesting but different approaches: a separate tool, a library, and a built-in keyword. What approach are you guys planning on taking with Nimrod? I personally like the idea of checking code invariants via a QuickCheck-style tool, but I don't know how feasible that is.
I'm sure there are fancy ways to write robust tests in Nimrod, but the easiest D 'unittest' equivalent looks like:
# somecode.nim
when defined(unittest):
# ... test code ...
compile with:
$ nimrod c -d:unittest somecode
and FYI, 'unittest' is just an example. You can declare any compiler directive you want with the "-d:" flag.
when isMainModule:
and put all their tests in that opened block; that way they are only run if you compile and run that module on its own. Of course, if the module you're writing is MEANT to be run as the main module, then you'll have to do something like filwit suggested.