1# Copyright (C) 2014-2016 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 16set testfile "py-completion" 17 18load_lib gdb-python.exp 19 20gdb_exit 21gdb_start 22 23# Skip all tests if Python scripting is not enabled. 24if { [skip_python_tests] } { continue } 25 26gdb_test_no_output "source ${srcdir}/${subdir}/${testfile}.py" 27 28# Create a temporary directory 29set testdir "[standard_output_file "py-completion-testdir"]/" 30set testdir_regex [string_to_regexp $testdir] 31set testdir_complete [standard_output_file "py-completion-test"] 32file mkdir $testdir 33 34# This one should always pass. 35send_gdb "completefileinit ${testdir_complete}\t" 36gdb_test_multiple "" "completefileinit completion" { 37 -re "^completefileinit ${testdir_regex}$" { 38 pass "completefileinit completion" 39 } 40} 41 42# Just discarding whatever we typed. 43set discard 0 44gdb_test " " ".*" "discard #[incr discard]" 45 46# This is the problematic one. 47send_gdb "completefilemethod ${testdir_complete}\t" 48gdb_test_multiple "" "completefilemethod completion" { 49 -re "^completefilemethod ${testdir_regex} $" { 50 fail "completefilemethod completion (completed filename as wrong command arg)" 51 } 52 -re "^completefilemethod ${testdir_regex}$" { 53 pass "completefilemethod completion" 54 } 55} 56 57# Discarding again 58gdb_test " " ".*" "discard #[incr discard]" 59 60# Another problematic 61set completion_regex "[string_to_regexp [standard_output_file "py-completion-t"]]" 62send_gdb "completefilecommandcond [standard_output_file "py-completion-t\t"]" 63gdb_test_multiple "" "completefilecommandcond completion" { 64 -re "^completefilecommandcond ${testdir}$" { 65 fail "completefilecommandcond completion (completed filename instead of command)" 66 } 67 -re "^completefilecommandcond ${completion_regex}\007$" { 68 pass "completefilecommandcond completion" 69 } 70} 71 72# Start gdb over again to clear out current state. This can interfere 73# with the expected output of the below tests in a buggy gdb. 74gdb_exit 75gdb_start 76gdb_test_no_output "source ${srcdir}/${subdir}/${testfile}.py" 77 78gdb_test_sequence "complete completel" \ 79 "list all completions of 'complete completel'" { 80 "completelimit1" 81 "completelimit2" 82 "completelimit3" 83 "completelimit4" 84 "completelimit5" 85 "completelimit6" 86 "completelimit7" 87 } 88 89# Discarding again 90gdb_test " " ".*" "discard #[incr discard]" 91 92gdb_test_sequence "complete completelimit1 c" \ 93 "list all completions of 'complete completelimit1 c'" { 94 "completelimit1 cl11" 95 "completelimit1 cl12" 96 "completelimit1 cl13" 97 } 98 99# Discarding again 100gdb_test " " ".*" "discard #[incr discard]" 101 102# If using readline, we can TAB-complete. This used to trigger a bug 103# because the cached result from the completer was being reused for 104# a different python command. 105if {[readline_is_used]} { 106 set testname "tab-complete 'completelimit1 c'" 107 send_gdb "completelimit1 c\t" 108 gdb_test_multiple "" $testname { 109 -re "^completelimit1 c\\\x07l1$" { 110 pass $testname 111 112 # Discard the command line 113 gdb_test " " ".*" "discard #[incr discard]" 114 } 115 } 116 117 gdb_test_sequence "complete completelimit2 c" \ 118 "list all completions of 'complete completelimit2 c'" { 119 "completelimit2 cl21" 120 "completelimit2 cl210" 121 "completelimit2 cl22" 122 "completelimit2 cl23" 123 "completelimit2 cl24" 124 "completelimit2 cl25" 125 "completelimit2 cl26" 126 "completelimit2 cl27" 127 "completelimit2 cl28" 128 "completelimit2 cl29" 129 } 130} 131