public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb/testsuite: handle older Python versions in gdb.python/py-disasm.exp
Date: Fri, 19 May 2023 09:01:01 +0000 (GMT)	[thread overview]
Message-ID: <20230519090101.11DB13858D28@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=637969a709c4542702d283a0471c5364d26ba81b

commit 637969a709c4542702d283a0471c5364d26ba81b
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed May 17 18:39:26 2023 +0100

    gdb/testsuite: handle older Python versions in gdb.python/py-disasm.exp
    
    It was pointed out on the mailing list that the new tests added in
    this commit:
    
      commit 4de4e48514fc47aeb4ca95cd4091e2a333fbe9e1
      Date:   Tue Jan 24 15:35:45 2023 +0000
    
          gdb/python: extend the Python Disassembler API to allow for styling
    
    will fail when GDB is built with Python 3.6 or earlier.  This is
    because the error that is emitted when a function argument is missing
    changed in Python 3.7, instead of an error like this:
    
      Python Exception <class 'TypeError'>: function missing required argument 'style' (pos 1)
    
    earlier versions of Python emit:
    
      Python Exception <class 'TypeError'>: Required argument 'style' (pos 1) not found
    
    and the new tests didn't allow for this.
    
    This commit fixes this by allowing either pattern.  I've tested this
    building GDB against Python 3.7.9 and 3.6.15, with this commit all
    tests in gdb.python/py-disasm.exp now pass.

Diff:
---
 gdb/testsuite/gdb.python/py-disasm.exp | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp
index 304393f71ab..f2f9225168a 100644
--- a/gdb/testsuite/gdb.python/py-disasm.exp
+++ b/gdb/testsuite/gdb.python/py-disasm.exp
@@ -75,6 +75,16 @@ proc make_exception_pattern { type msg } {
     return "${::addr_pattern}Python Exception <class '$type'>: $msg\r\n\r\n${::unknown_error_pattern}"
 }
 
+# Helper proc to build a pattern for the text Python emits when a
+# function argument is missing.  This string changed in Python 3.7 and
+# later.  NAME is the parameter name, and POS is its integer position
+# in the argument list.
+proc missing_arg_pattern { name pos } {
+    set pattern_1 "function missing required argument '$name' \\(pos $pos\\)"
+    set pattern_2 "Required argument '$name' \\(pos $pos\\) not found"
+    return "(?:${pattern_1}|${pattern_2})"
+}
+
 set test_plans \
     [list \
 	 [list "" "${base_pattern}\r\n.*"] \
@@ -113,16 +123,16 @@ set test_plans \
 		   "Result is not a DisassemblerResult."]] \
 	 [list "ErrorCreatingTextPart_NoArgs" \
 	      [make_exception_pattern "TypeError" \
-		  "function missing required argument 'style' \\(pos 1\\)"]] \
+		   [missing_arg_pattern "style" 1]]] \
 	 [list "ErrorCreatingAddressPart_NoArgs" \
 	      [make_exception_pattern "TypeError" \
-		  "function missing required argument 'address' \\(pos 1\\)"]] \
+		   [missing_arg_pattern "address" 1]]] \
 	 [list "ErrorCreatingTextPart_NoString" \
 	      [make_exception_pattern "TypeError" \
-		  "function missing required argument 'string' \\(pos 2\\)"]] \
+		   [missing_arg_pattern "string" 2]]] \
 	 [list "ErrorCreatingTextPart_NoStyle" \
 	      [make_exception_pattern "TypeError" \
-		  "function missing required argument 'style' \\(pos 1\\)"]] \
+		   [missing_arg_pattern "style" 1]]] \
 	 [list "All_Text_Part_Styles" "${addr_pattern}p1p2p3p4p5p6p7p8p9p10\r\n.*"] \
 	 [list "ErrorCreatingTextPart_StringAndParts" \
 	      [make_exception_pattern "ValueError" \
@@ -273,7 +283,7 @@ with_test_prefix "check inheritance" {
 # Test some error conditions when creating a DisassemblerResult object.
 gdb_test "python result = gdb.disassembler.DisassemblerResult()" \
     [multi_line \
-	 "TypeError: function missing required argument 'length' \\(pos 1\\)" \
+	 "TypeError: [missing_arg_pattern length 1]" \
 	 "Error while executing Python code\\."] \
     "try to create a DisassemblerResult without a length argument"

                 reply	other threads:[~2023-05-19  9:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519090101.11DB13858D28@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).