I am using cgreen to write tests for my C code, my question is:
Short version: Is it possible to put more than one Describe() in one file?
Long version: I have different test files, with their own Describe(), BeforeEach() and AfterEach(). Since in these files, I've used same module, I have to compile them together. [for preventing compiler from including the module more than once, I used this trick (include guard)
#ifndef SOME_NAME
#define SOME_NAME
...
#endif
I also have a file which contains all my tests, let say all_tests.c. Now, I want to include my test files into all_tests.c and compile everything together, something like this:
#include <cgreen/cgreen.h>
#include "./test1.c"
#include "./test2.c"
int main() {
TestSuite *suite = create_test_suite();
add_suite(suite, test1_tests());
add_suite(suite, test2_tests());
return run_test_suite(suite, create_text_reporter());
}
Well, I couldn't find a better idea, using recommended
TestSuite *test1_tests();
TestSuite *test2_tests();
instead of including the files directly leads to these errors:
error: redefinition of ‘setup’
error: redefinition of ‘teardown’
Just for being clear, the test1.c file looks like this:
#include <cgreen/cgreen.h>
#include "./some_global_module.h"
Describe(test1);
BeforeEach(test1) {
...
}
AfterEach(test1) {
...
}
Ensure(test1, do_something) {
...
}
TestSuite *test1_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, test1, do_something);
return suite;
}
Any idea? Perhaps there is some compiler trick that I can use or an easier way to manage the whole thing?
Aucun commentaire:
Enregistrer un commentaire