[binutils-gdb] [gdb/testsuite] Improve gdb.python/remove-readline-finder.exp

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=b7da195b94b423e5cfd27a14c636ffe9f7380cdd

commit b7da195b94b423e5cfd27a14c636ffe9f7380cdd
Author: Tom de Vries <[email protected]>
Date:   Wed Aug 5 15:08:03 2026 +0200

    [gdb/testsuite] Improve gdb.python/remove-readline-finder.exp
    
    I came across test-case gdb.python/remove-readline-finder.exp.
    
    It checks that a "python import readline" command fails.
    
    Extend the test-case with also checking that the readline module is not
    present in the sys.modules dict.
    
    While we're at it, modernize a regexp using multi_line.
    
    Tested on x86_64-linux (using make-check-all.sh) and aarch64-linux.

Diff:
---
 gdb/testsuite/gdb.python/remove-readline-finder.exp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.python/remove-readline-finder.exp b/gdb/testsuite/gdb.python/remove-readline-finder.exp
index 362e90e6b7c..325e9710e28 100644
--- a/gdb/testsuite/gdb.python/remove-readline-finder.exp
+++ b/gdb/testsuite/gdb.python/remove-readline-finder.exp
@@ -23,5 +23,21 @@ standard_testfile
 
 clean_restart
 
+gdb_test_no_output "py import sys"
+
+# Check that readline is not imported.
+with_test_prefix initial {
+    gdb_test "py print (sys.modules.get('readline'))" \
+       "None"
+}
+
+# Try to import readline, and check that it fails.
+set re_msg "readline module disabled under GDB"
 gdb_test "py import readline" \
-  "Python Exception <class 'ImportError'>: readline module disabled under GDB\r\n.*"
+    [multi_line \
+	"Python Exception <class 'ImportError'>: $re_msg" \
+	"Error occurred in Python: $re_msg"]
+
+# Check that readline is still not imported.
+gdb_test "py print (sys.modules.get('readline'))" \
+    "None"
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.