stuff-from-scratch/test/test_utils/TestFramework.h

30 lines
1.3 KiB
C
Raw Normal View History

2022-11-29 18:00:19 +00:00
#pragma once
#include "TestCaseRunner.h"
struct Holder
{
2023-12-18 10:16:31 +00:00
Holder(const String& name, const String& tags, std::function<void()> func)
2022-11-29 18:00:19 +00:00
{
TestCaseRunner::getInstance().addTestCase(name, tags, func);
}
};
#define TEST_CASE(NAME, TAGS) \
static void Test##NAME(); \
namespace{Holder holder##NAME( #NAME, #TAGS, &Test##NAME );} \
static void Test##NAME() \
2022-12-06 18:02:43 +00:00
#define REQUIRE(predicate) \
if(!bool(predicate)) \
{ \
2023-12-18 10:16:31 +00:00
const auto msg = String::to_string(__LINE__) + String(" with check: '") + String(#predicate) + String("'"); \
2023-12-20 16:58:22 +00:00
TestCaseRunner::getInstance().markTestFailure(msg); \
return; \
2022-12-06 18:02:43 +00:00
} \
2022-11-30 18:28:50 +00:00