1 # Copyright
2009-2022 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 # Tests below are about tab
-completion
, which doesn
't work if readline
63 # library isn't used. Check it first.
65 if { ![readline_is_used
] } {
66 untested
"no tab completion support without readline"
70 # Test that completion is restricted by class
name (all methods
)
71 test_class_complete Foo
"" "complete class methods" \
72 [list Foo Foofoo get_foo set_foo ~Foo
]
74 test_class_complete Foo F
"complete class methods beginning with F" \
77 # The tests below depend
on the current code scope.
79 set bp_location
[gdb_get_line_number
"Set breakpoint here" ${srcfile}]
81 if {![runto
"${srcfile}:$bp_location"]} {
82 perror
"test suppressed"
86 # This also tests inheritance
-- completion should only see a single
88 gdb_test
"complete p foo1.g" "p foo1\\.get_foo"
90 # Test inheritance without overriding.
91 gdb_test
"complete p foo1.base" "p foo1\\.base_function_only"
93 # Test non
-completion of constructor names.
94 gdb_test
"complete p foo1.Fo" "p foo1\\.Foofoo"
96 # Test completion with an anonymous struct.
97 gdb_test
"complete p a.g" "p a\\.get"
99 with_test_prefix
"expression with namespace" {
100 # Before the scope operator
, GDB shows all the symbols whose
101 # fully
-qualified
name matches the completion word.
102 test_gdb_complete_multiple
"p " "Test_NS" "" {
105 "Test_NS::Nested::qux"
110 # Unlike in linespecs
, tab
- and complete
-command completion work a
111 # bit differently when completing around the scope operator. The
112 # matches in the tab
-completion case only
show the part of the
113 # symbol after the scope
, since
':' is a word
break character.
115 set tab_completion_list
{
121 test_gdb_complete_tab_multiple
"p Test_NS:" ":" $tab_completion_list
122 test_gdb_complete_tab_multiple
"p Test_NS::" "" $tab_completion_list
124 # OTOH
, the complete command must
show the whole command
, with
125 # qualified symbol displayed as entered by the user.
126 set cmd_completion_list
{
128 "Test_NS::Nested::qux"
132 test_gdb_complete_cmd_multiple
"p " "Test_NS:" $cmd_completion_list
133 test_gdb_complete_cmd_multiple
"p " "Test_NS::" $cmd_completion_list
135 # Add a disambiguating character and we
get a unique completion.
136 test_gdb_complete_unique
"p Test_NS::f" "p Test_NS::foo"