[4/5] Fix latent bug in test_gdb_complete_cmd_multiple

Message ID 20190627191427.20742-5-palves@redhat.com
State New
Headers show
Series
  • pipe command completer, and string options
Related show

Commit Message

Pedro Alves June 27, 2019, 7:14 p.m.
A following patch will add the following to a testcase:

  test_gdb_completion_offers_commands "| "

And that tripped on a latent testsuite bug:

 (gdb) | PASS: gdb.base/shell.exp: tab complete "| "
 ^CQuit
 (gdb) complete |
 | !
 | +
 PASS: gdb.base/shell.exp: cmd complete "| "
 |  *** List may be truncated, max-completions reached. ***
 (gdb) FAIL: gdb.base/shell.exp: set max-completions 200
 set max-completions 200

The issue is that "|" ends up as part of a regexp, and "|" in regexps
has a special meaning...

Fix this with string_to_regexp.

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* lib/completion-support.exp (test_gdb_complete_cmd_multiple): Use
	string_to_regexp.
---
 gdb/testsuite/lib/completion-support.exp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.14.5

Comments

Tom Tromey June 28, 2019, 2:53 p.m. | #1
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:


Pedro>      if {$max_completions} {
Pedro> +	set cmd_prefix_re [string_to_regexp $cmd_prefix]
Pedro>  	append expected_re \
Pedro> -	    "$cmd_prefix \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
Pedro> +	    "$cmd_prefix_re \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
Pedro>      }
 
Pedro>      set cmd_re [string_to_regexp "complete $cmd_prefix$completion_word"]

It looks like this is going to end up running string_to_regexp twice --
once in the "if" and then again here, which is probably not desirable.

Tom
Pedro Alves June 28, 2019, 2:56 p.m. | #2
On 6/28/19 3:53 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

> 

> Pedro>      if {$max_completions} {

> Pedro> +	set cmd_prefix_re [string_to_regexp $cmd_prefix]

> Pedro>  	append expected_re \

> Pedro> -	    "$cmd_prefix \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"

> Pedro> +	    "$cmd_prefix_re \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"

> Pedro>      }

>  

> Pedro>      set cmd_re [string_to_regexp "complete $cmd_prefix$completion_word"]

> 

> It looks like this is going to end up running string_to_regexp twice --

> once in the "if" and then again here, which is probably not desirable.


It won't because the second time is still referring to $cmd_prefix,
while the new code introduces a new $cmd_prefix_re variable.

Thanks,
Pedro Alves
Tom Tromey June 28, 2019, 3:46 p.m. | #3
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:


Pedro> On 6/28/19 3:53 PM, Tom Tromey wrote:
>>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

>> 

Pedro> if {$max_completions} {
Pedro> +	set cmd_prefix_re [string_to_regexp $cmd_prefix]
Pedro> append expected_re \
Pedro> -	    "$cmd_prefix \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
Pedro> +	    "$cmd_prefix_re \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
Pedro> }
>> 

Pedro> set cmd_re [string_to_regexp "complete $cmd_prefix$completion_word"]
>> 

>> It looks like this is going to end up running string_to_regexp twice --

>> once in the "if" and then again here, which is probably not desirable.


Pedro> It won't because the second time is still referring to $cmd_prefix,
Pedro> while the new code introduces a new $cmd_prefix_re variable.

Indeed, I misread that.  Thanks.

Tom

Patch

diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp
index 3199e85fd4d..abe48b4a7f7 100644
--- a/gdb/testsuite/lib/completion-support.exp
+++ b/gdb/testsuite/lib/completion-support.exp
@@ -200,8 +200,9 @@  proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list
     set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char]
 
     if {$max_completions} {
+	set cmd_prefix_re [string_to_regexp $cmd_prefix]
 	append expected_re \
-	    "$cmd_prefix \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
+	    "$cmd_prefix_re \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
     }
 
     set cmd_re [string_to_regexp "complete $cmd_prefix$completion_word"]