Skip to content

Commit

Permalink
feat: overloads for the stylizer, so there's no need for std::initial…
Browse files Browse the repository at this point in the history
…izer list braces nor std::vector, and other more for when there's no need for using a modifier
  • Loading branch information
TheRustifyer committed Aug 16, 2024
1 parent dda11a7 commit 186e77a
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 158 deletions.
35 changes: 17 additions & 18 deletions zero/ifc/test-suite/suite.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,11 @@ export {
tsuite.cases.emplace_back(new TestCase(tname, tfunc));
else
tsuite.results.warnings.emplace_back(
stylize("[Warning in suite: ", Color::YELLOW, {}) +
stylize(tsuite.uuid, Color::EXT_PURPLE, {}) +
stylize("] Already exists a test case with the name: ",
Color::YELLOW, {}) +
stylize(tname, Color::EXT_SKY_BLUE, {}) +
stylize(". Skipping test case.", Color::YELLOW, {})
stylize("[Warning in suite: ", Color::YELLOW) +
stylize(tsuite.uuid, Color::EXT_PURPLE) +
stylize("] Already exists a test case with the name: ", Color::YELLOW) +
stylize(tname, Color::EXT_SKY_BLUE) +
stylize(". Skipping test case.", Color::YELLOW)
);

/// If this is the first time that the suite is being registered
Expand Down Expand Up @@ -287,7 +286,7 @@ void runSuiteTestCases(const TestRunBehavior behavior) {

for (const auto &test_suite : testSuites) {
print_separator();
println("- Running test suite:" + stylize(" {}", Color::EXT_PURPLE, {}), test_suite->uuid);
println("- Running test suite:" + stylize(" {}", Color::EXT_PURPLE), test_suite->uuid);

for (const auto &warning : test_suite->results.warnings)
println(" {}", warning);
Expand All @@ -300,7 +299,7 @@ void runSuiteTestCases(const TestRunBehavior behavior) {
"\n[Halt Suite Tests] Stopping further tests "
"of the suite ",
Color::EXT_LIGHT_ORANGE, {Modifier::BOLD}) +
stylize("{} ", Color::EXT_PURPLE, {}) +
stylize("{} ", Color::EXT_PURPLE) +
stylize(
"due to a failure."
"\n========================================",
Expand All @@ -311,25 +310,25 @@ void runSuiteTestCases(const TestRunBehavior behavior) {

if (behavior == ABORT_ALL_ON_FAIL) {
println("Test suite [{}] summary:", test_suite->uuid);
println(stylize(" Passed: {}", Color::GREEN, {}),
println(stylize(" Passed: {}", Color::GREEN),
test_suite->results.passed);
println(stylize(" Failed: {}", Color::RED, {}),
println(stylize(" Failed: {}", Color::RED),
test_suite->results.failed);

println(
stylize("\n========================================"
"\n[Abort] All further tests are aborted due "
"to a failure in a test in this suite."
"\n========================================",
Color::RED, {Modifier::BOLD}));
Color::RED, Modifier::BOLD));
return;
}
}
}

println("- Test suite [{}] summary:", test_suite->uuid);
println(stylize("\tPassed: {}", Color::GREEN, {}), test_suite->results.passed);
println(stylize("\tFailed: {}", Color::RED, {}), test_suite->results.failed); // TODO:
println(stylize("\tPassed: {}", Color::GREEN), test_suite->results.passed);
println(stylize("\tFailed: {}", Color::RED), test_suite->results.failed); // TODO:
// Add the names of the FAILED test cases?
print_separator();
}
Expand All @@ -351,9 +350,9 @@ bool runFreeTestCases(const TestRunBehavior behavior) {
}

println("\nFree tests summary:");
println(stylize(" Passed: {}", Color::GREEN, {}),
println(stylize(" Passed: {}", Color::GREEN),
freeTestsResults.passed);
println(stylize(" Failed: {}", Color::RED, {}), freeTestsResults.failed);
println(stylize(" Failed: {}", Color::RED), freeTestsResults.failed);

if (anyFailed) {
if (behavior == HALT_SUITE_ON_FAIL) {
Expand All @@ -376,15 +375,15 @@ bool runFreeTestCases(const TestRunBehavior behavior) {
}

bool runTest(const TestCase *const testCase, TestResults &results) {
print(" [[Test]]: {}", stylize(testCase->name, Color::EXT_SKY_BLUE, {}));
print(" [[Test]]: {}", stylize(testCase->name, Color::EXT_SKY_BLUE));
try {
// Call the test function
testCase->fn();
println(" ... => {}", stylize("Passed!", Color::GREEN, {}));
println(" ... => {}", stylize("Passed!", Color::GREEN));
results.passed++;
return true;
} catch (const std::exception &ex) {
println(" ... => {}:\n\t{}", stylize("Failed", Color::RED, {}), ex.what());
println(" ... => {}:\n\t{}", stylize("Failed", Color::RED), ex.what());
results.failed++;
return false;
}
Expand Down
1 change: 0 additions & 1 deletion zero/ifc/text/print_utils.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import formatter;


export namespace zero::fmt {

template<typename... Args>
constexpr void print(const std::string& format, Args... args) {
std::cout << formatter(format, args...);
Expand Down
Loading

0 comments on commit 186e77a

Please sign in to comment.