osuplusplus/test/test.hpp
jacekpoz 086e841110
make the test name a string
this is to avoid treesitter shitting itself
2024-04-28 18:52:13 +02:00

48 lines
1.5 KiB
C++

#pragma once
#include <iostream>
#include <string>
#define FG(r, g, b) "\033[38;2;" #r ";" #g ";" #b "m"
#define BG(r, g, b) "\033[48;2;" #r ";" #g ";" #b "m"
#define RESET "\033[0m"
#define TEST_START() \
int main() {\
uint tests_failed = 0;\
uint tests_total = 0;\
std::cout << "STARTING TEST FILE " << __FILE__ << "\n";
#define TEST_FINISH() \
std::cout << "FINISHED TEST FILE " << __FILE__ << "\n";\
std::cout << "PASSED TESTS: "\
<< (tests_failed != 0 ? BG(255, 0, 0) : BG(0, 255, 0))\
<< FG(0, 0, 0)\
<< (tests_total - tests_failed) << "/" << tests_total\
<< RESET\
<< "\n";\
return 0;\
}
#define assert(condition, message) \
asserts_total += 1;\
if (!(condition)) {\
asserts_failed += 1;\
std::cout << " " << BG(255, 0, 0) << FG(0, 0, 0) << #condition << ": " << message << " (" << __FILE__ << ":" << __LINE__ << ")" << RESET << "\n";\
}
#define TEST(name, ...) \
uint asserts_failed = 0;\
uint asserts_total = 0;\
tests_total += 1;\
std::cout << " RUNNING TEST `" << name << "`\n";\
__VA_ARGS__\
std::cout << " PASSED ASSERTS: "\
<< (asserts_failed != 0 ? BG(255, 0, 0) : BG(0, 255, 0))\
<< FG(0, 0, 0)\
<< (asserts_total - asserts_failed) << "/" << asserts_total\
<< RESET\
<< "\n";\
if (asserts_failed > 0) {\
tests_failed += 1;\
}