I try to test multiple build configurations with the Unity/Ceedling test framework from ThrowTheSwitch
I have code like this:
int function (int a)
{
#ifdef MACRO_DEFINED
return a
#else
return -1 * a
#endif
}
And a corresponding test functions:
void test_function_MacroEnabled(void)
{
int result;
result = function(1);
TEST_ASSERT_MESSAGE(result == 1, "Result should be 1");
}
void test_function_MacroDisabled(void)
{
int result;
result = function(1);
TEST_ASSERT_MESSAGE(result == -1, "Result should be -1");
}
But I cannot figure out how I can get Unity/Ceedling to test both cases. If I define the Macro within the test file Unity ignores it (which is of course logical). My only option (up to now) is to manually define/undefine the macro somewhere within the project (or the project.yml file) and run the first test, then flip the macro manually and run the other test. But my gutfeeling is that it should be possible to automate this. But I fail to find out how, unfortunately. Does anybody know how to approach this?
Thanks in advance
I run Unity/Ceelding/CMock from the docker image throwtheswitch/madsciencelab
vbchaos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.