public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gdb/testsuite: fix completion tests when using READ1
@ 2023-08-04 16:09 Bruno Larsen
  2023-08-23 10:01 ` Guinevere Larsen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bruno Larsen @ 2023-08-04 16:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Bruno Larsen

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-24 16:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 16:09 [PATCH v2] gdb/testsuite: fix completion tests when using READ1 Bruno Larsen
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

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).