News for hackers. Stuff that matters.
Re:How to C in 2016 by redahs on Friday January 08, 2016 @06:54PM (#10869234)
C is one of the easier languages to do unit testing in:

1. write a new one file script which parses function declarations from a source code file

2. have the script find all function declarations which start with "utest_", accept no parameters, and return "int" or "bool".

3. have the script write out a new C file which calls all of matching unit test functions and asserts their return value is equal to 1

4. have your Makefile build and run a unit test binary using code generated by your script for each source code file containing greater than 0 unit tests.

Writing a script to parse function declarations from your C source code is useful because you can extend the script later on to generate documentation, code statistics, or conduct project-specific static analysis.

There are no comments on this comment yet.