1 # Copyright (C) 2014-2024 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 set testfile "py-completion"
18 load_lib gdb-python.exp
20 require allow_python_tests
22 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
27 # Tab completion tests require readline support, and this set of tests
28 # doesn't work on a remote host either.
29 if { [readline_is_used] && ![is_remote host] } {
30 gdb_test_no_output "source ${pyfile}" "load python file"
32 # Create a temporary directory
33 set testdir "[standard_output_file "py-completion-testdir"]/"
34 set testdir_regex [string_to_regexp $testdir]
35 set testdir_complete [standard_output_file "py-completion-test"]
38 # This one should always pass.
39 send_gdb "completefileinit ${testdir_complete}\t"
40 gdb_test_multiple "" "completefileinit completion" {
41 -re "^completefileinit ${testdir_regex}$" {
42 pass "completefileinit completion"
46 # Just discarding whatever we typed.
47 gdb_test " " ".*" "discard #[incr discard]"
49 # This should offer no suggestions - the complete() methods
50 # returns something that is neither an integer, or a sequence.
51 gdb_test_no_output "complete completefilenone ${testdir_complete}" \
52 "no suggestions given"
54 # This is the problematic one.
55 send_gdb "completefilemethod ${testdir_complete}\t"
56 gdb_test_multiple "" "completefilemethod completion" {
57 -re "^completefilemethod ${testdir_regex} $" {
58 fail "completefilemethod completion (completed filename as wrong command arg)"
60 -re "^completefilemethod ${testdir_regex}$" {
61 pass "completefilemethod completion"
66 gdb_test " " ".*" "discard #[incr discard]"
69 set completion_regex "[string_to_regexp [standard_output_file "py-completion-t"]]"
70 send_gdb "completefilecommandcond [standard_output_file "py-completion-t\t"]"
71 gdb_test_multiple "" "completefilecommandcond completion" {
72 -re "^completefilecommandcond ${testdir}$" {
73 fail "completefilecommandcond completion (completed filename instead of command)"
75 -re "^completefilecommandcond ${completion_regex}\007$" {
76 pass "completefilecommandcond completion"
81 gdb_test " " ".*" "discard #[incr discard]"
84 # Start gdb over again to clear out current state. This can interfere
85 # with the expected output of the below tests in a buggy gdb.
88 gdb_test_no_output "source ${pyfile}" "load python file again"
90 # Check that GDB prints exceptions raised by Command.complete calls.
91 # This first command raises an exception during the brkchars phase of
93 gdb_test "complete complete_brkchar_exception " \
94 "Python Exception <class 'gdb\\.GdbError'>: brkchars exception"
96 # In this test the brkchars phase of completion is fine, but an
97 # exception is raised during the actual completion phase.
98 gdb_test "complete complete_raise_exception " \
99 "Python Exception <class 'gdb\\.GdbError'>: completion exception"
101 gdb_test_sequence "complete completel" \
102 "list all completions of 'complete completel'" {
113 gdb_test " " ".*" "discard #[incr discard]"
115 gdb_test_sequence "complete completelimit1 c" \
116 "list all completions of 'complete completelimit1 c'" {
117 "completelimit1 cl11"
118 "completelimit1 cl12"
119 "completelimit1 cl13"
123 gdb_test " " ".*" "discard #[incr discard]"
125 # If using readline, we can TAB-complete. This used to trigger a bug
126 # because the cached result from the completer was being reused for
127 # a different python command.
128 if {[readline_is_used]} {
129 set testname "tab-complete 'completelimit1 c'"
130 send_gdb "completelimit1 c\t"
131 gdb_test_multiple "" $testname {
132 -re "^completelimit1 c\\\x07l1$" {
135 # Discard the command line
136 gdb_test " " ".*" "discard #[incr discard]"
140 gdb_test_sequence "complete completelimit2 c" \
141 "list all completions of 'complete completelimit2 c'" {
142 "completelimit2 cl21"
143 "completelimit2 cl210"
144 "completelimit2 cl22"
145 "completelimit2 cl23"
146 "completelimit2 cl24"
147 "completelimit2 cl25"
148 "completelimit2 cl26"
149 "completelimit2 cl27"
150 "completelimit2 cl28"
151 "completelimit2 cl29"