Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-completion.exp
CommitLineData
88b9d363 1# Copyright (C) 2014-2022 Free Software Foundation, Inc.
7d793aa9
SDJ
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
16set testfile "py-completion"
17
18load_lib gdb-python.exp
19
74c2c1f4
SL
20set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
21set discard 0
7d793aa9
SDJ
22gdb_exit
23gdb_start
24
25# Skip all tests if Python scripting is not enabled.
26if { [skip_python_tests] } { continue }
27
74c2c1f4
SL
28# Tab completion tests require readline support, and this set of tests
29# doesn't work on a remote host either.
30if { [readline_is_used] && ![is_remote host] } {
31 gdb_test_no_output "source ${pyfile}" "load python file"
32
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
38
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"
44 }
7d793aa9 45 }
7d793aa9 46
74c2c1f4
SL
47 # Just discarding whatever we typed.
48 gdb_test " " ".*" "discard #[incr discard]"
49
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)"
55 }
56 -re "^completefilemethod ${testdir_regex}$" {
57 pass "completefilemethod completion"
58 }
7d793aa9 59 }
7d793aa9 60
74c2c1f4
SL
61 # Discarding again
62 gdb_test " " ".*" "discard #[incr discard]"
63
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)"
70 }
71 -re "^completefilecommandcond ${completion_regex}\007$" {
72 pass "completefilecommandcond completion"
73 }
7d793aa9 74 }
74c2c1f4 75
7d793aa9 76}
6d62641c
SDJ
77
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.
80gdb_exit
81gdb_start
74c2c1f4 82gdb_test_no_output "source ${pyfile}" "load python file again"
6d62641c
SDJ
83
84gdb_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"
93 }
94
95# Discarding again
96gdb_test " " ".*" "discard #[incr discard]"
97
98gdb_test_sequence "complete completelimit1 c" \
99 "list all completions of 'complete completelimit1 c'" {
100 "completelimit1 cl11"
101 "completelimit1 cl12"
102 "completelimit1 cl13"
103 }
104
105# Discarding again
106gdb_test " " ".*" "discard #[incr discard]"
107
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.
111if {[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
117
118 # Discard the command line
119 gdb_test " " ".*" "discard #[incr discard]"
120 }
121 }
122
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"
135 }
136}
This page took 1.386076 seconds and 4 git commands to generate.