1 # Copyright 2009-2018 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
18 load_lib completion-support.exp
20 # A helper procedure to test location completions restricted by
22 proc test_class_complete {class expr name matches} {
25 set matches [lsort $matches]
26 set cmd "complete break ${class}::$expr"
28 gdb_test_multiple $cmd $name {
29 "break ${class}::main" { fail "$name (saw global symbol)" }
31 -re "break ${class}::\[^\r\n\]*\r\n" {
32 set str $expect_out(0,string)
33 scan $str "break ${class}::%\[^(\]" method
39 foreach got [lsort $seen] have $matches {
40 if {![string equal $got $have]} {
45 if {[string length $failed] != 0} {
46 fail "$name ($failed not found)"
54 if { [skip_cplus_tests] } { continue }
56 standard_testfile pr9594.cc
58 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
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]
66 test_class_complete Foo F "complete class methods beginning with F" \
69 # The tests below depend on the current code scope.
71 set bp_location [gdb_get_line_number "Set breakpoint here" ${srcfile}]
73 if {![runto "${srcfile}:$bp_location"]} {
74 perror "test suppressed"
78 # This also tests inheritance -- completion should only see a single
80 gdb_test "complete p foo1.g" "p foo1\\.get_foo"
82 # Test inheritance without overriding.
83 gdb_test "complete p foo1.base" "p foo1\\.base_function_only"
85 # Test non-completion of constructor names.
86 gdb_test "complete p foo1.Fo" "p foo1\\.Foofoo"
88 # Test completion with an anonymous struct.
89 gdb_test "complete p a.g" "p a\\.get"
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" "" {
97 "Test_NS::Nested::qux"
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.
107 set tab_completion_list {
113 test_gdb_complete_tab_multiple "p Test_NS:" ":" $tab_completion_list
114 test_gdb_complete_tab_multiple "p Test_NS::" "" $tab_completion_list
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 {
120 "Test_NS::Nested::qux"
124 test_gdb_complete_cmd_multiple "p " "Test_NS:" $cmd_completion_list
125 test_gdb_complete_cmd_multiple "p " "Test_NS::" $cmd_completion_list
127 # Add a disambiguating character and we get a unique completion.
128 test_gdb_complete_unique "p Test_NS::f" "p Test_NS::foo"