Semantic names for tester

This commit is contained in:
xenia 2024-01-17 14:46:35 +01:00
parent cdf37168cf
commit 388c24ec78

View File

@ -3,11 +3,11 @@
#include "tester.hpp"
const std::string ANSI_RESET = "\033[0m";
const std::string ANSI_DARK = "\033[38;5;8m";
const std::string ANSI_BLUE = "\033[38;5;6m";
const std::string ANSI_GREEN = "\033[38;5;2m";
const std::string ANSI_RED = "\033[38;5;1m";
const std::string ANSI_YELLOW = "\033[38;5;11m";
const std::string ANSI_DARK = "\033[38;5;8m"; // dark gray
const std::string ANSI_LISTING = "\033[38;5;208m"; // orange
const std::string ANSI_INFO = "\033[38;5;6m"; // blue
const std::string ANSI_SUCCESS = "\033[38;5;2m"; // green
const std::string ANSI_FAIL = "\033[38;5;1m"; // red
Tester::Tester(std::string test_name) :
parent(),
@ -66,7 +66,7 @@ std::string Tester::prefix() {
int wanted_len = 10 * depth();
if (line.length() == wanted_len) {
line.insert(0, ANSI_BLUE);
line.insert(0, ANSI_LISTING);
line.append(ANSI_RESET);
line.append(" ");
return line;
@ -76,7 +76,7 @@ std::string Tester::prefix() {
for (int i = 0; i < wanted_len; i++)
line.append("");
line.insert(0, ANSI_BLUE);
line.insert(0, ANSI_LISTING);
line.append(ANSI_RESET);
line.append(" ");
return line;
@ -87,7 +87,7 @@ std::string Tester::prefix() {
for (int i = 1; i < extra; i++)
line.append("");
line.insert(0, ANSI_BLUE);
line.insert(0, ANSI_LISTING);
line.append(ANSI_RESET);
line.append(" ");
return line;
@ -96,7 +96,7 @@ std::string Tester::prefix() {
void Tester::intro() {
if (shown())
std::cout << prefix() << "=== " << ANSI_YELLOW << "start" << ANSI_RESET << std::endl;
std::cout << prefix() << "=== " << ANSI_INFO << "start" << ANSI_RESET << std::endl;
}
bool name_show_overwritten(std::string name) {
@ -130,13 +130,13 @@ bool Tester::shown() {
void Tester::assert_eq_str(std::string test_name, bool correct, std::string got_s, std::string expected_s) {
if (correct) {
if (shown()) {
std::cout << prefix() << ANSI_GREEN << "" << ANSI_RESET << test_name << ANSI_RESET << std::endl;
std::cout << prefix() << ANSI_SUCCESS << "" << ANSI_RESET << test_name << ANSI_RESET << std::endl;
}
for (std::optional<Tester*> at = this; at.has_value(); at = (*at)->parent) {
(*at)->succeeded++;
}
} else {
std::cout << prefix() << ANSI_RED << "" << ANSI_RESET << test_name << " - " << ANSI_RED << "got " << got_s << ", expected " << expected_s << ANSI_RESET << std::endl;
std::cout << prefix() << ANSI_FAIL << "" << ANSI_RESET << test_name << " - " << ANSI_FAIL << "got " << got_s << ", expected " << expected_s << ANSI_RESET << std::endl;
for (std::optional<Tester*> at = this; at.has_value(); at = (*at)->parent) {
(*at)->failed++;
}
@ -180,13 +180,13 @@ void Tester::finish() {
bool printed = false;
if (failed == 0) {
if (shown()) {
std::cout << prefix() << "=== " << ANSI_GREEN << "all succeeded" << ANSI_RESET << ", out of " << n_cases_s << " total";
std::cout << prefix() << "=== " << ANSI_SUCCESS << "all succeeded" << ANSI_RESET << ", out of " << n_cases_s << " total";
printed = true;
}
} else {
std::cout << prefix() << "=== " << ANSI_RED << n_failed_s << " failed" << ANSI_RESET << ", " << ANSI_GREEN << n_succeeded_s << " succeeded" << ANSI_RESET << " out of " << n_cases_s << " total";
std::cout << prefix() << "=== " << ANSI_FAIL << n_failed_s << " failed" << ANSI_RESET << ", " << ANSI_SUCCESS << n_succeeded_s << " succeeded" << ANSI_RESET << " out of " << n_cases_s << " total";
printed = true;
}
if (printed)
std::cout << " (" << ANSI_YELLOW << time_s << ANSI_RESET << " total, " << ANSI_YELLOW << time_per_s << ANSI_RESET << " per test)" << std::endl;
std::cout << " (" << ANSI_INFO << time_s << ANSI_RESET << " total, " << ANSI_INFO << time_per_s << ANSI_RESET << " per test)" << std::endl;
}