Commit 3a539644 3a5396445e68af006667f96b89a529c914d2028d by Sergey Poznyakoff

(mu_expect_list): New procedure

1 parent dd4127fe
......@@ -211,7 +211,8 @@ proc mu_expect { args } {
}
}
verbose "RUNNING remote_expect host $gtimeout $notransfer $expcode" 2
verbose "EXPCODE is $expcode" 4
verbose "RUNNING remote_expect host $gtimeout $notransfer" 2
set code [catch \
{uplevel remote_expect host $gtimeout $notransfer $expcode} string];
......@@ -236,6 +237,74 @@ proc mu_expect { args } {
}
}
proc mu_expect_list {args} {
set tmt [lindex $args 0]
set pattern [lindex $args 1]
set result 0
for {set i 0} {$i < [llength $pattern]} {incr i} {
set regexp 0
switch -regexp -- "[lindex ${pattern} $i]" {
^-re.*$ { set regexp 1; incr i }
^-- { incr i }
}
regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat
verbose "i=$i, pat=$pat" 2
if {$regexp} {
verbose "REGEX for $pat / [llength $pat] " 3
mu_expect $tmt {
-re $pat { }
default {
set result 1
break
}
timeout {
set result -2
break
}
eof {
set result -3
break
}
}
} else {
mu_expect $tmt {
-ex "$pat" {
if { $expect_out(buffer) != $expect_out(0,string) } {
verbose "Got \"$expect_out(buffer)\"" 2
verbose "instead of expected \"$pat\\r\\n\"" 2
set result 1
break
}
}
default {
set result 1
break
}
timeout {
set result -2
break
}
eof {
set result -3
break
}
}
}
if {$result == 0} {
mu_expect $tmt {
-re "\[ \t]*\r\n" { }
default { set result 1 }
timeout { set result -2 }
eof { set result -3 }
}
}
}
return $result
}
# mu_test COMMAND PATTERN
# COMMAND - Command to send to mail
# PATTERN - A list of strings to expect in return
......@@ -299,7 +368,7 @@ proc mu_test { args } {
if {$regexp} {
verbose "REGEX for $pat / [llength $pat] " 3
mu_expect $tmt {
-re $pat { }
-re "$pat\[ \r\t\]*\r\n" { }
default {
set result 1
break
......@@ -336,7 +405,6 @@ proc mu_test { args } {
break
}
}
}
if {$result == 0} {
mu_expect $tmt {
-re "\[ \t]*\r\n" { }
......@@ -346,6 +414,7 @@ proc mu_test { args } {
}
}
}
}
return $result
}
......