In environments where it is not possible or practical to use the cgreen-runner it is still possible to avoid the manual labour of keeping your driver code updated when you change or add to the tests.
The following Makefile extract shows the principle, using grep and sed, and should be documented as a makeshift alternative. The only prerequisite is that you keep the Ensure()'s on single lines.
discoverer_unit_test_runner.c : tests/discoverer_unit_tests.c
echo "#include \"tests/discoverer_unit_tests.c\"" > discoverer_unit_test_runner.c
echo "TestSuite *discoverer_unit_tests() {" >> discoverer_unit_test_runner.c
echo " TestSuite *suite = create_test_suite();" >> discoverer_unit_test_runner.c
grep Ensure tests/discoverer_unit_tests.c | sed -e 's/Ensure(/ add_test_with_context(suite, /g' -e 's/) {/);/g' >> discoverer_unit_test_runner.c
echo " return suite;" >> discoverer_unit_test_runner.c
echo "}" >> discoverer_unit_test_runner.c
echo "int main(int argc, char **argv) {" >> discoverer_unit_test_runner.c
echo " return run_test_suite(discoverer_unit_tests(), create_text_reporter());" >> discoverer_unit_test_runner.c
echo "}" >> discoverer_unit_test_runner.c
In environments where it is not possible or practical to use the
cgreen-runnerit is still possible to avoid the manual labour of keeping your driver code updated when you change or add to the tests.The following Makefile extract shows the principle, using grep and sed, and should be documented as a makeshift alternative. The only prerequisite is that you keep the
Ensure()'s on single lines.