public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bruno Larsen <blarsen@redhat.com>
To: gdb-patches@sourceware.org
Cc: Bruno Larsen <blarsen@redhat.com>
Subject: [PATCH v2] gdb/testsuite: fix completion tests when using READ1
Date: Fri,  4 Aug 2023 18:09:24 +0200	[thread overview]
Message-ID: <20230804160924.1338942-1-blarsen@redhat.com> (raw)

The commit a3da2e7e550c4fe79128b5e532dbb90df4d4f418 has introduced
regressions when testing using the READ1 mechanism. The reason for that
is the new failure path in proc test_gdb_complete_tab_unique, which
looks for GDB suggesting more than what the test inputted, but not the
correct answer, followed by a white space. Consider the following case:

int foo(int bar, int baz);

Sending the command "break foo<tab>" to GDB will return

break foo(int, int)

which easily fits the buffer in normal testing, so everything works, but
when reading one character at a time, the test will find the partial
"break foo(int, " and assume that there was a mistake, so we get a
spurious FAIL.

To fix this issue, the new code looks at the partial response, and the
test only fails if the received characters are not part of the expected
pattern.
---
 gdb/testsuite/lib/completion-support.exp | 33 ++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp
index ea73c3bb367..bef4d7f1ed7 100644
--- a/gdb/testsuite/lib/completion-support.exp
+++ b/gdb/testsuite/lib/completion-support.exp
@@ -71,6 +71,16 @@ proc make_cmd_completion_list_re { cmd_prefix completion_list start_quote_char e
     return $completion_list_re
 }
 
+# Make a list of the characters in $PATTERN that come after $PREFIX.
+# this assumes that PATTERN does start with PREFIX and is at least
+# one character longer.
+
+proc make_optional_partial_complete { prefix pattern } {
+    set pattern [string range $pattern [string length $prefix]+1 end]
+
+    return [split $pattern ""]
+}
+
 # Clear the input line.
 
 proc clear_input_line { test } {
@@ -112,13 +122,32 @@ proc test_gdb_complete_tab_unique { input_line complete_line_re append_char_re }
     set test "tab complete \"$input_line\""
     send_gdb "$input_line\t"
     set partial_complete [string_to_regexp $input_line]
+    set partial_expected [make_optional_partial_complete $input_line $complete_line_re]
+    set partial_size [array size $partial_expected]
     set res 1
     gdb_test_multiple "" "$test" {
 	-re "^$complete_line_re$append_char_re$" {
 	    pass "$test"
 	}
-	-re "$partial_complete\[^ \]+ $" {
-	    fail "$test"
+	-re "${partial_complete}(\[^ \]+) $" {
+	    set captured [split $expect_out(1,string) ""]
+	    set captured_size [array size $captured]
+	    if { $captured_size >= $partial_size } {
+		set unexpected 0
+		for { set i 0 } { $i < $captured_size } { incr i } {
+		    if { $captured($i) != $partial_expected($i) } {
+			set unexpected 1
+			break
+		    }
+		}
+		if { $unexpected } {
+		    fail "$test"
+		    set res -1
+		}
+	    } else {
+		fail "$test"
+		set res -1
+	    }
 	}
 	timeout {
 	    fail "$test (timeout)"
-- 
2.41.0


             reply	other threads:[~2023-08-04 16:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 16:09 Bruno Larsen [this message]
2023-08-23 10:01 ` Guinevere Larsen
2023-08-23 16:53 ` Andrew Burgess
2023-08-24 10:29 ` Andrew Burgess
2023-08-24 16:05   ` Guinevere Larsen

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=20230804160924.1338942-1-blarsen@redhat.com \
    --to=blarsen@redhat.com \
    --cc=gdb-patches@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).