1 # Copyright 2002, 2003, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Tom Tromey <tromey@redhat.com>
19 # This file is part of the gdb testsuite.
22 # Tests for readline operations.
25 # This function is used to test operate-and-get-next.
26 # NAME is the name of the test.
27 # ARGS is a list of alternating commands and expected results.
28 proc operate_and_get_next {name args} {
31 set my_gdb_prompt "($gdb_prompt| >)"
34 foreach {item result} $args {
35 verbose "sending $item"
38 # We can't use gdb_test here because we might see a " >" prompt.
62 fail "$name - send $item"
65 pass "$name - send $item"
67 set reverse [linsert $reverse 0 $item $result]
70 # Now use C-p to go back to the start.
71 foreach {item result} $reverse {
72 # Actually send C-p followed by C-l. This lets us recognize the
73 # command when gdb prints it again.
85 fail "$name - C-p to $item"
88 pass "$name - C-p to $item"
91 # Now C-o through the list. Don't send the command, since it is
92 # already there. Strip off the first command from the list so we
93 # can see the next command inside the loop.
95 foreach {item result} $args {
98 # If this isn't the first item, make sure we see the command at
112 # For the last item, send a simple \n instead of C-o.
113 if {$count == [llength $args] - 2} {
117 send_gdb [format %c 15]
131 fail "$name - C-o for $item"
134 pass "$name - C-o for $item"
136 set count [expr {$count + 2}]
139 # Match the prompt so the next test starts at the right place.
140 gdb_test "" ".*" "$name - final prompt"
151 gdb_reinitialize_dir $srcdir/$subdir
153 set oldtimeout1 $timeout
157 # A simple test of operate-and-get-next.
158 operate_and_get_next "Simple operate-and-get-next" \
163 # Test operate-and-get-next with a secondary prompt.
164 operate_and_get_next "operate-and-get-next with secondary prompt" \
169 # Verify that arrow keys work in secondary prompts. The control
170 # sequence is a hard-coded VT100 up arrow.
171 gdb_test "print 42" "\\\$\[0-9\]* = 42"
172 set msg "arrow keys with secondary prompt"
173 gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
174 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
177 -re ".*Undefined command:.*$gdb_prompt $" {
182 # Now repeat the first test with a history file that fills the entire
185 if [info exists env(GDBHISTFILE)] {
186 set old_gdbhistfile $env(GDBHISTFILE)
188 if [info exists env(HISTSIZE)] {
189 set old_histsize $env(HISTSIZE)
191 set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
192 set env(HISTSIZE) "10"
196 gdb_reinitialize_dir $srcdir/$subdir
198 operate_and_get_next "Simple operate-and-get-next" \
204 # Restore globals modified in this test...
205 if [info exists old_gdbhistfile] {
206 set env(GDBHISTFILE) $old_gdbhistfile
208 unset env(GDBHISTFILE)
210 if [info exists old_histsize] {
211 set env(HISTSIZE) $old_histsize
215 set timeout $oldtimeout1