2011-02-21 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / readline.exp
CommitLineData
7b6bb8da
JB
1# Copyright 2002, 2003, 2007, 2008, 2009, 2010, 2011
2# Free Software Foundation, Inc.
3c1499ad
TT
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
3c1499ad 7# (at your option) any later version.
e22f8b7c 8#
3c1499ad
TT
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.
e22f8b7c 13#
3c1499ad 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
3c1499ad 16
3c1499ad
TT
17# This file was written by Tom Tromey <tromey@redhat.com>
18
19# This file is part of the gdb testsuite.
20
21#
22# Tests for readline operations.
23#
24
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.
28proc operate_and_get_next {name args} {
29 global gdb_prompt
30
31 set my_gdb_prompt "($gdb_prompt| >)"
32
33 set reverse {}
34 foreach {item result} $args {
35 verbose "sending $item"
36 sleep 1
37
38 # We can't use gdb_test here because we might see a " >" prompt.
39 set status 0
40 send_gdb "$item\n"
41 gdb_expect {
42 -re "$item" {
43 # Ok
44 }
45 timeout {
46 set status 1
47 }
48 }
49
50 if {! $status} {
51 gdb_expect {
52 -re "$result" {
53 # Ok.
54 }
55 timeout {
56 set status 1
57 }
58 }
59 }
60
61 if {$status} {
62 fail "$name - send $item"
63 return 0
64 }
65 pass "$name - send $item"
66
67 set reverse [linsert $reverse 0 $item $result]
68 }
69
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.
74 send_gdb "\x10\x0c"
75 set status 0
76 gdb_expect {
77 -re "$item" {
78 # Ok
79 }
80 timeout {
81 set status 1
82 }
83 }
84 if {$status} {
85 fail "$name - C-p to $item"
86 return 0
87 }
88 pass "$name - C-p to $item"
89 }
90
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.
94 set count 0
95 foreach {item result} $args {
96 set status 0
97
98 # If this isn't the first item, make sure we see the command at
99 # the prompt.
100 if {$count > 0} {
101 gdb_expect {
102 -re ".*$item" {
103 # Ok
104 }
105 timeout {
106 set status 1
107 }
108 }
109 }
110
111 if {! $status} {
112 # For the last item, send a simple \n instead of C-o.
113 if {$count == [llength $args] - 2} {
114 send_gdb "\n"
115 } else {
116 # 15 is C-o.
117 send_gdb [format %c 15]
118 }
119 set status 0
120 gdb_expect {
121 -re "$result" {
122 # Ok
123 }
124 timeout {
125 set status 1
126 }
127 }
128 }
129
130 if {$status} {
131 fail "$name - C-o for $item"
132 return 0
133 }
134 pass "$name - C-o for $item"
135
136 set count [expr {$count + 2}]
137 }
138
d4e07204 139 # Match the prompt so the next test starts at the right place.
de7ff789 140 gdb_test "" ".*" "$name - final prompt"
d4e07204 141
3c1499ad
TT
142 return 1
143}
144
145
146if $tracelevel {
147 strace $tracelevel
148}
149
3c1499ad
TT
150gdb_start
151gdb_reinitialize_dir $srcdir/$subdir
152
153set oldtimeout1 $timeout
154set timeout 30
155
156
157# A simple test of operate-and-get-next.
158operate_and_get_next "Simple operate-and-get-next" \
159 "p 1" ".* = 1" \
b5ca3722 160 "p 2" ".* = 2" \
3c1499ad
TT
161 "p 3" ".* = 3"
162
163# Test operate-and-get-next with a secondary prompt.
164operate_and_get_next "operate-and-get-next with secondary prompt" \
165 "if 1 > 0" "" \
166 "p 5" "" \
167 "end" ".* = 5"
168
2e03ee74
DJ
169# Verify that arrow keys work in secondary prompts. The control
170# sequence is a hard-coded VT100 up arrow.
171gdb_test "print 42" "\\\$\[0-9\]* = 42"
172set msg "arrow keys with secondary prompt"
173gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
174 -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
175 pass $msg
176 }
177 -re ".*Undefined command:.*$gdb_prompt $" {
178 fail $msg
179 }
180}
3c1499ad 181
b5ca3722
MK
182# Now repeat the first test with a history file that fills the entire
183# history list.
184
185if [info exists env(GDBHISTFILE)] {
186 set old_gdbhistfile $env(GDBHISTFILE)
187}
188if [info exists env(HISTSIZE)] {
189 set old_histsize $env(HISTSIZE)
190}
191set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
192set env(HISTSIZE) "10"
193
194gdb_exit
195gdb_start
196gdb_reinitialize_dir $srcdir/$subdir
197
198operate_and_get_next "Simple operate-and-get-next" \
199 "p 7" ".* = 7" \
200 "p 8" ".* = 8" \
201 "p 9" ".* = 9"
202
203
3c1499ad 204# Restore globals modified in this test...
b5ca3722
MK
205if [info exists old_gdbhistfile] {
206 set env(GDBHISTFILE) $old_gdbhistfile
207} else {
208 unset env(GDBHISTFILE)
209}
210if [info exists old_histsize] {
211 set env(HISTSIZE) $old_histsize
212} else {
213 unset env(HISTSIZE)
214}
3c1499ad
TT
215set timeout $oldtimeout1
216
217return 0
This page took 0.837579 seconds and 4 git commands to generate.