(testsuite) Added `stdout' to assert_bash_exec()
Added support to assert_bash_exec() to retrieve bash output within tcl/expect.
This commit is contained in:
parent
fc3f65e6dd
commit
fcf2bf91c9
@ -13,14 +13,26 @@ package require textutil::string
|
|||||||
# checked; specify `title' to adorn the error message.
|
# checked; specify `title' to adorn the error message.
|
||||||
# @param string $title (optional) Command title. If empty, `cmd' is used.
|
# @param string $title (optional) Command title. If empty, `cmd' is used.
|
||||||
# @param string $prompt (optional) Bash prompt. Default is "/@"
|
# @param string $prompt (optional) Bash prompt. Default is "/@"
|
||||||
proc assert_bash_exec {{aCmd ""} {title ""} {prompt /@}} {
|
# @param string $stdout (optional) Reference to variable to hold stdout.
|
||||||
|
proc assert_bash_exec {{aCmd ""} {title ""} {prompt /@} {stdout ''}} {
|
||||||
|
upvar $stdout results
|
||||||
if {[string length $aCmd] != 0} {
|
if {[string length $aCmd] != 0} {
|
||||||
send "$aCmd\r"
|
send "$aCmd\r"
|
||||||
expect -ex "$aCmd\r\n"
|
expect -ex "$aCmd\r\n"
|
||||||
}; # if
|
}; # if
|
||||||
if {[string length $title] == 0} {set title $aCmd}
|
if {[string length $title] == 0} {set title $aCmd}
|
||||||
expect -ex $prompt
|
expect -ex $prompt
|
||||||
set out $expect_out(buffer); # Catch (non-expected) output
|
set results $expect_out(buffer); # Catch output
|
||||||
|
# Remove $prompt suffix from output
|
||||||
|
set results [
|
||||||
|
string range $results 0 [
|
||||||
|
expr [string length $results] - [string length "/@"] - 1
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set cmd "echo $?"
|
set cmd "echo $?"
|
||||||
send "$cmd\r"
|
send "$cmd\r"
|
||||||
expect {
|
expect {
|
||||||
@ -222,7 +234,7 @@ proc assert_env_unmodified {{sed ""} {file ""} {diff ""}} {
|
|||||||
# Prepare sed script
|
# Prepare sed script
|
||||||
|
|
||||||
# Escape special bash characters ("\)
|
# Escape special bash characters ("\)
|
||||||
regsub -all {([\"\\])} $sed {\\\1} sed
|
regsub -all {([\"\\])} $sed {\\\1} sed; #"# (fix Vim syntax highlighting)
|
||||||
# Escape newlines
|
# Escape newlines
|
||||||
regsub -all {\n} [string trim $sed] "\r\n" sed
|
regsub -all {\n} [string trim $sed] "\r\n" sed
|
||||||
|
|
||||||
@ -468,4 +480,4 @@ proc wd {} {
|
|||||||
global TESTDIR
|
global TESTDIR
|
||||||
# Remove `$TESTDIR' prefix from current working directory
|
# Remove `$TESTDIR' prefix from current working directory
|
||||||
set wd [string replace [pwd] 0 [expr [string length $TESTDIR] - 1]]/
|
set wd [string replace [pwd] 0 [expr [string length $TESTDIR] - 1]]/
|
||||||
}
|
}; # wd()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user