| 1 | # Copyright 2009-2019 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 | # Tests below are about tab-completion, which doesn't work if readline |
| 63 | # library isn't used. Check it first. |
| 64 | |
| 65 | if { ![readline_is_used] } { |
| 66 | untested "no tab completion support without readline" |
| 67 | return -1 |
| 68 | } |
| 69 | |
| 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] |
| 73 | |
| 74 | test_class_complete Foo F "complete class methods beginning with F" \ |
| 75 | [list Foo Foofoo] |
| 76 | |
| 77 | # The tests below depend on the current code scope. |
| 78 | |
| 79 | set bp_location [gdb_get_line_number "Set breakpoint here" ${srcfile}] |
| 80 | |
| 81 | if {![runto "${srcfile}:$bp_location"]} { |
| 82 | perror "test suppressed" |
| 83 | return |
| 84 | } |
| 85 | |
| 86 | # This also tests inheritance -- completion should only see a single |
| 87 | # "get_foo". |
| 88 | gdb_test "complete p foo1.g" "p foo1\\.get_foo" |
| 89 | |
| 90 | # Test inheritance without overriding. |
| 91 | gdb_test "complete p foo1.base" "p foo1\\.base_function_only" |
| 92 | |
| 93 | # Test non-completion of constructor names. |
| 94 | gdb_test "complete p foo1.Fo" "p foo1\\.Foofoo" |
| 95 | |
| 96 | # Test completion with an anonymous struct. |
| 97 | gdb_test "complete p a.g" "p a\\.get" |
| 98 | |
| 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" "" { |
| 103 | "Test_NS" |
| 104 | "Test_NS::Nested" |
| 105 | "Test_NS::Nested::qux" |
| 106 | "Test_NS::bar" |
| 107 | "Test_NS::foo" |
| 108 | } |
| 109 | |
| 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. |
| 114 | |
| 115 | set tab_completion_list { |
| 116 | "Nested" |
| 117 | "Nested::qux" |
| 118 | "bar" |
| 119 | "foo" |
| 120 | } |
| 121 | test_gdb_complete_tab_multiple "p Test_NS:" ":" $tab_completion_list |
| 122 | test_gdb_complete_tab_multiple "p Test_NS::" "" $tab_completion_list |
| 123 | |
| 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 { |
| 127 | "Test_NS::Nested" |
| 128 | "Test_NS::Nested::qux" |
| 129 | "Test_NS::bar" |
| 130 | "Test_NS::foo" |
| 131 | } |
| 132 | test_gdb_complete_cmd_multiple "p " "Test_NS:" $cmd_completion_list |
| 133 | test_gdb_complete_cmd_multiple "p " "Test_NS::" $cmd_completion_list |
| 134 | |
| 135 | # Add a disambiguating character and we get a unique completion. |
| 136 | test_gdb_complete_unique "p Test_NS::f" "p Test_NS::foo" |
| 137 | } |