This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 35/40] Comprehensive C++ linespec/completer tests


On 08/09/2017 06:30 PM, Keith Seitz wrote:
> On 06/02/2017 05:22 AM, Pedro Alves wrote:
>> Exercises all sorts of aspects fixed by the previous patches.
> 
> SUPER!
> 
>> Grows the gdb.linespec/ tests like this:
>>
>>   -# of expected passes           573
>>   +# of expected passes           4458
> 
> /me drools

:-)

> 
>> gdb/testsuite/ChangeLog:
>> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>>
>> 	* gdb.linespec/cpcompletion.exp: New file.
>> 	* gdb.linespec/cpls-hyphen.cc: New file.
>> 	* gdb.linespec/cpls.cc: New file.
>> 	* gdb.linespec/cpls2.cc: New file.
>> 	* gdb.linespec/explicit.exp: Load completion-support.exp.  Adjust
>> 	test to use test_gdb_complete_unique.  Add label completion,
>> 	keyword completion and explicit location completion tests.
>> 	* lib/completion-support.exp: New file.
> 
>> diff --git a/gdb/testsuite/gdb.linespec/cpls-hyphen.cc b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
>> new file mode 100644
>> index 0000000..fdc063f
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
>> @@ -0,0 +1,14 @@
>> +int
>> +ns_hyphen_function (int i)
>> +{
>> +  if (i > 0)
>> +    {
>> +    label1:
>> +      return i + 20;
>> +    }
>> +  else
>> +    {
>> +    label2:
>> +      return i + 10;
>> +    }
>> +}
> 
> Does this file not require a copyright header?

It does, missed it.  Thanks.

> 
>> diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp
>> index 65d78ca..998b70a 100644
>> --- a/gdb/testsuite/gdb.linespec/explicit.exp
>> +++ b/gdb/testsuite/gdb.linespec/explicit.exp
>> @@ -326,10 +329,202 @@ namespace eval $testfile {
> [snip]
>>  
>> +	# Follows completion tests that require having no symbols
>> +	# loaded.
> 
> "The following completion tests," perhaps?

Adjusted.

> 
>> +	gdb_exit
>> +	gdb_start
>> +
>> +	# The match list you get when you complete with no options
>> +	# specified at all.
>> +	set completion_list {
>> +	    "-function"
>> +	    "-label"
>> +	    "-line"
>> +	    "-probe"
>> +	    "-probe-dtrace"
>> +	    "-probe-stap"
>> +	    "-qualified"
>> +	    "-source"
>> +	}
>> +	with_test_prefix "complete with no arguments and no symbols" {
>> +	    test_gdb_complete_multiple "b " "" "-" $completion_list
>> +	    test_gdb_complete_multiple "b " "-" "" $completion_list
>> +	}
>>      }
>>      # End of completion tests.
>>  
>> diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp
>> new file mode 100644
>> index 0000000..ef78269
>> --- /dev/null
>> +++ b/gdb/testsuite/lib/completion-support.exp
>> @@ -0,0 +1,513 @@
> [snip]
>> +
>> +# Test that completing INPUT_LINE with TAB completes to
>> +# COMPLETE_LINE_RE.  APPEND_CHAR_RE is the character expected to be
>> +# appended after EXPECTED_OUTPUT.  Normally that's a whitespace, but
>> +# in some cases it's some other character, like a colon.
>> +
>> +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"
>> +    gdb_test_multiple "" "$test" {
>> +	-re "^$complete_line_re$append_char_re$" {
>> +	    pass "$test"
>> +	}
>> +    }
>> +
>> +    clear_input_line $test
>> +}
>> +
>> +# Test that completing INPUT_LINE with TAB completes to "INPUT_LINE +
>> +# ADD_COMPLETED_LINE" and that is displays the completion matches in
>                                   ^^
> 
> s/is/it/

Fixed.

> 
>> +# COMPLETION_LIST.
>> +
> 
>> +proc test_gdb_complete_tab_multiple { input_line add_completed_line \
>> +					  completion_list } {
>> +    global gdb_prompt
>> +    global bell_re
> [snip]
>> +
>> +proc test_gdb_complete_menu { line expected_output } {
>> +
> 
> Is this used? Maybe in a subsequent patch?

Whoops, no it's isn't used, because I couldn't make it
work last time I tried, I don't recall exactly why.
This was meant to test the "ESC, ?" sequence, which triggers
a completion too.  I've removed this for now.

> 
>> +    set test "menu complete $line"
>> +#    send_gdb "$expr\033?"
>> +#    send_gdb "$expr^\[?"
>> +    send_gdb "$expr"
>> +    send_gdb "\x1b"
>> +    send_gdb "?"
>> +    gdb_test_multiple "" "$test" {
>> +	-re "$expected_output" {
>> +	    pass "$test"
>> +	}
>> +    }
>> +}
>> +
> [snip]
>> +
>> +proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} {max_completions 0}} {
> 
> This procedure is only called from this file. If it is meant to be called by
> test writers, it deserves a comment, even if trivial.
> 
> If it is only meant for use here, then it should be named differently to
> differentiate it, or stick it into an appropriately namespace so that it is
> more obvious to potential users of this code that it is not meant to be
> "exported." There's a lot of (sometimes mindless) cut-n-paste going on in the
> test suite.

I gave it a comment now.  Actually, test_gdb_complete_unique can just
be a wrapper around test_gdb_complete_unique_re; not sure why I didn't
do that the first time.  Probably just mindless copy/paste.

I like the idea of a namespace, so I created one ("completion") and
moved other helper procedures and all the related globals there.
I considered moving the public procedures into the namespace as well,
but it requires touching many many lines of the huge tests throughout, and
causes hard to resolve conflicts and it doesn't seem worth it to fight
against that.  I'll see if it makes sense to do that on top of the
series instead.

> 
>> +    set append_char_re [string_to_regexp $append_char]
>> +    test_gdb_complete_tab_unique $input_line $complete_line_re $append_char_re
>> +
>> +    # Trim INPUT_LINE and COMPLETE LINE, for the case we're completing
>> +    # a command with leading whitespace.  Leading command whitespace
>> +    # is discarded by GDB.
>> +    set input_line [string trimleft $input_line]
>> +    set expected_output_re [string trimleft $complete_line_re]
>> +    if {$append_char_re != " "} {
>> +	append expected_output_re $append_char_re
>> +    }
>> +    if {$max_completions} {
>> +	set max_completion_reached_msg \
>> +	    "*** List may be truncated, max-completions reached. ***"
>> +	set input_line_re \
>> +	    [string_to_regexp $input_line]
>> +	set max_completion_reached_msg_re \
>> +	    [string_to_regexp $max_completion_reached_msg]
>> +
>> +	append expected_output_re \
>> +	    "\r\n$input_line_re $max_completion_reached_msg_re"
>> +    }
>> +
>> +    test_gdb_complete_cmd_unique $input_line $expected_output_re
>> +}
> [snip]
>> +
>> +# Test completing all the substring prefixes of COMPLETION from
>> +# [0..START) to [0..END) complete to COMPLETION.  If END is ommitted,
>> +# default to the length of COMPLETION.
>> +
>> +proc test_complete_prefix_range {completion start {end -1}} {
>> +    if {$end == -1} {
>> +	set end [string length $completion]
>> +    }
>> +
>> +    for {set i $start} {$i < $end} {incr i} {
>> +	set line [string range $completion 0 $i]
>> +	test_gdb_complete_unique "$line" "$completion"
>> +    }
>> +}
>> +
>> +proc test_complete_prefix_range_input {input completion_re start {end -1}} {
> 
> This procedure also isn't used. Maybe also a later patch? Ditto the "if it
> is meant to be used, ..., or renamed/hidden."

Ah, yes, it's used in a later patch [1].  I've moved it to the right
patch now, and renamed 
test_complete_prefix_range_input->test_complete_prefix_range_re instead,
following the similar theme of other procedures.  I also reimplemented
test_complete_prefix_range on top of it.

[1] - [PATCH 36/40] Add comprehensive C++ operator linespec/location/completion tests


> 
>> +    if {$end == -1} {
>> +	set end [string length $input]
>> +    }
>> +
>> +    for {set i $start} {$i < $end} {incr i} {
>> +	set line [string range $input 0 $i]
>> +	test_gdb_complete_unique_re "$line" $completion_re
>> +    }
>> +}
>> +
> [snip]
>> +# Return true if lists A and B have the same elements.  Order of
>> +# elements does not matter.
>> +
>> +proc gdb_leq {a b} {
>> +    return [expr {[lsort $a] eq [lsort $b]}]
>> +}
>> +
>> +# Check that creating the breakpoint at LINESPEC finds the same
>> +# breakpoint locations as completing LINESPEC.  COMPLETION_LIST is
>> +# expected completion match list.
> 
> You mention "LINESPEC" here, but this procedure actually takes a breakpoint
> command and a linepsec (or location?), no?

Right.  I think I first accepted a LINESPEC, then later made it work
with explicit locations too, and missed updating the comment.

> 
>> +
>> +proc check_bp_locations_match_list {break_command completion_list} {
>> +    global gdb_prompt
>> +    global hex
>> +
>> +    with_test_prefix "compare \"$break_command\" completion list with bp location list" {
>> +	set num_locations [create_bp $break_command]
>> +
>> +	set found_list ""
>> +
>> +	set any "\[^\r\n\]*"
>> +
>> +	gdb_test_multiple "info breakpoint \$bpnum" "info breakpoint" {
>> +	    -re "in \(\[^\r\n\]*\) at " {
>> +		# A function location.
>> +		set found_location "$expect_out(1,string)"
>> +		lappend found_list $found_location
>> +		exp_continue
>> +	    }
>> +	    -re "breakpoint${any}keep${any}y${any}$hex\[ \t]*\(${any}\)\r\n" {
>> +		# A label location.
>> +		set found_location "$expect_out(1,string)"
>> +		lappend found_list $found_location
>> +		exp_continue
>> +	    }
>> +	    -re "$gdb_prompt $" {
>> +	    }
>> +	}
>> +
>> +	gdb_assert {[gdb_leq $found_list $completion_list]} "matches"
>> +
>> +	delete_breakpoints
>> +    }
>> +}
>> +

Here's what I'm squashing in.

diff --git a/gdb/testsuite/gdb.linespec/cpcompletion.exp b/gdb/testsuite/gdb.linespec/cpcompletion.exp
index dd9bf70..5522b19 100644
--- a/gdb/testsuite/gdb.linespec/cpcompletion.exp
+++ b/gdb/testsuite/gdb.linespec/cpcompletion.exp
@@ -445,10 +445,8 @@ proc_with_prefix const-overload-quoted {} {
 # appends the end quote char automatically, both ' and ".
 
 proc_with_prefix append-end-quote-char-when-unambiguous {} {
-    global all_quotes_list
-
     foreach cmd_prefix {"b" "b -function"} {
-	foreach qc $all_quotes_list {
+	foreach qc $completion::all_quotes_list {
 	    set linespec "${qc}not_overloaded_fn()${qc}"
 	    foreach cmd [list "$cmd_prefix ${qc}not_overloaded_fn()" \
 			      "$cmd_prefix ${qc}not_overloaded_fn" \
@@ -480,13 +478,12 @@ proc_with_prefix in-source-file-unconstrained {} {
 # name.
 
 proc_with_prefix in-source-file-unambiguous {} {
-    global maybe_quoted_list
-
-    foreach sqc $maybe_quoted_list {
-	foreach fqc $maybe_quoted_list {
+    foreach sqc $completion::maybe_quoted_list {
+	foreach fqc $completion::maybe_quoted_list {
 	    # Linespec.
 	    foreach sep {":" ": "} {
-		set linespec "${sqc}cpls2.cc${sqc}${sep}${fqc}file_constrained_test_cpls2_function(int)${fqc}"
+		set linespec \
+		    "${sqc}cpls2.cc${sqc}${sep}${fqc}file_constrained_test_cpls2_function(int)${fqc}"
 		set complete_line "b $linespec"
 		set start [index_after "constrained_test" $complete_line]
 		set input_line [string range $complete_line 0 $start]
@@ -515,10 +512,8 @@ proc_with_prefix in-source-file-unambiguous {} {
 # function name.
 
 proc_with_prefix in-source-file-ambiguous {} {
-    global maybe_quoted_list
-
-    foreach sqc $maybe_quoted_list {
-	foreach fqc $maybe_quoted_list {
+    foreach sqc $completion::maybe_quoted_list {
+	foreach fqc $completion::maybe_quoted_list {
 	    # Linespec.
 	    foreach sep {":" ": "} {
 		set cmd_prefix "b ${sqc}cpls2.cc${sqc}${sep}"
@@ -542,13 +537,9 @@ proc_with_prefix in-source-file-ambiguous {} {
 # instead of a whitespace character.
 
 proc_with_prefix source-complete-appends-colon {} {
-    global maybe_quoted_list
-    global all_quotes_list
-    global keyword_list
-
     # Test with quotes to make sure the end quote char is put at the
     # right place.
-    foreach qc $maybe_quoted_list {
+    foreach qc $completion::maybe_quoted_list {
 	test_gdb_complete_unique \
 	    "b ${qc}cpls2." \
 	    "b ${qc}cpls2.cc${qc}" ":"
@@ -574,8 +565,9 @@ proc_with_prefix source-complete-appends-colon {} {
     # Cursor at the end of the string.
     test_gdb_complete_none "b nonexistingfilename.cc"
     # Cursor past the end of the string.
-    test_gdb_complete_multiple "b nonexistingfilename.cc " "" "" $keyword_list
-    foreach qc $all_quotes_list {
+    test_gdb_complete_multiple "b nonexistingfilename.cc " "" "" \
+	$completion::keyword_list
+    foreach qc $completion::all_quotes_list {
 	# Unterminated quote.
 	test_gdb_complete_none "b ${qc}nonexistingfilename.cc"
 	test_gdb_complete_none "b ${qc}nonexistingfilename.cc "
@@ -585,7 +577,8 @@ proc_with_prefix source-complete-appends-colon {} {
 	    "b ${qc}nonexistingfilename.cc${qc}"
 	# Terminated quote, cursor past the quote.
 	test_gdb_complete_multiple \
-	    "b ${qc}nonexistingfilename.cc${qc} " "" "" $keyword_list
+	    "b ${qc}nonexistingfilename.cc${qc} " "" "" \
+	    $completion::keyword_list
     }
 }
 
@@ -617,18 +610,16 @@ proc_with_prefix incomplete-scope-colon {} {
     # finds the same breakpoint location as completion does.
     #
     proc incomplete_scope_colon_helper {prototype range_ss {skip_check_bp 0}} {
-	global maybe_quoted_list
-
 	foreach source {"" "cpls.cc"} {
 	    # Test with and without source quoting.
-	    foreach sqc $maybe_quoted_list {
+	    foreach sqc $completion::maybe_quoted_list {
 		if {$source == "" && $sqc != ""} {
 		    # Invalid combination.
 		    continue
 		}
 
 		# Test with and without function quoting.
-		foreach fqc $maybe_quoted_list {
+		foreach fqc $completion::maybe_quoted_list {
 		    if {$source == ""} {
 			set linespec_source ""
 			set explicit_source ""
@@ -676,10 +667,8 @@ proc_with_prefix incomplete-scope-colon {} {
 # Test completing functions/methods in anonymous namespaces.
 
 proc_with_prefix anon-ns {} {
-    global maybe_quoted_list
-
     foreach cmd_prefix {"b" "b -function"} {
-	foreach qc $maybe_quoted_list {
+	foreach qc $completion::maybe_quoted_list {
 	    test_gdb_complete_unique \
 		"$cmd_prefix ${qc}anon_ns_function" \
 		"$cmd_prefix ${qc}anon_ns_function()${qc}"
@@ -833,9 +822,8 @@ proc_with_prefix function-labels {} {
 # location options in explicit locations mode.
 
 proc_with_prefix keywords-after-function {} {
-    global explicit_opts_list keyword_list
-
-    set explicit_list [concat $explicit_opts_list $keyword_list]
+    set explicit_list \
+	[concat $completion::explicit_opts_list $completion::keyword_list]
 
     # Test without a source file, with a known source file, and with
     # and unknown source file.
@@ -845,20 +833,21 @@ proc_with_prefix keywords-after-function {} {
 	{ "function_with_labels(int)" "unknown_function(int)" } \
 	{
 	    # Linespec version.
-	    test_gdb_complete_multiple "b ${location} " "" "" $keyword_list
+	    test_gdb_complete_multiple "b ${location} " "" "" \
+		$completion::keyword_list
 	} \
 	{
 	    # Explicit locations version.
-	    test_gdb_complete_multiple "b ${location} " "" "" $explicit_list
+	    test_gdb_complete_multiple "b ${location} " "" "" \
+		$explicit_list
 	}
 }
 
 # Same, but after a label.
 
 proc_with_prefix keywords-after-label {} {
-    global explicit_opts_list keyword_list
-
-    set explicit_list [concat $explicit_opts_list $keyword_list]
+    set explicit_list \
+	[concat $completion::explicit_opts_list $completion::keyword_list]
 
     foreach_location_labels \
 	{ "" "cpls.cc" } \
@@ -866,24 +855,23 @@ proc_with_prefix keywords-after-label {} {
 	{ "label1" "non_existing_label" } \
 	{
 	    # Linespec version.
-	    test_gdb_complete_multiple "b ${location} " "" "" $keyword_list
+	    test_gdb_complete_multiple "b ${location} " "" "" \
+		$completion::keyword_list
 	} \
 	{
 	    # Explicit locations version.
-	    test_gdb_complete_multiple "b ${location} " "" "" $explicit_list
+	    test_gdb_complete_multiple "b ${location} " "" "" \
+		$explicit_list
 	}
 }
 
 # Similar, but after an unknown file, and in linespec mode only.
 
 proc_with_prefix keywords-after-unknown-file {} {
-    global maybe_quoted_list
-    global keyword_list
-
     # Test with and without quoting.
-    foreach qc $maybe_quoted_list {
+    foreach qc $completion::maybe_quoted_list {
 	set line "b ${qc}unknown_file.cc${qc}: "
-	test_gdb_complete_multiple $line "" "" $keyword_list
+	test_gdb_complete_multiple $line "" "" $completion::keyword_list
     }
 }
 
diff --git a/gdb/testsuite/gdb.linespec/cpls-hyphen.cc b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
index fdc063f..4bd2d9f 100644
--- a/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
+++ b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
@@ -1,3 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2017 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* A function in a file whose name has an hyphen.  */
+
 int
 ns_hyphen_function (int i)
 {
diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp
index 6936971..1e7f0dc 100644
--- a/gdb/testsuite/gdb.linespec/explicit.exp
+++ b/gdb/testsuite/gdb.linespec/explicit.exp
@@ -225,7 +225,7 @@ namespace eval $testfile {
 	}
 
 	with_test_prefix "complete unique file name" {
-	    foreach qc $maybe_quoted_list {
+	    foreach qc $completion::maybe_quoted_list {
 		set cmd "break -source ${qc}3explicit.c${qc}"
 		test_gdb_complete_unique \
 		    "break -source ${qc}3ex" \
@@ -332,7 +332,7 @@ namespace eval $testfile {
 	global maybe_quoted_list
 
 	with_test_prefix "complete unique label name" {
-	    foreach qc $maybe_quoted_list {
+	    foreach qc $completion::maybe_quoted_list {
 		test_gdb_complete_unique \
 		    "break -function myfunction -label ${qc}to" \
 		    "break -function myfunction -label ${qc}top${qc}"
@@ -521,7 +521,7 @@ namespace eval $testfile {
 	# such as "-func main -sour 3ex\t" (main is defined in explicit.c).
 	# The completer cannot handle these yet.
 
-	# Follows completion tests that require having no symbols
+	# The following completion tests require having no symbols
 	# loaded.
 	gdb_exit
 	gdb_start
diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp
index ef78269..3d03943 100644
--- a/gdb/testsuite/lib/completion-support.exp
+++ b/gdb/testsuite/lib/completion-support.exp
@@ -15,18 +15,23 @@
 
 # This file is part of the gdb testsuite.
 
-set timeout 5
+# Any variable or procedure in the namespace whose name starts with
+# "_" is private to the module.  Do not use these.
 
-set bell_re "\\\x07"
+namespace eval completion {
+    variable bell_re "\\\x07"
 
-# List of all quote chars.
-set all_quotes_list {"'" "\""}
+    # List of all quote chars.
+    variable all_quotes_list {"'" "\""}
 
-# List of all quote chars, including no-quote at all.
-set maybe_quoted_list {"" "'" "\""}
+    # List of all quote chars, including no-quote at all.
+    variable maybe_quoted_list {"" "'" "\""}
 
-set keyword_list {"if" "task" "thread"}
-set explicit_opts_list {"-function" "-label" "-line" "-qualified" "-source"}
+    variable keyword_list {"if" "task" "thread"}
+
+    variable explicit_opts_list \
+	{"-function" "-label" "-line" "-qualified" "-source"}
+}
 
 # Make a regular expression that matches a TAB completion list.
 
@@ -81,14 +86,12 @@ proc clear_input_line { test } {
 # Test that completing LINE with TAB completes to nothing.
 
 proc test_gdb_complete_tab_none { line } {
-    global bell_re
-
     set line_re [string_to_regexp $line]
 
     set test "tab complete \"$line\""
     send_gdb "$line\t"
     gdb_test_multiple "" "$test" {
-	-re "^$line_re$bell_re$" {
+	-re "^$line_re$completion::bell_re$" {
 	    pass "$test"
 	}
     }
@@ -115,13 +118,12 @@ 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 is displays the completion matches in
+# ADD_COMPLETED_LINE" and that it displays the completion matches in
 # COMPLETION_LIST.
 
 proc test_gdb_complete_tab_multiple { input_line add_completed_line \
 					  completion_list } {
     global gdb_prompt
-    global bell_re
 
     set input_line_re [string_to_regexp $input_line]
     set add_completed_line_re [string_to_regexp $add_completed_line]
@@ -131,7 +133,7 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \
     set test "tab complete \"$input_line\""
     send_gdb "$input_line\t"
     gdb_test_multiple "" "$test (first tab)" {
-	-re "^${input_line_re}$bell_re$add_completed_line_re$" {
+	-re "^${input_line_re}${completion::bell_re}$add_completed_line_re$" {
 	    send_gdb "\t"
 	    # If we auto-completed to an ambiguous prefix, we need an
 	    # extra tab to show the matches list.
@@ -189,21 +191,6 @@ proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list
     }
 }
 
-proc test_gdb_complete_menu { line expected_output } {
-
-    set test "menu complete $line"
-#    send_gdb "$expr\033?"
-#    send_gdb "$expr^\[?"
-    send_gdb "$expr"
-    send_gdb "\x1b"
-    send_gdb "?"
-    gdb_test_multiple "" "$test" {
-	-re "$expected_output" {
-	    pass "$test"
-	}
-    }
-}
-
 # Test that completing LINE completes to nothing.
 
 proc test_gdb_complete_none { input_line } {
@@ -211,7 +198,7 @@ proc test_gdb_complete_none { input_line } {
     test_gdb_complete_cmd_none $input_line
 }
 
-# Test that completing INPUT_LINE completes to COMPLETE_LINE.
+# Test that completing INPUT_LINE completes to COMPLETE_LINE_RE.
 #
 # APPEND_CHAR is the character expected to be appended after
 # EXPECTED_OUTPUT when TAB completing.  Normally that's a whitespace,
@@ -222,9 +209,12 @@ proc test_gdb_complete_none { input_line } {
 # match, this will only be visible in the "complete" command output.
 # Tab completion will just auto-complete the only match and won't
 # display a match list.
+#
+# Note: usually it's more convenient to pass a literal string instead
+# of a regular expression (as COMPLETE_LINE_RE).  See
+# test_gdb_complete_unique below.
 
-proc test_gdb_complete_unique { input_line complete_line {append_char " "} {max_completions 0}} {
-    set complete_line_re [string_to_regexp $complete_line]
+proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} {max_completions 0}} {
     set append_char_re [string_to_regexp $append_char]
     test_gdb_complete_tab_unique $input_line $complete_line_re $append_char_re
 
@@ -251,31 +241,12 @@ proc test_gdb_complete_unique { input_line complete_line {append_char " "} {max_
     test_gdb_complete_cmd_unique $input_line $expected_output_re
 }
 
-proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} {max_completions 0}} {
-    set append_char_re [string_to_regexp $append_char]
-    test_gdb_complete_tab_unique $input_line $complete_line_re $append_char_re
+# Like TEST_GDB_COMPLETE_UNIQUE_RE, but COMPLETE_LINE is a string, not
+# a regular expression.
 
-    # Trim INPUT_LINE and COMPLETE LINE, for the case we're completing
-    # a command with leading whitespace.  Leading command whitespace
-    # is discarded by GDB.
-    set input_line [string trimleft $input_line]
-    set expected_output_re [string trimleft $complete_line_re]
-    if {$append_char_re != " "} {
-	append expected_output_re $append_char_re
-    }
-    if {$max_completions} {
-	set max_completion_reached_msg \
-	    "*** List may be truncated, max-completions reached. ***"
-	set input_line_re \
-	    [string_to_regexp $input_line]
-	set max_completion_reached_msg_re \
-	    [string_to_regexp $max_completion_reached_msg]
-
-	append expected_output_re \
-	    "\r\n$input_line_re $max_completion_reached_msg_re"
-    }
-
-    test_gdb_complete_cmd_unique $input_line $expected_output_re
+proc test_gdb_complete_unique { input_line complete_line {append_char " "} {max_completions 0}} {
+    set complete_line_re [string_to_regexp $complete_line]
+    test_gdb_complete_unique_re $input_line $complete_line_re $append_char $max_completions
 }
 
 # Test that completing "CMD_PREFIX + COMPLETION_WORD" adds
@@ -288,8 +259,8 @@ proc test_gdb_complete_multiple { cmd_prefix completion_word add_completed_line
     test_gdb_complete_cmd_multiple $cmd_prefix $completion_word $completion_list $start_quote_char $end_quote_char
 }
 
-# Test completing all the substring prefixes of COMPLETION from
-# [0..START) to [0..END) complete to COMPLETION.  If END is ommitted,
+# Test that all the substring prefixes of COMPLETION from
+# [0..START) to [0..END) complete to COMPLETION.  If END is ommitted,
 # default to the length of COMPLETION.
 
 proc test_complete_prefix_range {completion start {end -1}} {
@@ -303,17 +274,6 @@ proc test_complete_prefix_range {completion start {end -1}} {
     }
 }
 
-proc test_complete_prefix_range_input {input completion_re start {end -1}} {
-    if {$end == -1} {
-	set end [string length $input]
-    }
-
-    for {set i $start} {$i < $end} {incr i} {
-	set line [string range $input 0 $i]
-	test_gdb_complete_unique_re "$line" $completion_re
-    }
-}
-
 # Find NEEDLE in HAYSTACK and return the index _after_ NEEDLE.  E.g.,
 # searching for "(" in "foo(int)" returns 4, which would be useful if
 # you want to find the "(" to try completing "foo(".
@@ -326,10 +286,10 @@ proc index_after {needle haystack} {
     return [expr $start + [string length $needle]]
 }
 
-# Create a breakpoint using BREAK_COMMAND, and return the number of
-# locations found.
+# Create a breakpoint using BREAK_COMMAND, and return the number
+# of locations found.
 
-proc create_bp {break_command} {
+proc completion::_create_bp {break_command} {
     global gdb_prompt
     global decimal hex
 
@@ -361,11 +321,18 @@ proc create_bp {break_command} {
     return $found_locations
 }
 
-# Check that trying to create a breakpoint from linespec fails.
+# Return true if lists A and B have the same elements.  Order of
+# elements does not matter.
+
+proc completion::_leq {a b} {
+    return [expr {[lsort $a] eq [lsort $b]}]
+}
+
+# Check that trying to create a breakpoint using BREAK_COMMAND fails.
 
 proc check_setting_bp_fails {break_command} {
     with_test_prefix "\"$break_command\" creates no bp locations" {
-	set found_locations [create_bp $break_command]
+	set found_locations [completion::_create_bp $break_command]
 	gdb_assert {$found_locations == 0} "matches"
 	if {$found_locations != 0} {
 	    delete_breakpoints
@@ -373,23 +340,16 @@ proc check_setting_bp_fails {break_command} {
     }
 }
 
-# Return true if lists A and B have the same elements.  Order of
-# elements does not matter.
-
-proc gdb_leq {a b} {
-    return [expr {[lsort $a] eq [lsort $b]}]
-}
-
-# Check that creating the breakpoint at LINESPEC finds the same
-# breakpoint locations as completing LINESPEC.  COMPLETION_LIST is
-# expected completion match list.
+# Check that creating the breakpoint using BREAK_COMMAND finds the
+# same breakpoint locations as completing BREAK_COMMAND.
+# COMPLETION_LIST is the expected completion match list.
 
 proc check_bp_locations_match_list {break_command completion_list} {
     global gdb_prompt
     global hex
 
     with_test_prefix "compare \"$break_command\" completion list with bp location list" {
-	set num_locations [create_bp $break_command]
+	set num_locations [completion::_create_bp $break_command]
 
 	set found_list ""
 
@@ -412,7 +372,7 @@ proc check_bp_locations_match_list {break_command completion_list} {
 	    }
 	}
 
-	gdb_assert {[gdb_leq $found_list $completion_list]} "matches"
+	gdb_assert {[completion::_leq $found_list $completion_list]} "matches"
 
 	delete_breakpoints
     }
@@ -426,7 +386,6 @@ proc check_bp_locations_match_list {break_command completion_list} {
 # currently iterated location.
 
 proc foreach_location_functions { sources functions body_linespec body_explicit } {
-    global maybe_quoted_list
     upvar source source
     upvar function function
     upvar source_sep source_sep
@@ -434,14 +393,14 @@ proc foreach_location_functions { sources functions body_linespec body_explicit
 
     foreach source $sources {
 	# Test with and without source quoting.
-	foreach sqc $maybe_quoted_list {
+	foreach sqc $completion::maybe_quoted_list {
 	    if {$source == "" && $sqc != ""} {
 		# Invalid combination.
 		continue
 	    }
 
 	    # Test with and without function quoting.
-	    foreach fqc $maybe_quoted_list {
+	    foreach fqc $completion::maybe_quoted_list {
 		# Test known and unknown functions.
 		foreach function $functions {
 		    # Linespec version.  Test with and without spacing
@@ -477,7 +436,6 @@ proc foreach_location_functions { sources functions body_linespec body_explicit
 # Same as foreach_locations_functions, but also iterate over
 # combinations of labels.
 proc foreach_location_labels { sources functions labels body_linespec body_explicit } {
-    global maybe_quoted_list
     upvar source source
     upvar function function
     upvar label label


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]