(mu_expect_list): New procedure
Showing
1 changed file
with
80 additions
and
11 deletions
... | @@ -211,7 +211,8 @@ proc mu_expect { args } { | ... | @@ -211,7 +211,8 @@ proc mu_expect { args } { |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | verbose "RUNNING remote_expect host $gtimeout $notransfer $expcode" 2 | 214 | verbose "EXPCODE is $expcode" 4 |
215 | verbose "RUNNING remote_expect host $gtimeout $notransfer" 2 | ||
215 | 216 | ||
216 | set code [catch \ | 217 | set code [catch \ |
217 | {uplevel remote_expect host $gtimeout $notransfer $expcode} string]; | 218 | {uplevel remote_expect host $gtimeout $notransfer $expcode} string]; |
... | @@ -236,6 +237,74 @@ proc mu_expect { args } { | ... | @@ -236,6 +237,74 @@ proc mu_expect { args } { |
236 | } | 237 | } |
237 | } | 238 | } |
238 | 239 | ||
240 | proc mu_expect_list {args} { | ||
241 | set tmt [lindex $args 0] | ||
242 | set pattern [lindex $args 1] | ||
243 | |||
244 | set result 0 | ||
245 | for {set i 0} {$i < [llength $pattern]} {incr i} { | ||
246 | set regexp 0 | ||
247 | switch -regexp -- "[lindex ${pattern} $i]" { | ||
248 | ^-re.*$ { set regexp 1; incr i } | ||
249 | ^-- { incr i } | ||
250 | } | ||
251 | |||
252 | regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat | ||
253 | verbose "i=$i, pat=$pat" 2 | ||
254 | |||
255 | if {$regexp} { | ||
256 | verbose "REGEX for $pat / [llength $pat] " 3 | ||
257 | mu_expect $tmt { | ||
258 | -re $pat { } | ||
259 | default { | ||
260 | set result 1 | ||
261 | break | ||
262 | } | ||
263 | timeout { | ||
264 | set result -2 | ||
265 | break | ||
266 | } | ||
267 | eof { | ||
268 | set result -3 | ||
269 | break | ||
270 | } | ||
271 | } | ||
272 | } else { | ||
273 | mu_expect $tmt { | ||
274 | -ex "$pat" { | ||
275 | if { $expect_out(buffer) != $expect_out(0,string) } { | ||
276 | verbose "Got \"$expect_out(buffer)\"" 2 | ||
277 | verbose "instead of expected \"$pat\\r\\n\"" 2 | ||
278 | set result 1 | ||
279 | break | ||
280 | } | ||
281 | } | ||
282 | default { | ||
283 | set result 1 | ||
284 | break | ||
285 | } | ||
286 | timeout { | ||
287 | set result -2 | ||
288 | break | ||
289 | } | ||
290 | eof { | ||
291 | set result -3 | ||
292 | break | ||
293 | } | ||
294 | } | ||
295 | } | ||
296 | if {$result == 0} { | ||
297 | mu_expect $tmt { | ||
298 | -re "\[ \t]*\r\n" { } | ||
299 | default { set result 1 } | ||
300 | timeout { set result -2 } | ||
301 | eof { set result -3 } | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | return $result | ||
306 | } | ||
307 | |||
239 | # mu_test COMMAND PATTERN | 308 | # mu_test COMMAND PATTERN |
240 | # COMMAND - Command to send to mail | 309 | # COMMAND - Command to send to mail |
241 | # PATTERN - A list of strings to expect in return | 310 | # PATTERN - A list of strings to expect in return |
... | @@ -290,7 +359,7 @@ proc mu_test { args } { | ... | @@ -290,7 +359,7 @@ proc mu_test { args } { |
290 | set regexp 0 | 359 | set regexp 0 |
291 | switch -regexp -- "[lindex ${pattern} $i]" { | 360 | switch -regexp -- "[lindex ${pattern} $i]" { |
292 | ^-re.*$ { set regexp 1; incr i } | 361 | ^-re.*$ { set regexp 1; incr i } |
293 | ^-- { incr i } | 362 | ^-- { incr i } |
294 | } | 363 | } |
295 | 364 | ||
296 | regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat | 365 | regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat |
... | @@ -299,7 +368,7 @@ proc mu_test { args } { | ... | @@ -299,7 +368,7 @@ proc mu_test { args } { |
299 | if {$regexp} { | 368 | if {$regexp} { |
300 | verbose "REGEX for $pat / [llength $pat] " 3 | 369 | verbose "REGEX for $pat / [llength $pat] " 3 |
301 | mu_expect $tmt { | 370 | mu_expect $tmt { |
302 | -re $pat { } | 371 | -re "$pat\[ \r\t\]*\r\n" { } |
303 | default { | 372 | default { |
304 | set result 1 | 373 | set result 1 |
305 | break | 374 | break |
... | @@ -336,15 +405,15 @@ proc mu_test { args } { | ... | @@ -336,15 +405,15 @@ proc mu_test { args } { |
336 | break | 405 | break |
337 | } | 406 | } |
338 | } | 407 | } |
408 | if {$result == 0} { | ||
409 | mu_expect $tmt { | ||
410 | -re "\[ \t]*\r\n" { } | ||
411 | default { set result 1 } | ||
412 | timeout { set result -2 } | ||
413 | eof { set result -3 } | ||
414 | } | ||
415 | } | ||
339 | } | 416 | } |
340 | if {$result == 0} { | ||
341 | mu_expect $tmt { | ||
342 | -re "\[ \t]*\r\n" { } | ||
343 | default { set result 1 } | ||
344 | timeout { set result -2 } | ||
345 | eof { set result -3 } | ||
346 | } | ||
347 | } | ||
348 | } | 417 | } |
349 | return $result | 418 | return $result |
350 | } | 419 | } | ... | ... |
-
Please register or sign in to post a comment