]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-completion.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-completion.exp
1 # Copyright (C) 2014-2024 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 set testfile "py-completion"
17
18 load_lib gdb-python.exp
19
20 require allow_python_tests
21
22 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
23 set discard 0
24 gdb_exit
25 gdb_start
26
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"
31
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"]
36 file mkdir $testdir
37
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"
43 }
44 }
45
46 # Just discarding whatever we typed.
47 gdb_test " " ".*" "discard #[incr discard]"
48
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"
53
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)"
59 }
60 -re "^completefilemethod ${testdir_regex}$" {
61 pass "completefilemethod completion"
62 }
63 }
64
65 # Discarding again
66 gdb_test " " ".*" "discard #[incr discard]"
67
68 # Another problematic
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)"
74 }
75 -re "^completefilecommandcond ${completion_regex}\007$" {
76 pass "completefilecommandcond completion"
77 }
78 }
79
80 # Discarding again
81 gdb_test " " ".*" "discard #[incr discard]"
82 }
83
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.
86 gdb_exit
87 gdb_start
88 gdb_test_no_output "source ${pyfile}" "load python file again"
89
90 # Check that GDB prints exceptions raised by Command.complete calls.
91 # This first command raises an exception during the brkchars phase of
92 # completion.
93 gdb_test "complete complete_brkchar_exception " \
94 "Python Exception <class 'gdb\\.GdbError'>: brkchars exception"
95
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"
100
101 gdb_test_sequence "complete completel" \
102 "list all completions of 'complete completel'" {
103 "completelimit1"
104 "completelimit2"
105 "completelimit3"
106 "completelimit4"
107 "completelimit5"
108 "completelimit6"
109 "completelimit7"
110 }
111
112 # Discarding again
113 gdb_test " " ".*" "discard #[incr discard]"
114
115 gdb_test_sequence "complete completelimit1 c" \
116 "list all completions of 'complete completelimit1 c'" {
117 "completelimit1 cl11"
118 "completelimit1 cl12"
119 "completelimit1 cl13"
120 }
121
122 # Discarding again
123 gdb_test " " ".*" "discard #[incr discard]"
124
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$" {
133 pass $testname
134
135 # Discard the command line
136 gdb_test " " ".*" "discard #[incr discard]"
137 }
138 }
139
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"
152 }
153 }