[1/2,gdb/testsuite] Fix gdb.python/py-startup-opt.exp with empty PYTHONDONTWRITEBYTECODE

Message ID 20241125101010.9825-2-tdevries@suse.de
State Committed
Headers
Series Handle empty PYTHONDONTWRITEBYTECODE |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Nov. 25, 2024, 10:10 a.m. UTC
  When running test-case gdb.python/py-startup-opt.exp with empty
PYTHONDONTWRITEBYTECODE:
...
$ cd build/gdb/testsuite
$ PYTHONDONTWRITEBYTECODE= make check \
    RUNTESTFLAGS=gdb.python/py-startup-opt.exp
...
I get:
...
end^M
dont_write_bytecode is off^M
(gdb) FAIL: $exp: attr=dont_write_bytecode: testname: input 6: end
...

The problem is that the test-case expects dont_write_bytecode to be
on, which is incorrect because PYTHONDONTWRITEBYTECODE only has effect if set
to a non-empty string [1].

Fix this by correctly setting expectations in the test-case.

Tested on x86_64-linux, with:
- PYTHONDONTWRITEBYTECODE=
- PYTHONDONTWRITEBYTECODE=1
- unset PYTHONDONTWRITEBYTECODE

[1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
---
 gdb/testsuite/gdb.python/py-startup-opt.exp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index cf2a2cf6768..014aff5725a 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -78,8 +78,9 @@  proc test_python_settings { exp_state } {
 	# all GDB developers some will test GDB with this environment
 	# variable unset.
 	if { $attr == "dont_write_bytecode" \
-		 && $exp_state == "off"
-		 && [info exists ::env(PYTHONDONTWRITEBYTECODE)] } {
+		 && $exp_state == "off" \
+		 && [info exists ::env(PYTHONDONTWRITEBYTECODE)] \
+		 && $::env(PYTHONDONTWRITEBYTECODE) != "" } {
 	    set answer "on"
 	} else {
 	    set answer $exp_state