1 # Copyright 2002, 2003, 2007, 2008, 2009 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 # This file was written by Tom Tromey <tromey@redhat.com>
18 # This file is part of the gdb testsuite.
21 # Tests for readline operations.
24 # This function is used to test operate-and-get-next.
25 # NAME is the name of the test.
26 # ARGS is a list of alternating commands and expected results.
27 proc operate_and_get_next {name args} {
30 set my_gdb_prompt "($gdb_prompt| >)"
33 foreach {item result} $args {
34 verbose "sending $item"
37 # We can't use gdb_test here because we might see a " >" prompt.
61 fail "$name - send $item"
64 pass "$name - send $item"
66 set reverse [linsert $reverse 0 $item $result]
69 # Now use C-p to go back to the start.
70 foreach {item result} $reverse {
71 # Actually send C-p followed by C-l. This lets us recognize the
72 # command when gdb prints it again.
84 fail "$name - C-p to $item"
87 pass "$name - C-p to $item"
90 # Now C-o through the list. Don't send the command, since it is
91 # already there. Strip off the first command from the list so we
92 # can see the next command inside the loop.
94 foreach {item result} $args {
97 # If this isn't the first item, make sure we see the command at
111 # For the last item, send a simple \n instead of C-o.
112 if {$count == [llength $args] - 2} {
116 send_gdb [format %c 15]
130 fail "$name - C-o for $item"
133 pass "$name - C-o for $item"
135 set count [expr {$count + 2}]
138 # Match the prompt so the next test starts at the right place.
139 gdb_test "" "" "$name - final prompt"
149 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
150 # the test results. Even if /dev/null doesn't exist on the particular
151 # platform, the readline library will use the default setting just by
152 # failing to open the file. OTOH, opening /dev/null successfully will
153 # also result in the default settings being used since nothing will be
154 # read from this file.
156 if [info exists env(INPUTRC)] {
157 set old_inputrc $env(INPUTRC)
159 set env(INPUTRC) "/dev/null"
161 # The arrow key test relies on the standard VT100 bindings, so make
162 # sure that an appropriate terminal is selected. The same bug
163 # doesn't show up if we use ^P / ^N instead.
164 if [info exists env(TERM)] {
165 set old_term $env(TERM)
167 set env(TERM) "vt100"
170 gdb_reinitialize_dir $srcdir/$subdir
172 set oldtimeout1 $timeout
176 # A simple test of operate-and-get-next.
177 operate_and_get_next "Simple operate-and-get-next" \
182 # Test operate-and-get-next with a secondary prompt.
183 operate_and_get_next "operate-and-get-next with secondary prompt" \
188 # Verify that arrow keys work in secondary prompts. The control
189 # sequence is a hard-coded VT100 up arrow.
190 gdb_test "print 42" "\\\$\[0-9\]* = 42"
191 set msg "arrow keys with secondary prompt"
192 gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
193 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
196 -re ".*Undefined command:.*$gdb_prompt $" {
201 # Now repeat the first test with a history file that fills the entire
204 if [info exists env(GDBHISTFILE)] {
205 set old_gdbhistfile $env(GDBHISTFILE)
207 if [info exists env(HISTSIZE)] {
208 set old_histsize $env(HISTSIZE)
210 set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
211 set env(HISTSIZE) "10"
215 gdb_reinitialize_dir $srcdir/$subdir
217 operate_and_get_next "Simple operate-and-get-next" \
223 # Restore globals modified in this test...
224 if [info exists old_inputrc] {
225 set env(INPUTRC) $old_inputrc
229 if [info exists old_gdbhistfile] {
230 set env(GDBHISTFILE) $old_gdbhistfile
232 unset env(GDBHISTFILE)
234 if [info exists old_histsize] {
235 set env(HISTSIZE) $old_histsize
239 set timeout $oldtimeout1