Simple C++ testing framework.
1#include "test.hpp"
2
3
4Test::Test(CString name) {
5 this->test_name = name;
6}
7
8void Test::operator = (std::initializer_list<bool> checks) {
9 std::cout << test_name << std::endl;
10 U64 counter = 0;
11 for (auto check : checks) {
12 if (check) {
13 std::cout << "\t| " << counter << ": passed";
14 } else {
15 std::cerr << format_err(test_name) << std::endl;
16 throw TestFail();
17 }
18 ++counter;
19 std::cout << std::endl;
20 }
21}
22
23Test operator ""_test(CString str, U64 length) {
24 static_cast<void>(length);
25 return Test(str);
26}
27
28void Test::operator = (bool passed) {
29 if (passed) {
30 std::cout << test_name << ": passed" << std::endl;
31 } else {
32 std::cerr << format_err(test_name) << std::endl;
33 throw TestFail();
34 }
35}
36
37auto red(String const& str) noexcept -> String {
38 auto const prefix = "\033[31m";
39 auto const suffix = "\033[0m";
40 return prefix + str + suffix;
41}
42
43auto format_err(String const& test_name) noexcept -> String {
44 return test_name + ": " + red("failed");
45}
46