1 # Copyright 2002, 2003, 2007, 2008 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 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Tom Tromey <tromey@redhat.com>
21 # This file is part of the gdb testsuite.
24 # Tests for readline operations.
27 # This function is used to test operate-and-get-next.
28 # NAME is the name of the test.
29 # ARGS is a list of alternating commands and expected results.
30 proc operate_and_get_next {name args} {
33 set my_gdb_prompt "($gdb_prompt| >)"
36 foreach {item result} $args {
37 verbose "sending $item"
40 # We can't use gdb_test here because we might see a " >" prompt.
64 fail "$name - send $item"
67 pass "$name - send $item"
69 set reverse [linsert $reverse 0 $item $result]
72 # Now use C-p to go back to the start.
73 foreach {item result} $reverse {
74 # Actually send C-p followed by C-l. This lets us recognize the
75 # command when gdb prints it again.
87 fail "$name - C-p to $item"
90 pass "$name - C-p to $item"
93 # Now C-o through the list. Don't send the command, since it is
94 # already there. Strip off the first command from the list so we
95 # can see the next command inside the loop.
97 foreach {item result} $args {
100 # If this isn't the first item, make sure we see the command at
114 # For the last item, send a simple \n instead of C-o.
115 if {$count == [llength $args] - 2} {
119 send_gdb [format %c 15]
133 fail "$name - C-o for $item"
136 pass "$name - C-o for $item"
138 set count [expr {$count + 2}]
141 # Match the prompt so the next test starts at the right place.
142 gdb_test "" "" "$name - final prompt"
152 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
153 # the test results. Even if /dev/null doesn't exist on the particular
154 # platform, the readline library will use the default setting just by
155 # failing to open the file. OTOH, opening /dev/null successfully will
156 # also result in the default settings being used since nothing will be
157 # read from this file.
159 if [info exists env(INPUTRC)] {
160 set old_inputrc $env(INPUTRC)
162 set env(INPUTRC) "/dev/null"
164 # The arrow key test relies on the standard VT100 bindings, so make
165 # sure that an appropriate terminal is selected. The same bug
166 # doesn't show up if we use ^P / ^N instead.
167 if [info exists env(TERM)] {
168 set old_term $env(TERM)
170 set env(TERM) "vt100"
173 gdb_reinitialize_dir $srcdir/$subdir
175 set oldtimeout1 $timeout
179 # A simple test of operate-and-get-next.
180 operate_and_get_next "Simple operate-and-get-next" \
185 # Test operate-and-get-next with a secondary prompt.
186 operate_and_get_next "operate-and-get-next with secondary prompt" \
191 # Verify that arrow keys work in secondary prompts. The control
192 # sequence is a hard-coded VT100 up arrow.
193 gdb_test "print 42" "\\\$\[0-9\]* = 42"
194 set msg "arrow keys with secondary prompt"
195 gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
196 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
199 -re ".*Undefined command:.*$gdb_prompt $" {
204 # Now repeat the first test with a history file that fills the entire
207 if [info exists env(GDBHISTFILE)] {
208 set old_gdbhistfile $env(GDBHISTFILE)
210 if [info exists env(HISTSIZE)] {
211 set old_histsize $env(HISTSIZE)
213 set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
214 set env(HISTSIZE) "10"
218 gdb_reinitialize_dir $srcdir/$subdir
220 operate_and_get_next "Simple operate-and-get-next" \
226 # Restore globals modified in this test...
227 if [info exists old_inputrc] {
228 set env(INPUTRC) $old_inputrc
232 if [info exists old_gdbhistfile] {
233 set env(GDBHISTFILE) $old_gdbhistfile
235 unset env(GDBHISTFILE)
237 if [info exists old_histsize] {
238 set env(HISTSIZE) $old_histsize
242 set timeout $oldtimeout1