feat: add logging functions for tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
|
||||
/*
|
||||
test implementation interface
|
||||
@@ -13,8 +15,38 @@ class ITest
|
||||
|
||||
protected:
|
||||
virtual void run() = 0;
|
||||
virtual const char* getName() = 0;
|
||||
|
||||
/*
|
||||
shamelessly yoinked from log lib
|
||||
*/
|
||||
template <typename... Args> void logVerbose(std::format_string<Args...> fmt, Args&&... args)
|
||||
{
|
||||
writeLog("\x1b[34;40m", std::vformat(fmt.get(), std::make_format_args(args...)));
|
||||
}
|
||||
|
||||
template <typename... Args> void logInfo(std::format_string<Args...> fmt, Args&&... args)
|
||||
{
|
||||
writeLog("\x1b[32;40m", std::vformat(fmt.get(), std::make_format_args(args...)));
|
||||
}
|
||||
|
||||
template <typename... Args> void logWarning(std::format_string<Args...> fmt, Args&&... args)
|
||||
{
|
||||
writeLog("\x1b[30;43m", std::vformat(fmt.get(), std::make_format_args(args...)));
|
||||
}
|
||||
|
||||
template <typename... Args> void logError(std::format_string<Args...> fmt, Args&&... args)
|
||||
{
|
||||
writeLog("\x1b[97;41m", std::vformat(fmt.get(), std::make_format_args(args...)));
|
||||
}
|
||||
|
||||
friend class TestRunner;
|
||||
|
||||
private:
|
||||
void writeLog(const char* color, const std::string& message)
|
||||
{
|
||||
std::cout << color << "[" << getName() << "]" << "\x1b[0m " << message << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -26,7 +58,11 @@ class TestRunner
|
||||
void runTests()
|
||||
{
|
||||
for (auto& test : _tests)
|
||||
{
|
||||
test->logInfo("------- Init -------");
|
||||
test->run();
|
||||
test->logInfo("-------- End --------");
|
||||
}
|
||||
}
|
||||
|
||||
static TestRunner& get()
|
||||
|
||||
Reference in New Issue
Block a user