Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Makefile/script to autogenerate test driver #286

Open
thoni56 opened this issue Dec 28, 2021 · 0 comments
Open

Document Makefile/script to autogenerate test driver #286

thoni56 opened this issue Dec 28, 2021 · 0 comments

Comments

@thoni56
Copy link
Contributor

thoni56 commented Dec 28, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant