Skip to content

Instantly share code, notes, and snippets.

@TheAllenChou
Last active October 12, 2018 21:19
Show Gist options
  • Save TheAllenChou/a10d6dbd34664d37a96a75086c9e391c to your computer and use it in GitHub Desktop.
Save TheAllenChou/a10d6dbd34664d37a96a75086c9e391c to your computer and use it in GitHub Desktop.
#define BEGIN_TEST_DEFINES static const int testIndexCounterBase = __COUNTER__
#define END_TEST_DEFINES static const int kNumTests = (__COUNTER__ - testIndexCounterBase - 1)
#define TEST_CASE(TestName) \
static const int k##TestName##Index = __COUNTER__ - testIndexCounterBase - 1; \
bool TestName##Func(TestArgs &args)
struct TestEval
{
int m_testIndex;
bool (*m_testFunc) (TestArgs &);
}
bool RunTests(TestEval* aTestEval, int numTests, TestArgs &args, BitArray<kMaxtests> testPassBits)
{
bool ret = true;
for (int i = 0; i < numTests; ++i)
{
TestEval& tesEval = aTestEval[i];
const bool pass = testEval.m_testFunc(args);
if (pass)
{
testPassBits.SetBit(tesetEval.m_testIndex);
}
else
{
ret = false;
// early out if you want
}
}
return ret;
}
#define TEST_EVAL_LIST(ListName) TestEval Listname[] =
#define TEST_EVAL(TestName) { k##TestName##Index, TestName##Func }
BEGIN_TESTS_DEFINES;
TEST_CASE(MyTest0)
{
// stuff
}
TEST_CASE(MyTest1)
{
// stuff
}
// ...
END_TEST_DEFINES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment