As a little personal project I am doing a small, very simple, test-framework in C.
The problem I am facing, is that I want to be able to register test cases (i.e. functions with ASSERTS of some kinds in them) automatically when a user writes them, and then run them in my predefined main function.
So from the user side, I only want to have to do
TEST_CASE("TestName1")
{
// Testing stuff here
}
TEST_CASE("TestName2")
{
// Testing more stuff here
}
and the rest should be covered.
At the moment the define only looks like
#define TEST_CASE(name) int name()
and the question is therefor if it is possible to somewhat "remember" these functions so I can call them in the main function.
EDIT: So the point is that the user should include a "test-framework.h" which defines a predefined main() function which runs all the tests that the user specified with TEST_CASEs. That meaning it should look something like this:
User defined file:
// File where tests are defined
#include "framework.h"
TEST_CASE("TestCase1")
{
// Test stuff
}
TEST_CASE("TestCase2")
{
// Test more stuff
}
And in the framework file:
// framework.h
#define TEST_CASE(name) int name()
int main()
{
// Here run all TEST_CASEs there is
}
That meaning, I do not know the names of the TEST_CASES in my main().