Kumo

A hand-rolled game engine.

git clone https://git.sentomk.me/Kumo.git
commit 648327d8a864296051e1f7f51e43bf623ce319cb
parent 30af7b196ad6db646af367e39859050386f58fcf
Author: sentomk <sentomk@proton.me>
Date:   Wed, 14 Oct 2026 16:25:15 +0800

style: align the lines of the test output

The verdict (PASS, FAIL, CRASH) is padded like the labels of the other lines,
so that the names of all the lines start in the same column, and the time of
a test program is right aligned. The names of the test cases are padded to one
width shared by all the programs instead of the longest of each, which puts
the results of every program in the same column. A longer name only moves
the column of its own program.

Diffstat:
Mkumo_builder.cpp | 31+++++++++++++++++++------------
Mtests/check.h | 8++++++--
2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/kumo_builder.cpp b/kumo_builder.cpp @@ -203,6 +203,12 @@ static std::string pad(const std::string& text, size_t width) { : text + std::string(width - text.size(), ' '); } +/// @brief Pads @p text with spaces on the left up to @p width characters. +static std::string pad_left(const std::string& text, size_t width) { + return text.size() >= width ? text + : std::string(width - text.size(), ' ') + text; +} + /// @brief "1 test program" or "3 test programs". static std::string plural(size_t count, const std::string& noun) { return std::to_string(count) + " " + noun + (count == 1 ? "" : "s"); @@ -1588,18 +1594,19 @@ int main(int argc, char** argv) { !status.ok() && !(status.signal == 0 && status.code == 1); // A crash leaves the line of the test case that was running unfinished. if (crashed && !quiet) std::printf("\n"); - if (status.ok()) { - std::printf("%s %s %s\n", paint(Style::Green, "PASS ").c_str(), - pad(name, name_width).c_str(), - paint(Style::Dim, took).c_str()); - } else { - failed.push_back(name); - std::printf( - "%s %s %s%s\n", - paint(Style::Red, crashed ? "CRASH" : "FAIL ").c_str(), - pad(name, name_width).c_str(), paint(Style::Dim, took).c_str(), - crashed ? (" " + paint(Style::Red, describe(status))).c_str() : ""); - } + // The verdict is in the same column as the labels of the other lines, the + // name is padded to the longest one and the time is right aligned, so that + // the lines of all the programs line up. + const std::string verdict = status.ok() ? "PASS" + : crashed ? "CRASH" + : "FAIL"; + if (!status.ok()) failed.push_back(name); + std::printf( + "%s %s %s%s\n", + paint(status.ok() ? Style::Green : Style::Red, pad(verdict, 8)).c_str(), + pad(name, name_width).c_str(), + paint(Style::Dim, pad_left(took, 7)).c_str(), + crashed ? (" " + paint(Style::Red, describe(status))).c_str() : ""); } const std::string total = " in " + format_duration(Clock::now() - began); diff --git a/tests/check.h b/tests/check.h @@ -157,7 +157,11 @@ int main(int argc, char** argv) { return color ? std::string("\033[") + code + "m" + text + "\033[0m" : text; }; - size_t width = 0; + // The names are padded to one width for every program, not to the longest of + // each, so that the results line up from one program to the next. A longer + // name only moves the column of its own program. + constexpr size_t kNameWidth = 60; + size_t width = kNameWidth; for (const kumo_test::Case& test : kumo_test::cases()) { width = std::max(width, std::string(test.name).size()); } @@ -190,7 +194,7 @@ int main(int argc, char** argv) { // On a terminal, erase "running" and write the result in its place. if (live) std::printf("\r\033[2K%s", label.c_str()); std::printf( - "%s %s\n", + "%s %s\n", failed ? paint("31", "FAIL").c_str() : paint("32", "ok ").c_str(), paint("2", kumo_test::pad_left(took, 6)).c_str()); std::fflush(stdout);