From 3ce62c9cbdd439ed086ddae5f98019603f79b87a Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 08:06:21 +0300 Subject: [PATCH] tests: cover colored Argparse help and NO_COLOR opt-out --- tests/standalone/Configuration/Argparse.cpp | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/standalone/Configuration/Argparse.cpp b/tests/standalone/Configuration/Argparse.cpp index 2f9e04c..cfaf142 100644 --- a/tests/standalone/Configuration/Argparse.cpp +++ b/tests/standalone/Configuration/Argparse.cpp @@ -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;