minunit
minunit copied to clipboard
Support for multiple MU_TEST_SUITE() from different .c files?
Would you be interested in supporting multiple MU_TEST_SUITE() from different .c files? I am offering to implement it. I know that with this MinUnit would lose the "single header file" characteristics, but I think that it is better to split tests for different modules in different files.
For this purpose, there's only a minor change to make at https://github.com/siu/minunit/blob/3b0921c4751b27b5ef4d6f4ac2adfe42f07ce25e/minunit.h#L92: remove the static
keyword.
secondary_suite.c:
#include "minunit.h"
MU_TEST(test_check)
{
mu_check(6 == 16);
}
MU_TEST_SUITE(secondary_test_suite)
{
MU_RUN_TEST(test_check);
}
main.c:
#include "minunit.h"
/* declare secondary test suite */
MU_TEST_SUITE(secondary_test_suite);
MU_TEST(test_check)
{
mu_check(5 == 7);
}
MU_TEST_SUITE(test_suite)
{
MU_RUN_TEST(test_check);
}
int main(int argc, char *argv[])
{
/* use secondary test suite */
MU_RUN_SUITE(secondary_test_suite);
MU_RUN_SUITE(test_suite);
MU_REPORT();
return MU_EXIT_CODE;
}
It works on my machineᵀᴹ:
$ gcc -Wall main.c secondary_suite.c
$ ./a.out
F
test_check failed:
secondary_suite.c:5: 6 == 16
F
test_check failed:
main.c:8: 5 == 7
1 tests, 1 assertions, 1 failures
Finished in 0.00006298 seconds (real) 0.00006241 seconds (proc)
It does not work! You have 2 tests, but in output we see: 1 tests, 1 assertions, 1 failures
This because you can #include "minunit.h"
only in one file, because it contains static variable.
I have forked this repository (https://github.com/bzgec/minunit) and enabled support for this feature, but now it is not contained in a single header file. There are also some other modifications.
@chipsoft You're partially right. The total report is wrong as you said. But the two suites are used, and failed tests are reported.
That was sufficient for me at that time, but this can be improved.