]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Rewrite the "show environment" test
authorTom Tromey <tromey@adacore.com>
Tue, 9 Dec 2025 14:57:51 +0000 (07:57 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 9 Dec 2025 18:26:37 +0000 (11:26 -0700)
In a review early in the year:

    https://inbox.sourceware.org/gdb-patches/874iz3f4ek.fsf@redhat.com/

Andrew pointed out that a new test I proposed failed with read1.
This test was essentially a copy of gdb.base/environ.exp.

I couldn't reproduce the read1 problem, but this patch rewrites the
one test there that seems like it could possibly fail in this mode.
Now it uses line-by-line mode and checks for a certain environment
variable appearing in the output.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/testsuite/gdb.base/environ.exp

index 36cc5f488135280a6283f89816c82d4ece41b792..091010acfda4a7ae23ec76b6f3067eabe5399c42 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-gdb_start
+# Make sure there is at least one environment variable.
+save_vars { env(GDB_TEST_ENV_VAR) } {
+    setenv GDB_TEST_ENV_VAR abc
+    gdb_start
+}
 
 proc test_set_show_env_var { name value test_name } {
     gdb_test_no_output "set environment $name $value" "$test_name"
@@ -29,11 +33,20 @@ proc test_set_show_env_var_equal { name value test_name } {
 
 # Verify that we can show all currently-set environment variables.
 # It's hard to do this verification since we can't really compare each
-# entry with the current environment.  So we just check to see if
-# there is anything that looks like an environment variable being
-# printed.
-gdb_test "show environment" "(\[A-Za-z_\]+=.*)+" \
-    "show environment works"
+# entry with the current environment.  So we just check to see if the
+# environment variable we set at startup is printed.
+set saw_env 0
+gdb_test_multiple "show environment" "show environment works" -lbl {
+    -re "\r\nGDB_TEST_ENV_VAR=abc" {
+       incr saw_env 1
+       exp_continue
+    }
+
+    -re "\r\n$gdb_prompt $" {
+    }
+}
+
+gdb_assert {$saw_env == 1} "show environment displayed variable"
 
 # Verify that we can unset a specific environment variable.
 gdb_test_no_output "unset environment EDITOR" "unset environment variable"