1 # Copyright 2002, 2003, 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Tom Tromey <tromey@redhat.com>
22 # This file is part of the gdb testsuite.
25 # Tests for readline operations.
28 # This function is used to test operate-and-get-next.
29 # NAME is the name of the test.
30 # ARGS is a list of alternating commands and expected results.
31 proc operate_and_get_next {name args} {
34 set my_gdb_prompt "($gdb_prompt| >)"
37 foreach {item result} $args {
38 verbose "sending $item"
41 # We can't use gdb_test here because we might see a " >" prompt.
65 fail "$name - send $item"
68 pass "$name - send $item"
70 set reverse [linsert $reverse 0 $item $result]
73 # Now use C-p to go back to the start.
74 foreach {item result} $reverse {
75 # Actually send C-p followed by C-l. This lets us recognize the
76 # command when gdb prints it again.
88 fail "$name - C-p to $item"
91 pass "$name - C-p to $item"
94 # Now C-o through the list. Don't send the command, since it is
95 # already there. Strip off the first command from the list so we
96 # can see the next command inside the loop.
98 foreach {item result} $args {
101 # If this isn't the first item, make sure we see the command at
115 # For the last item, send a simple \n instead of C-o.
116 if {$count == [llength $args] - 2} {
120 send_gdb [format %c 15]
134 fail "$name - C-o for $item"
137 pass "$name - C-o for $item"
139 set count [expr {$count + 2}]
142 # Match the prompt so the next test starts at the right place.
143 gdb_test "" "" "$name - final prompt"
153 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
154 # the test results. Even if /dev/null doesn't exist on the particular
155 # platform, the readline library will use the default setting just by
156 # failing to open the file. OTOH, opening /dev/null successfully will
157 # also result in the default settings being used since nothing will be
158 # read from this file.
160 if [info exists env(INPUTRC)] {
161 set old_inputrc $env(INPUTRC)
163 set env(INPUTRC) "/dev/null"
165 # The arrow key test relies on the standard VT100 bindings, so make
166 # sure that an appropriate terminal is selected. The same bug
167 # doesn't show up if we use ^P / ^N instead.
168 if [info exists env(TERM)] {
169 set old_term $env(TERM)
171 set env(TERM) "vt100"
174 gdb_reinitialize_dir $srcdir/$subdir
176 set oldtimeout1 $timeout
180 # A simple test of operate-and-get-next.
181 operate_and_get_next "Simple operate-and-get-next" \
186 # Test operate-and-get-next with a secondary prompt.
187 operate_and_get_next "operate-and-get-next with secondary prompt" \
192 # Verify that arrow keys work in secondary prompts. The control
193 # sequence is a hard-coded VT100 up arrow.
194 gdb_test "print 42" "\\\$\[0-9\]* = 42"
195 set msg "arrow keys with secondary prompt"
196 gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
197 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
200 -re ".*Undefined command:.*$gdb_prompt $" {
205 # Now repeat the first test with a history file that fills the entire
208 if [info exists env(GDBHISTFILE)] {
209 set old_gdbhistfile $env(GDBHISTFILE)
211 if [info exists env(HISTSIZE)] {
212 set old_histsize $env(HISTSIZE)
214 set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
215 set env(HISTSIZE) "10"
219 gdb_reinitialize_dir $srcdir/$subdir
221 operate_and_get_next "Simple operate-and-get-next" \
227 # Restore globals modified in this test...
228 if [info exists old_inputrc] {
229 set env(INPUTRC) $old_inputrc
233 if [info exists old_gdbhistfile] {
234 set env(GDBHISTFILE) $old_gdbhistfile
236 unset env(GDBHISTFILE)
238 if [info exists old_histsize] {
239 set env(HISTSIZE) $old_histsize
243 set timeout $oldtimeout1