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 1/2] gdb/testsuite: add test with regex for multiple completion patterns
Date: Tue, 17 Jan 2023 14:00:07 +0100	[thread overview]
Message-ID: <20230117130007.1686917-2-blarsen@redhat.com> (raw)
In-Reply-To: <20230117130007.1686917-1-blarsen@redhat.com>

Currently there is no way to test tab completion on GDB using regexes if
you expect multiple suggestions. This commit adds a proc for that,
test_gdb_complete_multiple_re, which does just that.

To achieve that, test_gdb_complete_cmd_multiple_re and
test_gdb_complete_tab_multiple_re are introduced, following a similar
logic to the unique tests, which already have an _re version.
---
 gdb/testsuite/lib/completion-support.exp | 73 +++++++++++++++++++-----
 1 file changed, 60 insertions(+), 13 deletions(-)

diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp
index bf9c5ad352c..babe802e9a1 100644
--- a/gdb/testsuite/lib/completion-support.exp
+++ b/gdb/testsuite/lib/completion-support.exp
@@ -47,7 +47,7 @@ proc make_tab_completion_list_re { completion_list } {
 
     set completion_list_re ""
     foreach c $completion_list {
-	append completion_list_re [string_to_regexp $c]
+	append completion_list_re $c
 	append completion_list_re $ws
     }
     append completion_list_re $ws
@@ -58,13 +58,18 @@ proc make_tab_completion_list_re { completion_list } {
 # Make a regular expression that matches a "complete" command
 # completion list.  CMD_PREFIX is the command prefix added to each
 # completion match.
+# COMPLETION_LIST is expected to already be regexp.  This is done so
+# we can have regex options in the completion list, to account for
+# differences in compiler results.
 
 proc make_cmd_completion_list_re { cmd_prefix completion_list start_quote_char end_quote_char } {
 
     set completion_list_re ""
     foreach c $completion_list {
 	# The command prefix is included in all completion matches.
-	append completion_list_re [string_to_regexp $cmd_prefix$start_quote_char$c$end_quote_char]
+	append completion_list_re [string_to_regexp $cmd_prefix$start_quote_char]
+	append completion_list_re $c
+	append completion_list_re [string_to_regexp $end_quote_char]
 	append completion_list_re "\r\n"
     }
 
@@ -124,18 +129,18 @@ proc test_gdb_complete_tab_unique { input_line complete_line_re append_char_re }
 }
 
 # Test that completing INPUT_LINE with TAB completes to "INPUT_LINE +
-# ADD_COMPLETED_LINE" and that it displays the completion matches in
+# ADD_COMPLETED_LINE_RE" and that it displays the completion matches in
 # COMPLETION_LIST.  If MAX_COMPLETIONS then we expect the completion
 # to hit the max-completions limit.
+# ADD_COMPLETED_LINE_RE and EXPECTED_RE must be regular expressions,
+# while INPUT_LINE is does is not.
 
-proc test_gdb_complete_tab_multiple { input_line add_completed_line \
-					  completion_list {max_completions 0}} {
+proc test_gdb_complete_tab_multiple_re { input_line add_completed_line_re \
+					  completion_list_re {max_completions 0}} {
     global gdb_prompt
 
     set input_line_re [string_to_regexp $input_line]
-    set add_completed_line_re [string_to_regexp $add_completed_line]
-
-    set expected_re [make_tab_completion_list_re $completion_list]
+    set expected_re [make_tab_completion_list_re $completion_list_re]
 
     if {$max_completions} {
 	append expected_re "\r\n"
@@ -150,14 +155,14 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \
 	    send_gdb "\t"
 	    # If we auto-completed to an ambiguous prefix, we need an
 	    # extra tab to show the matches list.
-	    if {$add_completed_line != ""} {
+	    if {$add_completed_line_re != ""} {
 		send_gdb "\t"
 		set maybe_bell ${completion::bell_re}
 	    } else {
 		set maybe_bell ""
 	    }
 	    gdb_test_multiple "" "$test (second tab)" {
-		-re "^${maybe_bell}\r\n$expected_re\r\n$gdb_prompt " {
+		-re "^$maybe_bell\r\n$expected_re\r\n$gdb_prompt " {
 		    gdb_test_multiple "" "$test (second tab)" {
 			-re "^$input_line_re$add_completed_line_re$" {
 			    pass "$test"
@@ -171,6 +176,21 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \
     clear_input_line $test
 }
 
+# Simplified call test completeing an INPUT_LINE using TAB.  This just
+# turns the given COMPLETION_LIST into regexps and calls the proc
+# test_gdb_complete_tab_multiple_re
+
+proc test_gdb_complete_tab_multiple { input_line add_completed_line \
+					  completion_list {max_completions 0}} {
+    set add_completed_line_re [string_to_regexp $add_completed_line]
+    set completion_list_re ""
+    foreach c $completion_list {
+	lappend completion_list_re [string_to_regexp $c]
+    }
+
+    test_gdb_complete_tab_multiple_re $input_line $add_completed_line_re \
+	$completion_list_re $max_completions
+}
 # Test that completing LINE with the complete command completes to
 # nothing.
 
@@ -195,15 +215,16 @@ proc test_gdb_complete_cmd_unique { input_line complete_line_re } {
 }
 
 # Test that completing "CMD_PREFIX + COMPLETION_WORD" with the
-# complete command displays the COMPLETION_LIST completion list.  Each
+# complete command displays the COMPLETION_LIST_RE completion list.  Each
 # entry in the list should be prefixed by CMD_PREFIX.  If
 # MAX_COMPLETIONS then we expect the completion to hit the
 # max-completions limit.
+# COMPLETION_LIST_RE must already be valid regexes.
 
-proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} {max_completions 0}} {
+proc test_gdb_complete_cmd_multiple_re { cmd_prefix completion_word completion_list_re {start_quote_char ""} {end_quote_char ""} {max_completions 0}} {
     global gdb_prompt
 
-    set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char]
+    set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list_re $start_quote_char $end_quote_char]
 
     if {$max_completions} {
 	set cmd_prefix_re [string_to_regexp $cmd_prefix]
@@ -220,6 +241,19 @@ proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list
     }
 }
 
+# Simplified call to test_gdb_complete_cmd_multiple_re, allowing for
+# passing completions that are not regular expressions.
+
+proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} {max_completions 0}} {
+    set completion_list_re ""
+    foreach c $completion_list {
+	lappend completion_list_re [string_to_regexp $c]
+    }
+
+    test_gdb_complete_cmd_multiple_re $cmd_prefix $completion_word \
+	$completion_list_re $start_quote_char $end_quote_char $max_completions
+}
+
 # Test that completing LINE completes to nothing.
 
 proc test_gdb_complete_none { input_line } {
@@ -300,6 +334,19 @@ proc test_gdb_complete_multiple {
     test_gdb_complete_cmd_multiple $cmd_prefix $completion_word $completion_list $start_quote_char $end_quote_char $max_completions
 }
 
+# Similar to test_gdb_complete_multiple, but requires regular expressions
+# in COMPLETION_LIST_RE.
+
+proc test_gdb_complete_multiple_re {
+  cmd_prefix completion_word add_completed_line completion_list_re
+  {start_quote_char ""} {end_quote_char ""} {max_completions 0}
+} {
+    if { [readline_is_used] } {
+      test_gdb_complete_tab_multiple_re "$cmd_prefix$completion_word" $add_completed_line $completion_list_re $max_completions
+    }
+    test_gdb_complete_cmd_multiple_re $cmd_prefix $completion_word $completion_list_re $start_quote_char $end_quote_char $max_completions
+}
+
 # Test that all the substring prefixes of INPUT from [0..START) to
 # [0..END) complete to COMPLETION_RE (a regular expression).  If END
 # is ommitted, default to the length of INPUT.
-- 
2.39.0


  reply	other threads:[~2023-01-17 14:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 13:00 [PATCH 0/2] Fix testing gdb.linespec/cp-completion-aliases with Bruno Larsen
2023-01-17 13:00 ` Bruno Larsen [this message]
2023-01-17 13:00 ` [PATCH 2/2] gdb/testsuite: fix running gdb.linespec/cp-completion-aliases.exp with clang Bruno Larsen
2023-02-03 13:44   ` Andrew Burgess
2023-02-03 15:49     ` Andrew Burgess
2023-02-06 14:10     ` Bruno Larsen
2023-02-06 15:48       ` Andrew Burgess
2023-02-03  8:04 ` [PING][PATCH 0/2] Fix testing gdb.linespec/cp-completion-aliases with Bruno 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=20230117130007.1686917-2-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).