Commit 3a539644 3a5396445e68af006667f96b89a529c914d2028d by Sergey Poznyakoff

(mu_expect_list): New procedure

1 parent dd4127fe
...@@ -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
...@@ -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,7 +405,6 @@ proc mu_test { args } { ...@@ -336,7 +405,6 @@ proc mu_test { args } {
336 break 405 break
337 } 406 }
338 } 407 }
339 }
340 if {$result == 0} { 408 if {$result == 0} {
341 mu_expect $tmt { 409 mu_expect $tmt {
342 -re "\[ \t]*\r\n" { } 410 -re "\[ \t]*\r\n" { }
...@@ -346,6 +414,7 @@ proc mu_test { args } { ...@@ -346,6 +414,7 @@ proc mu_test { args } {
346 } 414 }
347 } 415 }
348 } 416 }
417 }
349 return $result 418 return $result
350 } 419 }
351 420
......