aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-09-15 17:24:26 -0600
committerTom Tromey <tom@tromey.com>2023-09-29 10:55:43 -0600
commit4ebfd53de03599b73838ee339e47652ac26c37c0 (patch)
tree5990de5f860d32aa252dfb7564fbbb56179f737c /gdb/testsuite
parent2677a57064afd32076b85295bdc11de6e75e7e36 (diff)
downloadgdb-4ebfd53de03599b73838ee339e47652ac26c37c0.zip
gdb-4ebfd53de03599b73838ee339e47652ac26c37c0.tar.gz
gdb-4ebfd53de03599b73838ee339e47652ac26c37c0.tar.bz2
Support the NO_COLOR environment variable
I ran across this site: https://no-color.org/ ... which lobbies for tools to recognize the NO_COLOR environment variable and disable any terminal styling when it is seen. This patch implements this for gdb. Regression tested on x86-64 Fedora 38. Co-Authored-By: Andrew Burgess <aburgess@redhat.com> Reviewed-by: Kevin Buettner <kevinb@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/early-init-file.exp4
-rw-r--r--gdb/testsuite/gdb.base/readline-ask.exp2
-rw-r--r--gdb/testsuite/gdb.base/style-interp-exec-mi.exp5
-rw-r--r--gdb/testsuite/gdb.base/style-logging.exp5
-rw-r--r--gdb/testsuite/gdb.base/style.exp11
-rw-r--r--gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp5
-rw-r--r--gdb/testsuite/gdb.debuginfod/crc_mismatch.exp5
-rw-r--r--gdb/testsuite/gdb.python/py-format-string.exp3
-rw-r--r--gdb/testsuite/gdb.python/py-source-styling.exp4
-rw-r--r--gdb/testsuite/gdb.python/py-startup-opt.exp5
-rw-r--r--gdb/testsuite/gdb.rust/rust-style.exp5
-rw-r--r--gdb/testsuite/gdb.tui/tui-layout.exp18
-rw-r--r--gdb/testsuite/lib/gdb.exp21
-rw-r--r--gdb/testsuite/lib/tuiterm.exp3
14 files changed, 49 insertions, 47 deletions
diff --git a/gdb/testsuite/gdb.base/early-init-file.exp b/gdb/testsuite/gdb.base/early-init-file.exp
index 237439f..6426da8 100644
--- a/gdb/testsuite/gdb.base/early-init-file.exp
+++ b/gdb/testsuite/gdb.base/early-init-file.exp
@@ -99,9 +99,7 @@ proc check_gdb_startups_up_quietly { message } {
}
}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
+with_ansi_styling_terminal {
# Start GDB and confirm that the version string is styled.
save_vars { INTERNAL_GDBFLAGS env(HOME) env(XDG_CONFIG_HOME) } {
diff --git a/gdb/testsuite/gdb.base/readline-ask.exp b/gdb/testsuite/gdb.base/readline-ask.exp
index 51bf642..ff33c83 100644
--- a/gdb/testsuite/gdb.base/readline-ask.exp
+++ b/gdb/testsuite/gdb.base/readline-ask.exp
@@ -21,6 +21,8 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}]
return -1
}
+setenv TERM dumb
+
# INPUTRC gets reset for the next testfile.
setenv INPUTRC $inputrc
clean_restart ${binfile}
diff --git a/gdb/testsuite/gdb.base/style-interp-exec-mi.exp b/gdb/testsuite/gdb.base/style-interp-exec-mi.exp
index 9b2ed87..b99e767 100644
--- a/gdb/testsuite/gdb.base/style-interp-exec-mi.exp
+++ b/gdb/testsuite/gdb.base/style-interp-exec-mi.exp
@@ -23,10 +23,7 @@
standard_testfile
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
if { [prepare_for_testing "failed to prepare" \
${testfile} ${srcfile}] } {
return
diff --git a/gdb/testsuite/gdb.base/style-logging.exp b/gdb/testsuite/gdb.base/style-logging.exp
index a156c39..c21c332 100644
--- a/gdb/testsuite/gdb.base/style-logging.exp
+++ b/gdb/testsuite/gdb.base/style-logging.exp
@@ -22,10 +22,7 @@ require {!is_remote host}
standard_testfile style.c
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 60f909e..7ee1b44 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -69,10 +69,7 @@ proc run_style_tests { } {
global testfile srcfile hex binfile
global currently_disabled_style decimal hex
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
clean_restart_and_disable "restart 1" ${binfile}
@@ -319,9 +316,10 @@ proc run_style_tests { } {
# Python pygments module is not available, so, when we disable
# disassembler styling, we should always see a change in output.
proc test_disable_disassembler_styling { } {
- save_vars { env(TERM) } {
+ save_vars { env(TERM) env(NO_COLOR) } {
# We need an ANSI-capable terminal to get the output.
setenv TERM ansi
+ setenv NO_COLOR ""
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
@@ -427,9 +425,10 @@ proc test_disassembler_error_handling { } {
return
}
- save_vars { env(TERM) } {
+ save_vars { env(TERM) env(NO_COLOR) } {
# We need an ANSI-capable terminal to get the output.
setenv TERM ansi
+ setenv NO_COLOR ""
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
diff --git a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
index 148363a..8ee3bb0 100644
--- a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
+++ b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
@@ -98,10 +98,7 @@ gdb_test "file ${build_id_debug_file}" \
# Do the same thing again, but this time check that the styling is
# correct.
with_test_prefix "check styling" {
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get styled output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
clean_restart
gdb_test_no_output "set debug-file-directory ${debug_file_directory}" \
diff --git a/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp b/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp
index 074028e..e88c4b3 100644
--- a/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp
+++ b/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp
@@ -71,10 +71,7 @@ if {[build_executable crc_mismatch.exp crc_mismatch-2 crc_mismatch-2.c debug] !=
# Do the same thing again, but this time check that the styling is
# correct.
with_test_prefix "check styling" {
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get styled output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
clean_restart
set debug_file_re [style "${escapedobjdirsubdir}/crc_mismatch-2\\.debug" file]
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp
index 55a3776..04d19e4 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -1184,11 +1184,10 @@ with_test_prefix "format_string" {
# Perform C Tests.
if { [build_inferior "${binfile}" "c"] == 0 } {
with_test_prefix "lang_c" {
- save_vars { env(TERM) } {
+ with_ansi_styling_terminal {
# We run all of these tests in an environment where styling
# could work, but we only expect the final call to
# test_styling to actually produce any styled output.
- setenv TERM ansi
set current_lang "c"
prepare_gdb "${binfile}"
test_all_common
diff --git a/gdb/testsuite/gdb.python/py-source-styling.exp b/gdb/testsuite/gdb.python/py-source-styling.exp
index f92d6f7..d3ae339 100644
--- a/gdb/testsuite/gdb.python/py-source-styling.exp
+++ b/gdb/testsuite/gdb.python/py-source-styling.exp
@@ -20,13 +20,11 @@ load_lib gdb-python.exp
standard_testfile
-save_vars { env(TERM) } {
+with_ansi_styling_terminal {
# We need an ANSI-capable terminal to get the output, additionally
# we need to set LC_ALL so GDB knows the terminal is UTF-8
# capable, otherwise we'll get a UnicodeEncodeError trying to
# encode the output.
- setenv TERM ansi
-
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index 08d1c79..729b1c1 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -97,10 +97,7 @@ proc test_python_settings { exp_state } {
gdb_exit
}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
# Check the features are off by default.
test_python_settings "off"
diff --git a/gdb/testsuite/gdb.rust/rust-style.exp b/gdb/testsuite/gdb.rust/rust-style.exp
index 0555ea4..b4ea05c 100644
--- a/gdb/testsuite/gdb.rust/rust-style.exp
+++ b/gdb/testsuite/gdb.rust/rust-style.exp
@@ -19,10 +19,7 @@ load_lib rust-support.exp
require allow_rust_tests
require {can_compile rust}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
{debug rust}]} {
diff --git a/gdb/testsuite/gdb.tui/tui-layout.exp b/gdb/testsuite/gdb.tui/tui-layout.exp
index 1382338..90f27c5 100644
--- a/gdb/testsuite/gdb.tui/tui-layout.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout.exp
@@ -44,13 +44,17 @@ proc test_layout_or_focus {layout_name terminal execution} {
set dumb_terminal [string equal $terminal "dumb"]
- if {$dumb_terminal} {
- clean_restart $binfile
- } else {
- Term::clean_restart 24 80 $binfile
- if {![Term::prepare_for_tui]} {
- unsupported "TUI not supported"
- return
+ global env
+ save_vars { env(TERM) } {
+ setenv TERM $terminal
+ if {$dumb_terminal} {
+ clean_restart $binfile
+ } else {
+ Term::clean_restart 24 80 $binfile
+ if {![Term::prepare_for_tui]} {
+ unsupported "TUI not supported"
+ return
+ }
}
}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1b91794..de22da8 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6468,7 +6468,7 @@ proc default_gdb_init { test_file_name } {
# This disables style output, which would interfere with many
# tests.
- setenv TERM "dumb"
+ setenv NO_COLOR sorry
# This setting helps detect bugs in the Python code and doesn't
# seem to have a significant downside for the tests.
@@ -9238,6 +9238,25 @@ proc with_override { name override body } {
return $result
}
+# Run BODY after setting the TERM environment variable to 'ansi', and
+# unsetting the NO_COLOR environment variable.
+proc with_ansi_styling_terminal { body } {
+ save_vars { ::env(TERM) ::env(NO_COLOR) } {
+ # Set environment variables to allow styling.
+ setenv TERM ansi
+ unset -nocomplain ::env(NO_COLOR)
+
+ set code [catch {uplevel 1 $body} result]
+ }
+
+ if {$code == 1} {
+ global errorInfo errorCode
+ return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+ } else {
+ return -code $code $result
+ }
+}
+
# Setup tuiterm.exp environment. To be used in test-cases instead of
# "load_lib tuiterm.exp". Calls initialization function and schedules
# finalization function.
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 598c1f8..854fde5 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -844,8 +844,9 @@ namespace eval Term {
# BODY.
proc with_tuiterm {rows cols body} {
global env stty_init
- save_vars {env(TERM) stty_init} {
+ save_vars {env(TERM) env(NO_COLOR) stty_init} {
setenv TERM ansi
+ setenv NO_COLOR ""
_setup $rows $cols
uplevel $body