1 # Copyright (C) 2014-2019 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
23 # Skip all tests if Python scripting is not enabled.
24 if { [skip_python_tests] } { continue }
26 gdb_test_no_output "source ${srcdir}/${subdir}/${testfile}.py" \
29 # Create a temporary directory
30 set testdir "[standard_output_file "py-completion-testdir"]/"
31 set testdir_regex [string_to_regexp $testdir]
32 set testdir_complete [standard_output_file "py-completion-test"]
35 # This one should always pass.
36 send_gdb "completefileinit ${testdir_complete}\t"
37 gdb_test_multiple "" "completefileinit completion" {
38 -re "^completefileinit ${testdir_regex}$" {
39 pass "completefileinit completion"
43 # Just discarding whatever we typed.
45 gdb_test " " ".*" "discard #[incr discard]"
47 # This is the problematic one.
48 send_gdb "completefilemethod ${testdir_complete}\t"
49 gdb_test_multiple "" "completefilemethod completion" {
50 -re "^completefilemethod ${testdir_regex} $" {
51 fail "completefilemethod completion (completed filename as wrong command arg)"
53 -re "^completefilemethod ${testdir_regex}$" {
54 pass "completefilemethod completion"
59 gdb_test " " ".*" "discard #[incr discard]"
62 set completion_regex "[string_to_regexp [standard_output_file "py-completion-t"]]"
63 send_gdb "completefilecommandcond [standard_output_file "py-completion-t\t"]"
64 gdb_test_multiple "" "completefilecommandcond completion" {
65 -re "^completefilecommandcond ${testdir}$" {
66 fail "completefilecommandcond completion (completed filename instead of command)"
68 -re "^completefilecommandcond ${completion_regex}\007$" {
69 pass "completefilecommandcond completion"
73 # Start gdb over again to clear out current state. This can interfere
74 # with the expected output of the below tests in a buggy gdb.
77 gdb_test_no_output "source ${srcdir}/${subdir}/${testfile}.py" \
78 "load python file again"
80 gdb_test_sequence "complete completel" \
81 "list all completions of 'complete completel'" {
92 gdb_test " " ".*" "discard #[incr discard]"
94 gdb_test_sequence "complete completelimit1 c" \
95 "list all completions of 'complete completelimit1 c'" {
102 gdb_test " " ".*" "discard #[incr discard]"
104 # If using readline, we can TAB-complete. This used to trigger a bug
105 # because the cached result from the completer was being reused for
106 # a different python command.
107 if {[readline_is_used]} {
108 set testname "tab-complete 'completelimit1 c'"
109 send_gdb "completelimit1 c\t"
110 gdb_test_multiple "" $testname {
111 -re "^completelimit1 c\\\x07l1$" {
114 # Discard the command line
115 gdb_test " " ".*" "discard #[incr discard]"
119 gdb_test_sequence "complete completelimit2 c" \
120 "list all completions of 'complete completelimit2 c'" {
121 "completelimit2 cl21"
122 "completelimit2 cl210"
123 "completelimit2 cl22"
124 "completelimit2 cl23"
125 "completelimit2 cl24"
126 "completelimit2 cl25"
127 "completelimit2 cl26"
128 "completelimit2 cl27"
129 "completelimit2 cl28"
130 "completelimit2 cl29"