1 # Copyright 2002-2022 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"
144 save_vars { env(TERM) } {
145 # The arrow key test relies on the standard VT100 bindings, so
146 # make sure that an appropriate terminal is selected. The same
147 # bug doesn't show up if we use ^P / ^N instead.
151 gdb_reinitialize_dir $srcdir/$subdir
153 if { ![readline_is_used] } {
154 unsupported "readline isn't used."
158 save_vars { timeout env(GDBHISTSIZE) env(GDBHISTFILE) } {
161 # A simple test of operate-and-get-next.
162 operate_and_get_next "Simple operate-and-get-next" \
167 # Test operate-and-get-next with a secondary prompt.
168 operate_and_get_next "operate-and-get-next with secondary prompt" \
173 # Verify that arrow keys work in secondary prompts. The control
174 # sequence is a hard-coded VT100 up arrow.
175 gdb_test "print 42" "\\\$\[0-9\]* = 42"
176 set msg "arrow keys with secondary prompt"
177 gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
178 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
181 -re ".*Undefined command:.*$gdb_prompt $" {
186 # Use the up arrow to select a previous command. Check that
187 # no unexpected output is added between the previously
188 # selected command, and the output of that command.
189 gdb_test "print 123" "\\\$\[0-9\]* = 123"
190 gdb_test_multiple "\033\[A" "use up arrow" {
191 -re -wrap "print 123\r\n\\\$\[0-9\]* = 123" {
196 # Now repeat the first test with a history file that fills the entire
199 set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
200 set env(GDBHISTSIZE) "10"
204 gdb_reinitialize_dir $srcdir/$subdir
206 operate_and_get_next "Simple operate-and-get-next, two" \