Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.python / py-completion.exp
blobaa4e0f46afc18571626441b2902942c1db7ff4a1
1 # Copyright (C) 2014-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 set testfile "py-completion"
18 load_lib gdb-python.exp
20 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
21 set discard 0
22 gdb_exit
23 gdb_start
25 # Skip all tests if Python scripting is not enabled.
26 if { [skip_python_tests] } { continue }
28 # Tab completion tests require readline support, and this set of tests
29 # doesn't work on a remote host either.
30 if { [readline_is_used] && ![is_remote host] } {
31 gdb_test_no_output "source ${pyfile}" "load python file"
33 # Create a temporary directory
34 set testdir "[standard_output_file "py-completion-testdir"]/"
35 set testdir_regex [string_to_regexp $testdir]
36 set testdir_complete [standard_output_file "py-completion-test"]
37 file mkdir $testdir
39 # This one should always pass.
40 send_gdb "completefileinit ${testdir_complete}\t"
41 gdb_test_multiple "" "completefileinit completion" {
42 -re "^completefileinit ${testdir_regex}$" {
43 pass "completefileinit completion"
47 # Just discarding whatever we typed.
48 gdb_test " " ".*" "discard #[incr discard]"
50 # This is the problematic one.
51 send_gdb "completefilemethod ${testdir_complete}\t"
52 gdb_test_multiple "" "completefilemethod completion" {
53 -re "^completefilemethod ${testdir_regex} $" {
54 fail "completefilemethod completion (completed filename as wrong command arg)"
56 -re "^completefilemethod ${testdir_regex}$" {
57 pass "completefilemethod completion"
61 # Discarding again
62 gdb_test " " ".*" "discard #[incr discard]"
64 # Another problematic
65 set completion_regex "[string_to_regexp [standard_output_file "py-completion-t"]]"
66 send_gdb "completefilecommandcond [standard_output_file "py-completion-t\t"]"
67 gdb_test_multiple "" "completefilecommandcond completion" {
68 -re "^completefilecommandcond ${testdir}$" {
69 fail "completefilecommandcond completion (completed filename instead of command)"
71 -re "^completefilecommandcond ${completion_regex}\007$" {
72 pass "completefilecommandcond completion"
78 # Start gdb over again to clear out current state. This can interfere
79 # with the expected output of the below tests in a buggy gdb.
80 gdb_exit
81 gdb_start
82 gdb_test_no_output "source ${pyfile}" "load python file again"
84 gdb_test_sequence "complete completel" \
85 "list all completions of 'complete completel'" {
86 "completelimit1"
87 "completelimit2"
88 "completelimit3"
89 "completelimit4"
90 "completelimit5"
91 "completelimit6"
92 "completelimit7"
95 # Discarding again
96 gdb_test " " ".*" "discard #[incr discard]"
98 gdb_test_sequence "complete completelimit1 c" \
99 "list all completions of 'complete completelimit1 c'" {
100 "completelimit1 cl11"
101 "completelimit1 cl12"
102 "completelimit1 cl13"
105 # Discarding again
106 gdb_test " " ".*" "discard #[incr discard]"
108 # If using readline, we can TAB-complete. This used to trigger a bug
109 # because the cached result from the completer was being reused for
110 # a different python command.
111 if {[readline_is_used]} {
112 set testname "tab-complete 'completelimit1 c'"
113 send_gdb "completelimit1 c\t"
114 gdb_test_multiple "" $testname {
115 -re "^completelimit1 c\\\x07l1$" {
116 pass $testname
118 # Discard the command line
119 gdb_test " " ".*" "discard #[incr discard]"
123 gdb_test_sequence "complete completelimit2 c" \
124 "list all completions of 'complete completelimit2 c'" {
125 "completelimit2 cl21"
126 "completelimit2 cl210"
127 "completelimit2 cl22"
128 "completelimit2 cl23"
129 "completelimit2 cl24"
130 "completelimit2 cl25"
131 "completelimit2 cl26"
132 "completelimit2 cl27"
133 "completelimit2 cl28"
134 "completelimit2 cl29"