osuplusplus/test/test.hpp

51 lines
1.5 KiB
C++
Raw Permalink Normal View History

2024-04-28 17:43:53 +02:00
#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 tests_failed;\
2024-04-28 17:43:53 +02:00
}
#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;\
}\
2024-04-28 17:43:53 +02:00
}