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