autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] autotest: Respect NO_COLOR in test suites.


From: Nick Bowler
Subject: [PATCH v2] autotest: Respect NO_COLOR in test suites.
Date: Sat, 7 Dec 2024 22:23:22 -0500

This implements support for NO_COLOR in test suites using AT_COLOR_TESTS
to enable colour by default.  NO_COLOR is an informal standard[1] way
for users to express their preference to not use colours by default.

If NO_COLOR is set in the environment to anything other than the empty
string, the default should be "no colour" (but the command-line --color
option is expected to work as usual).

[1] http://no-color.org

* lib/autotest/general.m4 (AT_INIT): Respect user NO_COLOR setting
to restrict enabling of ANSI colours by default.
* doc/autoconf.texi (Writing testsuite.at): Describe effect of NO_COLOR.
* NEWS: Mention the change.
---
 NEWS                    | 2 ++
 doc/autoconf.texi       | 6 ++++--
 lib/autotest/general.m4 | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

v2: Update NEWS and the manual.

diff --git a/NEWS b/NEWS
index bde1ccd0..e4f60423 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,8 @@ GNU Autoconf NEWS - User visible changes.
   The autom4te, autoscan and ifnames programs now recognize the two
   preprocessor directives, which were introduced in C23 and C++23.
 
+*** Autotest test suites built using AT_COLOR_TESTS now respect NO_COLOR.
+
 ** Notable bug fixes
 
 *** AC_FUNC_STRNLEN now detects Android 5.0's broken strnlen.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index dd0b1fa2..bc5e142e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -25273,8 +25273,10 @@ names in order to avoid clashes with future Autotest 
built-in options.
 
 @defmac AT_COLOR_TESTS
 @atindex{COLOR_TESTS}
-Enable colored test results by default when the output is connected to
-a terminal.
+@evindex NO_COLOR
+Unless the user has set the @uref{http://no-color.org, @env{NO_COLOR}
+environment variable} to a nonempty value, enable colored test results
+by default when the output is connected to a terminal.
 @end defmac
 
 @defmac AT_TESTED (@var{executables})
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 6b4c3ae5..b5388da4 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -446,7 +446,9 @@ m4_define([_AT_FINISH],
 m4_divert_text([DEFAULTS],
 [
 # Whether to enable colored test results.
-at_color=m4_ifdef([AT_color], [AT_color], [no])
+m4_ifdef([AT_color],
+  [AS_CASE([$NO_COLOR], [''], [at_color=auto], [at_color=no])],
+  [at_color=no])
 # As many question marks as there are digits in the last test group number.
 # Used to normalize the test group numbers so that 'ls' lists them in
 # numerical order.
-- 
2.45.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]