[binutils-gdb] [gdb/testsuite] Fix Term::_TERM setting leak in Term::with_tuiterm

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dc3229016dffaad10a30ba381849f603790b31c5

commit dc3229016dffaad10a30ba381849f603790b31c5
Author: Tom de Vries <[email protected]>
Date:   Fri Mar 20 10:13:27 2026 +0100

    [gdb/testsuite] Fix Term::_TERM setting leak in Term::with_tuiterm
    
    Add a test for proc Term::with_tuiterm in gdb.tui/tuiterm.exp, and fix that a
    local Term::_TERM setting leaks out of the proc.
    
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/testsuite/gdb.tui/tuiterm.exp | 20 ++++++++++++++++++++
 gdb/testsuite/lib/tuiterm.exp     |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index e23209ad1f7..beab9f7a304 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -821,6 +821,25 @@ proc_with_prefix test_with_term {} {
     }
 }
 
+proc_with_prefix test_with_tuiterm {} {
+    with_test_prefix pre {
+	gdb_assert {$Term::_TERM == ""}
+    }
+
+    save_vars ::env(TERM) {
+	setenv TERM foo
+	Term::with_tuiterm 24 80 {
+	    gdb_assert {$::env(TERM) != "foo"}
+	    gdb_assert {$Term::_TERM != "foo"}
+	}
+	gdb_assert {$::env(TERM) == "foo"}
+    }
+
+    with_test_prefix post {
+	gdb_assert {$Term::_TERM == ""}
+    }
+}
+
 # Run proc TEST_PROC_NAME with a "small" terminal.
 
 proc run_one_test_small { test_proc_name } {
@@ -877,3 +896,4 @@ foreach_with_prefix test {
 test_attrs
 
 test_with_term
+test_with_tuiterm
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 5c73106822c..a1c841ebcee 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -1247,7 +1247,7 @@ proc Term::with_term { term body } {
 proc Term::with_tuiterm {rows cols body} {
     global env stty_init
     variable _TERM
-    save_vars {env(TERM) env(NO_COLOR) stty_init} {
+    save_vars {env(TERM) _TERM env(NO_COLOR) stty_init} {
 	if { $Term::_TERM != "" } {
 	    setenv TERM $Term::_TERM
 	} elseif { [ishost *-*-*bsd*] } {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.