Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.base / readline.exp
blob511cb6ba2e5fe352a80a9bea97b35397c9c11ecb
1 # Copyright 2002 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.
7 #
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} {
32 global gdb_prompt
34 set my_gdb_prompt "($gdb_prompt| >)"
36 set reverse {}
37 foreach {item result} $args {
38 verbose "sending $item"
39 sleep 1
41 # We can't use gdb_test here because we might see a " >" prompt.
42 set status 0
43 send_gdb "$item\n"
44 gdb_expect {
45 -re "$item" {
46 # Ok
48 timeout {
49 set status 1
53 if {! $status} {
54 gdb_expect {
55 -re "$result" {
56 # Ok.
58 timeout {
59 set status 1
64 if {$status} {
65 fail "$name - send $item"
66 return 0
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.
77 send_gdb "\x10\x0c"
78 set status 0
79 gdb_expect {
80 -re "$item" {
81 # Ok
83 timeout {
84 set status 1
87 if {$status} {
88 fail "$name - C-p to $item"
89 return 0
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.
97 set count 0
98 foreach {item result} $args {
99 set status 0
101 # If this isn't the first item, make sure we see the command at
102 # the prompt.
103 if {$count > 0} {
104 gdb_expect {
105 -re ".*$item" {
106 # Ok
108 timeout {
109 set status 1
114 if {! $status} {
115 # For the last item, send a simple \n instead of C-o.
116 if {$count == [llength $args] - 2} {
117 send_gdb "\n"
118 } else {
119 # 15 is C-o.
120 send_gdb [format %c 15]
122 set status 0
123 gdb_expect {
124 -re "$result" {
125 # Ok
127 timeout {
128 set status 1
133 if {$status} {
134 fail "$name - C-o for $item"
135 return 0
137 pass "$name - C-o for $item"
139 set count [expr {$count + 2}]
142 return 1
146 if $tracelevel {
147 strace $tracelevel
150 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
151 # the test results. Even if /dev/null doesn't exist on the particular
152 # platform, the readline library will use the default setting just by
153 # failing to open the file. OTOH, opening /dev/null successfully will
154 # also result in the default settings being used since nothing will be
155 # read from this file.
156 global env
157 if [info exists env(INPUTRC)] {
158 set old_inputrc $env(INPUTRC)
160 set env(INPUTRC) "/dev/null"
162 gdb_start
163 gdb_reinitialize_dir $srcdir/$subdir
165 set oldtimeout1 $timeout
166 set timeout 30
169 # A simple test of operate-and-get-next.
170 operate_and_get_next "Simple operate-and-get-next" \
171 "p 1" ".* = 1" \
172 "p 2" ".* = 2" \
173 "p 3" ".* = 3"
175 # Test operate-and-get-next with a secondary prompt.
176 operate_and_get_next "operate-and-get-next with secondary prompt" \
177 "if 1 > 0" "" \
178 "p 5" "" \
179 "end" ".* = 5"
182 # Now repeat the first test with a history file that fills the entire
183 # history list.
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"
194 gdb_exit
195 gdb_start
196 gdb_reinitialize_dir $srcdir/$subdir
198 operate_and_get_next "Simple operate-and-get-next" \
199 "p 7" ".* = 7" \
200 "p 8" ".* = 8" \
201 "p 9" ".* = 9"
204 # Restore globals modified in this test...
205 if [info exists old_inputrc] {
206 set env(INPUTRC) $old_inputrc
207 } else {
208 unset env(INPUTRC)
210 if [info exists old_gdbhistfile] {
211 set env(GDBHISTFILE) $old_gdbhistfile
212 } else {
213 unset env(GDBHISTFILE)
215 if [info exists old_histsize] {
216 set env(HISTSIZE) $old_histsize
217 } else {
218 unset env(HISTSIZE)
220 set timeout $oldtimeout1
222 return 0