Simple C++ testing framework.
at master 792 B view raw
1#pragma once 2#include <string> 3#include <cstdint> 4#include <iostream> 5#include <exception> 6#include <format> 7using CString = const char *; 8using U64 = std::uint64_t; 9using String = std::string; 10 11enum class TestFail {}; 12 13auto red(String const& in) noexcept -> String; 14 15auto format_err(String const& test_name) noexcept -> String; 16 17class Test { 18 String test_name; 19 20 public: 21 Test(CString name); 22 23 void operator = (auto fn) { 24 if (fn()) { 25 std::cout << test_name << ": passed" << std::endl; 26 } else { 27 std::cerr << test_name << ": failed" << std::endl; 28 throw TestFail(); 29 } 30 } 31 32 33 void operator = (std::initializer_list<bool> checks); 34 35 void operator = (bool passed); 36}; 37 38Test operator ""_test(CString str, U64 length);