7#include <unordered_set>
20enum class TaskCategory
43 void add (
const std::string& name,
const std::string& tags, TaskCategory testCategory,
void (*func)())
45 std::unordered_set<std::string>& registeredNamesContainer =
46 testCategory == TaskCategory::test
48 : registeredGeneratorNames;
50 const auto insertResult = registeredNamesContainer.insert (name);
51 const bool isDuplicate = ! insertResult.second;
56 std::vector<TaskInfo>& tasks =
57 testCategory == TaskCategory::test
61 tasks.emplace_back (TaskInfo {name, tags, func});
73 std::vector<TaskInfo>& tasks =
78 if (tasks.size() == 0)
80 std::cout <<
"Nothing to run!" << std::endl;
87 for (
const TaskInfo& task : tasks)
90 std::cout << std::endl;
91 std::cout <<
"[ PASSED ] " << tasksPassed <<
'/' << tasks.size() << std::endl;
94 std::cout <<
"[ FAILED ] " << tasksFailed <<
'/' << tasks.size() << std::endl;
97 std::cout << std::endl << resultAsciiArt << std::endl;
98 return (
int) (tasksFailed != 0);
109 TestRegistry() =
default;
110 std::vector<TaskInfo> tests;
111 std::vector<TaskInfo> generators;
112 std::unordered_set<std::string> registeredTestNames;
113 std::unordered_set<std::string> registeredGeneratorNames;
115 size_t tasksPassed = 0;
116 size_t tasksFailed = 0;
118 void runTask (
const TaskInfo& task)
120 std::cout <<
"[ ... ] Running " << task.name;
121 bool assertionFailed =
false;
122 std::string assertionFailMessage;
131 assertionFailMessage = e.what();
132 assertionFailed =
true;
136 assertionFailMessage = e.what();
137 assertionFailed =
true;
145 if (assertionFailed || expectationsFailed)
147 constexpr char separator[] =
"-------------------------------------------";
148 std::cout <<
"[ </3 ] " << task.name <<
" - failed" << std::endl;
152 std::cout << separator << std::endl << assertionFailMessage << std::endl;
157 std::cout << separator << std::endl << expectationFailureMessage << std::endl;
160 std::cout << separator << std::endl;
165 std::cout <<
"[ <3 ] " << task.name <<
" - passed" << std::endl;
170 static void shuffleTasks (std::vector<TaskInfo>& tasks)
173 std::shuffle (tasks.begin(), tasks.end(), rng);
static std::vector< std::string > & get()
static TestRegistry & getInstance()
Gets the singleton instance.
int runAll()
Runs all tests or generators.
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
static const char * hartAsciiArt
static const char * passAsciiArt
static const char * failAsciiArt
uint_fast32_t getRandomSeed()
bool shouldRunGenerators()
bool shouldShuffleTasks()
static CLIConfig & getInstance()