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});
72 std::vector<TaskInfo>& tasks =
77 if (tasks.size() == 0)
79 std::cout <<
"Nothing to run!" << std::endl;
86 for (
const TaskInfo& task : tasks)
89 std::cout << std::endl;
90 std::cout <<
"[ PASSED ] " << tasksPassed <<
'/' << tasks.size() << std::endl;
93 std::cout <<
"[ FAILED ] " << tasksFailed <<
'/' << tasks.size() << std::endl;
96 std::cout << std::endl << resultAsciiArt << std::endl;
97 return (
int) (tasksFailed != 0);
108 TestRegistry() =
default;
109 std::vector<TaskInfo> tests;
110 std::vector<TaskInfo> generators;
111 std::unordered_set<std::string> registeredTestNames;
112 std::unordered_set<std::string> registeredGeneratorNames;
114 size_t tasksPassed = 0;
115 size_t tasksFailed = 0;
117 void runTask (
const TaskInfo& task)
119 std::cout <<
"[ ... ] Running " << task.name;
120 bool assertionFailed =
false;
121 std::string assertionFailMessage;
130 assertionFailMessage = e.what();
131 assertionFailed =
true;
135 assertionFailMessage = e.what();
136 assertionFailed =
true;
144 if (assertionFailed || expectationsFailed)
146 constexpr char separator[] =
"-------------------------------------------";
147 std::cout <<
"[ </3 ] " << task.name <<
" - failed" << std::endl;
151 std::cout << separator << std::endl << assertionFailMessage << std::endl;
156 std::cout << separator << std::endl << expectationFailureMessage << std::endl;
159 std::cout << separator << std::endl;
164 std::cout <<
"[ <3 ] " << task.name <<
" - passed" << std::endl;
169 static void shuffleTasks (std::vector<TaskInfo>& tasks)
172 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()