From fb259b019b6ca6e2956fdaa621b014d14b234b3d Mon Sep 17 00:00:00 2001 From: neru Date: Mon, 11 May 2026 08:17:13 -0300 Subject: [PATCH] feat: add logging functions for tests --- src/test/tests.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/tests.h b/src/test/tests.h index 8e67725..5d73dd5 100644 --- a/src/test/tests.h +++ b/src/test/tests.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include /* 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 void logVerbose(std::format_string fmt, Args&&... args) + { + writeLog("\x1b[34;40m", std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void logInfo(std::format_string fmt, Args&&... args) + { + writeLog("\x1b[32;40m", std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void logWarning(std::format_string fmt, Args&&... args) + { + writeLog("\x1b[30;43m", std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void logError(std::format_string 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()