tests: cover colored Argparse help and NO_COLOR opt-out

This commit is contained in:
faumaray committed 2026-12-04 08:06:21 +03:00
1 parent 5e70ad2bc4
commit 3ce62c9cbd
1 file changed
+23
@@ -175,6 +175,29 @@ Void::Testing::Test argparse_unknown_option_is_error()
// ── help ──────────────────────────────────────────────────────────────────────
Void::Testing::Test argparse_help_color_default_and_toggle()
{
::unsetenv("NO_COLOR");
bool v = false;
Parser p{"tool"};
p.flag("--verbose", "-v", "verbose mode", v);
const auto colored = p.help();
Void::Testing::expect(colored.find("\033[") != std::string::npos);
Void::Testing::expect(colored.find("--verbose") != std::string::npos);
p.color(false);
const auto plain = p.help();
Void::Testing::expect(plain.find("\033[") == std::string::npos);
Void::Testing::expect(plain.find("--verbose") != std::string::npos);
// NO_COLOR disables styling even when the parser allows it.
p.color(true);
::setenv("NO_COLOR", "1", 1);
Void::Testing::expect(p.help().find("\033[") == std::string::npos);
::unsetenv("NO_COLOR");
}
Void::Testing::Test argparse_help_contains_names()
{
bool v = false;