Fix regression: expression completer and scope operator (PR gdb/22584)
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / cpcompletion.exp
1 # Copyright 2009-2017 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the gdb testsuite.
17
18 load_lib completion-support.exp
19
20 # A helper procedure to test location completions restricted by
21 # class.
22 proc test_class_complete {class expr name matches} {
23 global gdb_prompt
24
25 set matches [lsort $matches]
26 set cmd "complete break ${class}::$expr"
27 set seen {}
28 gdb_test_multiple $cmd $name {
29 "break ${class}::main" { fail "$name (saw global symbol)" }
30 $cmd { exp_continue }
31 -re "break ${class}::\[^\r\n\]*\r\n" {
32 set str $expect_out(0,string)
33 scan $str "break ${class}::%\[^(\]" method
34 lappend seen $method
35 exp_continue
36 }
37 -re "$gdb_prompt $" {
38 set failed ""
39 foreach got [lsort $seen] have $matches {
40 if {![string equal $got $have]} {
41 set failed $have
42 break
43 }
44 }
45 if {[string length $failed] != 0} {
46 fail "$name ($failed not found)"
47 } else {
48 pass $name
49 }
50 }
51 }
52 }
53
54 if { [skip_cplus_tests] } { continue }
55
56 standard_testfile pr9594.cc
57
58 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
59 return -1
60 }
61
62 # Test that completion is restricted by class name (all methods)
63 test_class_complete Foo "" "complete class methods" \
64 [list Foo Foofoo get_foo set_foo ~Foo]
65
66 test_class_complete Foo F "complete class methods beginning with F" \
67 [list Foo Foofoo]
68
69 # The tests below depend on the current code scope.
70
71 set bp_location [gdb_get_line_number "Set breakpoint here" ${srcfile}]
72
73 if {![runto "${srcfile}:$bp_location"]} {
74 perror "test suppressed"
75 return
76 }
77
78 # This also tests inheritance -- completion should only see a single
79 # "get_foo".
80 gdb_test "complete p foo1.g" "p foo1\\.get_foo"
81
82 # Test inheritance without overriding.
83 gdb_test "complete p foo1.base" "p foo1\\.base_function_only"
84
85 # Test non-completion of constructor names.
86 gdb_test "complete p foo1.Fo" "p foo1\\.Foofoo"
87
88 # Test completion with an anonymous struct.
89 gdb_test "complete p a.g" "p a\\.get"
90
91 with_test_prefix "expression with namespace" {
92 # Before the scope operator, GDB shows all the symbols whose
93 # fully-qualified name matches the completion word.
94 test_gdb_complete_multiple "p " "Test_NS" "" {
95 "Test_NS"
96 "Test_NS::Nested"
97 "Test_NS::Nested::qux"
98 "Test_NS::bar"
99 "Test_NS::foo"
100 }
101
102 # Unlike in linespecs, tab- and complete-command completion work a
103 # bit differently when completing around the scope operator. The
104 # matches in the tab-completion case only show the part of the
105 # symbol after the scope, since ':' is a word break character.
106
107 set tab_completion_list {
108 "Nested"
109 "Nested::qux"
110 "bar"
111 "foo"
112 }
113 test_gdb_complete_tab_multiple "p Test_NS:" ":" $tab_completion_list
114 test_gdb_complete_tab_multiple "p Test_NS::" "" $tab_completion_list
115
116 # OTOH, the complete command must show the whole command, with
117 # qualified symbol displayed as entered by the user.
118 set cmd_completion_list {
119 "Test_NS::Nested"
120 "Test_NS::Nested::qux"
121 "Test_NS::bar"
122 "Test_NS::foo"
123 }
124 test_gdb_complete_cmd_multiple "p " "Test_NS:" $cmd_completion_list
125 test_gdb_complete_cmd_multiple "p " "Test_NS::" $cmd_completion_list
126
127 # Add a disambiguating character and we get a unique completion.
128 test_gdb_complete_unique "p Test_NS::f" "p Test_NS::foo"
129 }
This page took 0.032077 seconds and 4 git commands to generate.