If you're planning to write unit tests for a C program, what is the convention for placement of the main function? Do you put it in it's own separate file, with the functions in another file, that way you can include the functions file inside a test without having conflicts with two main methods? This makes sense to me but just wondering if there's a certain convention.
I ask because we have several SQR programs at work that are a difficult to maintain, and I'd like to take a stab at getting them under test, but I need a way to call the functions from another file, so I figured my first step would be to take the begin-program - end-program section and stick it in a separate file.
It is good practice use a unit testing framework such as Check, Cmocka, etc. This frameworks offer many useful test functions and macros, and provide a unit test harness which handle the reporting of failures. A framework like CUnit also isolates tests from each other by forking them, this protecting the test harness from buffer overruns, and preventing tests from interfering with each other.
If you do want to or have to roll your own, then I would put the "Harness" code in one c module and put the unit tests in a separate file. You would also want the tests to register themselves with the harness and not the other way round. Possible then you could reuse the harness code elsewhere if your platform does not have other unit test frameworks ported to it.