News for hackers. Stuff that matters.
Re:Greatest: C unit testing library in one file by dasmithii on Tuesday January 07, 2014 @08:51PM (#7021203)
Macros are surprisingly useful in the unit testing context. Whether or not it's considered good practice, I like to embed my tests within the header files that they're associated with. With macros and gcc's -D flag in order to generate production and testing builds separately.

I'm new to the world of C, is this typical?

Re:Greatest: C unit testing library in one file by simias on Wednesday January 08, 2014 @04:41AM (#7022579)
It's fairly typical. The standard "assert" macro behaves exactly that way, it does not generate code if the code is compiled with NDEBUG defined.

Of course you shouldn't abuse it but in this instance it's perfectly fine IMHO.

This reminds me that in addition to that the linux kernel has a pretty cool feature for debugging called "dynamic debugging" where you can enable and disable "printk" (the kernel's version of printf) messages dynamically from the shell through the debugfs:

http://lwn.net/Articles/434833/

Re:Greatest: C unit testing library in one file by silentbicycle on Tuesday January 07, 2014 @09:02PM (#7021231)
I've seen people do that before, as well as putting the tests in the .c file, guarded by "#if TEST_MODULE_NAME", and exporting a (module_name)_run_tests(void) function.

My preference is to have separate test_module_name.c files. Failing that, I would include tests in the module's .c file rather than the header, so that the header can be relatively short and focused on documenting the module's interface, rather than its implementation details.

greatest doesn't force any specific style there, by design.