diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-16 18:45:38 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-16 18:45:38 (GMT) |
commit | 21ad94030ac5757eefe70e335cf8dc57e7b06338 (patch) | |
tree | 42ed4343209e8ad6a84af3f060a4c159f65429c6 /tests/exec.test | |
parent | 7d5b0dc33c13fa1026a537ab90b201ed1ce43666 (diff) | |
parent | e10b32c27a1f48c45ea90e6af530c75fa3fff7a2 (diff) | |
download | tcl-21ad94030ac5757eefe70e335cf8dc57e7b06338.zip tcl-21ad94030ac5757eefe70e335cf8dc57e7b06338.tar.gz tcl-21ad94030ac5757eefe70e335cf8dc57e7b06338.tar.bz2 |
Add 32-bit Windows builds, both with MSVC and GCC, to Travis.
Backport various test-suite changes fro 8.6 to 8.5, mainly "knownBug" markers and comments
Diffstat (limited to 'tests/exec.test')
-rw-r--r-- | tests/exec.test | 245 |
1 files changed, 130 insertions, 115 deletions
diff --git a/tests/exec.test b/tests/exec.test index 7bb8579..a180906 100644 --- a/tests/exec.test +++ b/tests/exec.test @@ -1,15 +1,15 @@ # Commands covered: exec # -# This file contains a collection of tests for one or more of the Tcl -# built-in commands. Sourcing this file into Tcl runs the tests and -# generates output for errors. No output means no errors were found. +# This file contains a collection of tests for one or more of the Tcl built-in +# commands. Sourcing this file into Tcl runs the tests and generates output +# for errors. No output means no errors were found. # # Copyright (c) 1991-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. # Copyright (c) 1998-1999 by Scriptics Corporation. # -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# See the file "license.terms" for information on usage and redistribution of +# this file, and for a DISCLAIMER OF ALL WARRANTIES. package require tcltest 2 namespace import -force ::tcltest::* @@ -18,6 +18,8 @@ namespace import -force ::tcltest::* # Skip them if exec is not defined. testConstraint exec [llength [info commands exec]] unset -nocomplain path + +# Utilities that are like bourne shell stalwarts, but cross-platform. set path(echo) [makeFile { puts -nonewline [lindex $argv 0] foreach str [lrange $argv 1 end] { @@ -26,17 +28,16 @@ set path(echo) [makeFile { puts {} exit } echo] - set path(echo2) [makeFile { puts stdout [join $argv] puts stderr [lindex $argv 1] exit } echo2] - set path(cat) [makeFile { if {$argv == {}} { set argv - } + fconfigure stdout -translation binary foreach name $argv { if {$name == "-"} { set f stdin @@ -44,6 +45,7 @@ set path(cat) [makeFile { puts stderr $f continue } + fconfigure $f -translation binary while {[eof $f] == 0} { puts -nonewline [read $f] } @@ -53,7 +55,6 @@ set path(cat) [makeFile { } exit } cat] - set path(wc) [makeFile { set data [read stdin] set lines [regsub -all "\n" $data {} dummy] @@ -62,7 +63,6 @@ set path(wc) [makeFile { puts [format "%8.d%8.d%8.d" $lines $words $chars] exit } wc] - set path(sh) [makeFile { if {[lindex $argv 0] != "-c"} { error "sh: unexpected arguments $argv" @@ -71,7 +71,7 @@ set path(sh) [makeFile { lappend cmd ";" set newcmd {} - + foreach arg $cmd { if {$arg == ";"} { eval exec >@stdout 2>@stderr [list [info nameofexecutable]] $newcmd @@ -93,7 +93,7 @@ set path(sh2) [makeFile { lappend cmd ";" set newcmd {} - + foreach arg $cmd { if {$arg == ";"} { eval exec -ignorestderr >@stdout [list [info nameofexecutable]] $newcmd @@ -104,16 +104,22 @@ set path(sh2) [makeFile { } exit } sh2] - set path(sleep) [makeFile { after [expr $argv*1000] exit } sleep] - set path(exit) [makeFile { exit $argv } exit] +proc readfile filename { + set f [open $filename] + set d [read $f] + close $f + return [string trimright $d \n] +} + +# ---------------------------------------------------------------------- # Basic operations. test exec-1.1 {basic exec operation} {exec} { @@ -150,13 +156,24 @@ test exec-2.4 {redirecting input from immediate source} {exec stdio} { test exec-2.5 {redirecting input from immediate source} {exec} { exec [interpreter] $path(cat) "<<Joined to arrows" } {Joined to arrows} -test exec-2.6 {redirecting input from immediate source, with UTF} {exec} { - # If this fails, it may give back: - # "\uC3\uA9\uC3\uA0\uC3\uBC\uC3\uB1" - # If it does, this means that the UTF -> external conversion did not - # occur before writing out the temp file. - exec [interpreter] $path(cat) << "\uE9\uE0\uFC\uF1" -} "\uE9\uE0\uFC\uF1" +test exec-2.6 {redirecting input from immediate source, with UTF} -setup { + set sysenc [encoding system] + encoding system iso8859-1 + proc quotenonascii s { + regsub -all {\[|\\|\]} $s {\\&} s + regsub -all "\[\u007f-\uffff\]" $s \ + {[apply {c {format {\u%04x} [scan $c %c]}} &]} s + return [subst -novariables $s] + } +} -constraints {exec} -body { + # If this fails, it may give back: "\uC3\uA9\uC3\uA0\uC3\uBC\uC3\uB1" + # If it does, this means that the UTF -> external conversion did not occur + # before writing out the temp file. + quotenonascii [exec [interpreter] $path(cat) << "\uE9\uE0\uFC\uF1"] +} -cleanup { + encoding system $sysenc + rename quotenonascii {} +} -result {\u00e9\u00e0\u00fc\u00f1} # I/O redirection: output to file. @@ -205,37 +222,37 @@ test exec-3.7 {redirecting output to file} {exec} { file delete $path(gorp.file) test exec-4.1 {redirecting output and stderr to file} {exec} { - exec [interpreter] "$path(echo)" "test output" >& $path(gorp.file) - exec [interpreter] "$path(cat)" "$path(gorp.file)" + exec [interpreter] $path(echo) "test output" >& $path(gorp.file) + exec [interpreter] $path(cat) $path(gorp.file) } "test output" test exec-4.2 {redirecting output and stderr to file} {exec} { - list [exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" >&$path(gorp.file)] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file)"] + list [exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" >&$path(gorp.file)] \ + [exec [interpreter] $path(cat) $path(gorp.file)] } {{} {foo bar}} test exec-4.3 {redirecting output and stderr to file} {exec} { exec [interpreter] $path(echo) "first line" > $path(gorp.file) - list [exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" >>&$path(gorp.file)] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file)"] + list [exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" >>&$path(gorp.file)] \ + [exec [interpreter] $path(cat) $path(gorp.file)] } "{} {first line\nfoo bar}" test exec-4.4 {redirecting output and stderr to file} {exec} { - set f [open "$path(gorp.file)" w] + set f [open $path(gorp.file) w] puts $f "Line 1" flush $f - exec [interpreter] "$path(echo)" "More text" >&@ $f - exec [interpreter] "$path(echo)" >&@$f "Even more" + exec [interpreter] $path(echo) "More text" >&@ $f + exec [interpreter] $path(echo) >&@$f "Even more" puts $f "Line 3" close $f - exec [interpreter] "$path(cat)" "$path(gorp.file)" + exec [interpreter] $path(cat) $path(gorp.file) } "Line 1\nMore text\nEven more\nLine 3" test exec-4.5 {redirecting output and stderr to file} {exec} { - set f [open "$path(gorp.file)" w] + set f [open $path(gorp.file) w] puts $f "Line 1" flush $f - exec >&@ $f [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" - exec >&@$f [interpreter] "$path(sh)" -c "\"$path(echo)\" xyzzy 1>&2" + exec >&@ $f [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" + exec >&@$f [interpreter] $path(sh) -c "\"$path(echo)\" xyzzy 1>&2" puts $f "Line 3" close $f - exec [interpreter] "$path(cat)" "$path(gorp.file)" + exec [interpreter] $path(cat) $path(gorp.file) } "Line 1\nfoo bar\nxyzzy\nLine 3" # I/O redirection: input from file. @@ -258,30 +275,30 @@ test exec-5.4 {redirecting input from file} {exec stdio} { test exec-5.5 {redirecting input from file} {exec} { exec [interpreter] $path(cat) <$path(gorp.file) } {Just a few thoughts} -test exec-5.6 {redirecting input from file} {exec} { +test exec-5.6 {redirecting input from file} -constraints {exec} -body { set f [open $path(gorp.file) r] - set result [exec [interpreter] $path(cat) <@ $f] + exec [interpreter] $path(cat) <@ $f +} -cleanup { close $f - set result -} {Just a few thoughts} -test exec-5.7 {redirecting input from file} {exec} { +} -result {Just a few thoughts} +test exec-5.7 {redirecting input from file} -constraints {exec} -body { set f [open $path(gorp.file) r] - set result [exec <@$f [interpreter] $path(cat)] + exec <@$f [interpreter] $path(cat) +} -cleanup { close $f - set result -} {Just a few thoughts} +} -result {Just a few thoughts} # I/O redirection: standard error through a pipeline. test exec-6.1 {redirecting stderr through a pipeline} {exec stdio} { - exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar" |& [interpreter] "$path(cat)" + exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar" |& [interpreter] $path(cat) } "foo bar" test exec-6.2 {redirecting stderr through a pipeline} {exec stdio} { - exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" |& [interpreter] "$path(cat)" + exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" |& [interpreter] $path(cat) } "foo bar" test exec-6.3 {redirecting stderr through a pipeline} {exec stdio} { - exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" \ - |& [interpreter] "$path(sh)" -c "\"$path(echo)\" second msg 1>&2 ; \"$path(cat)\"" |& [interpreter] "$path(cat)" + exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" \ + |& [interpreter] $path(sh) -c "\"$path(echo)\" second msg 1>&2 ; \"$path(cat)\"" |& [interpreter] $path(cat) } "second msg\nfoo bar" # I/O redirection: combinations. @@ -297,7 +314,6 @@ test exec-7.2 {multiple I/O redirections} {exec} { } {command input} # Long input to command and output from command. - set a "0123456789 xxxxxxxxx abcdefghi ABCDEFGHIJK\n" set a [concat $a $a $a $a] set a [concat $a $a $a $a] @@ -306,9 +322,7 @@ set a [concat $a $a $a $a] test exec-8.1 {long input and output} {exec} { exec [interpreter] $path(cat) << $a } $a - # More than 20 arguments to exec. - test exec-8.2 {long input and output} {exec} { exec [interpreter] $path(echo) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23} @@ -322,40 +336,40 @@ test exec-9.1 {commands returning errors} {exec} { test exec-9.2 {commands returning errors} {exec} { string tolower [list [catch {exec [interpreter] echo foo | foo123} msg] $msg $errorCode] } {1 {couldn't execute "foo123": no such file or directory} {posix enoent {no such file or directory}}} -test exec-9.3 {commands returning errors} {exec stdio} { - list [catch {exec [interpreter] $path(sleep) 1 | [interpreter] $path(exit) 43 | [interpreter] $path(sleep) 1} msg] $msg -} {1 {child process exited abnormally}} -test exec-9.4 {commands returning errors} {exec stdio} { - list [catch {exec [interpreter] $path(exit) 43 | [interpreter] $path(echo) "foo bar"} msg] $msg -} {1 {foo bar -child process exited abnormally}} -test exec-9.5 {commands returning errors} {exec stdio} { - list [catch {exec gorp456 | [interpreter] echo a b c} msg] [string tolower $msg] -} {1 {couldn't execute "gorp456": no such file or directory}} -test exec-9.6 {commands returning errors} {exec} { - list [catch {exec [interpreter] "$path(sh)" -c "\"$path(echo)\" error msg 1>&2"} msg] $msg -} {1 {error msg}} -test exec-9.7 {commands returning errors} {exec stdio} { - list [catch {exec [interpreter] "$path(sh)" -c "\"$path(echo)\" error msg 1>&2 ; \"$path(sleep)\" 1" \ - | [interpreter] "$path(sh)" -c "\"$path(echo)\" error msg 1>&2 ; \"$path(sleep)\" 1"} msg] $msg -} {1 {error msg -error msg}} - +test exec-9.3 {commands returning errors} -constraints {exec stdio} -body { + exec [interpreter] $path(sleep) 1 | [interpreter] $path(exit) 43 | [interpreter] $path(sleep) 1 +} -returnCodes error -result {child process exited abnormally} +test exec-9.4 {commands returning errors} -constraints {exec stdio} -body { + exec [interpreter] $path(exit) 43 | [interpreter] $path(echo) "foo bar" +} -returnCodes error -result {foo bar +child process exited abnormally} +test exec-9.5 {commands returning errors} -constraints {exec stdio} -body { + exec gorp456 | [interpreter] echo a b c +} -returnCodes error -result {couldn't execute "gorp456": no such file or directory} +test exec-9.6 {commands returning errors} -constraints {exec} -body { + exec [interpreter] $path(sh) -c "\"$path(echo)\" error msg 1>&2" +} -returnCodes error -result {error msg} +test exec-9.7 {commands returning errors} -constraints {exec stdio nonPortable} -body { + # This test can fail easily on multiprocessor machines + exec [interpreter] $path(sh) -c "\"$path(echo)\" error msg 1>&2 ; \"$path(sleep)\" 1" \ + | [interpreter] $path(sh) -c "\"$path(echo)\" error msg 1>&2 ; \"$path(sleep)\" 1" +} -returnCodes error -result {error msg +error msg} set path(err) [makeFile {} err] - -test exec-9.8 {commands returning errors} {exec} { +test exec-9.8 {commands returning errors} -constraints {exec} -setup { set f [open $path(err) w] puts $f { puts stdout out puts stderr err } close $f - list [catch {exec [interpreter] $path(err)} msg] $msg -} {1 {out -err}} +} -body { + exec [interpreter] $path(err) +} -returnCodes error -result {out +err} -# Errors in executing the Tcl command, as opposed to errors in the -# processes that are invoked. +# Errors in executing the Tcl command, as opposed to errors in the processes +# that are invoked. test exec-10.1 {errors in exec invocation} {exec} { list [catch {exec} msg] $msg @@ -432,12 +446,12 @@ test exec-10.22 {errors in exec invocation} \ # Commands in background. test exec-11.1 {commands in background} {exec} { - set x [lindex [time {exec [interpreter] $path(sleep) 2 &}] 0] - expr $x<1000000 + set time [time {exec [interpreter] $path(sleep) 2 &}] + expr {[lindex $time 0] < 1000000} } 1 -test exec-11.2 {commands in background} {exec} { - list [catch {exec [interpreter] $path(echo) a &b} msg] $msg -} {0 {a &b}} +test exec-11.2 {commands in background} -constraints {exec} -body { + exec [interpreter] $path(echo) a &b +} -result {a &b} test exec-11.3 {commands in background} {exec} { llength [exec [interpreter] $path(sleep) 1 &] } 1 @@ -448,35 +462,33 @@ test exec-11.5 {commands in background} {exec} { set f [open $path(gorp.file) w] puts $f [list catch [list exec [info nameofexecutable] $path(echo) foo &]] close $f - string compare "foo" [exec [interpreter] $path(gorp.file)] -} 0 + exec [interpreter] $path(gorp.file) +} foo -# Make sure that background commands are properly reaped when -# they eventually die. +# Make sure that background commands are properly reaped when they +# eventually die. -if {[testConstraint exec]} { - exec [interpreter] $path(sleep) 3 +if {[testConstraint exec] && [testConstraint nonPortable]} { + after 1300 + exec [interpreter] $path(sleep) 1 } -test exec-12.1 {reaping background processes} \ - {exec unix nonPortable} { +test exec-12.1 {reaping background processes} {exec unix nonPortable} { for {set i 0} {$i < 20} {incr i} { exec echo foo > /dev/null & } - exec sleep 1 + after 1000 catch {exec ps | fgrep "echo foo" | fgrep -v fgrep | wc} msg lindex $msg 0 } 0 -test exec-12.2 {reaping background processes} \ - {exec unix nonPortable} { +test exec-12.2 {reaping background processes} {exec unix nonPortable} { exec sleep 2 | sleep 2 | sleep 2 & catch {exec ps | fgrep -i "sleep" | fgrep -i -v fgrep | wc} msg set x [lindex $msg 0] - exec sleep 3 + after 3000 catch {exec ps | fgrep -i "sleep" | fgrep -i -v fgrep | wc} msg list $x [lindex $msg 0] } {3 0} -test exec-12.3 {reaping background processes} \ - {exec unix nonPortable} { +test exec-12.3 {reaping background processes} {exec unix nonPortable} { exec sleep 1000 & exec sleep 1000 & set x [exec ps | fgrep "sleep" | fgrep -v fgrep] @@ -489,7 +501,6 @@ test exec-12.3 {reaping background processes} \ } catch {exec ps | fgrep "sleep" | fgrep -v fgrep | wc} msg set x [lindex $msg 0] - foreach i $pids { catch {exec kill -KILL $i} } @@ -541,7 +552,7 @@ test exec-13.5 {extended exit result codes: max value} { -result {1 {CHILDSTATUS {} 1073741823}} } -test exec-13.6 {extended exit result codes: signalled} { +test exec-13.6 {extended exit result codes: signalled} { -constraints {win} -setup { set tmp [makeFile {exit 0xC0000016} tmpfile.exec-13.6] @@ -578,37 +589,37 @@ test exec-14.5 {-ignorestderr switch} {exec} { # Redirecting standard error separately from standard output test exec-15.1 {standard error redirection} {exec} { - exec [interpreter] "$path(echo)" "First line" > "$path(gorp.file)" - list [exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" 2> "$path(gorp.file)"] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file)"] + exec [interpreter] $path(echo) "First line" > $path(gorp.file) + list [exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" 2> $path(gorp.file)] \ + [exec [interpreter] $path(cat) $path(gorp.file)] } {{} {foo bar}} test exec-15.2 {standard error redirection} {exec stdio} { - list [exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" \ - | [interpreter] "$path(echo)" biz baz >$path(gorp.file) 2> "$path(gorp.file2)"] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file)"] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file2)"] + list [exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" \ + | [interpreter] $path(echo) biz baz >$path(gorp.file) 2> $path(gorp.file2)] \ + [exec [interpreter] $path(cat) $path(gorp.file)] \ + [exec [interpreter] $path(cat) $path(gorp.file2)] } {{} {biz baz} {foo bar}} test exec-15.3 {standard error redirection} {exec stdio} { - list [exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" \ - | [interpreter] "$path(echo)" biz baz 2>$path(gorp.file) > "$path(gorp.file2)"] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file)"] \ - [exec [interpreter] "$path(cat)" "$path(gorp.file2)"] + list [exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" \ + | [interpreter] $path(echo) biz baz 2>$path(gorp.file) > $path(gorp.file2)] \ + [exec [interpreter] $path(cat) $path(gorp.file)] \ + [exec [interpreter] $path(cat) $path(gorp.file2)] } {{} {foo bar} {biz baz}} test exec-15.4 {standard error redirection} {exec} { - set f [open "$path(gorp.file)" w] + set f [open $path(gorp.file) w] puts $f "Line 1" flush $f - exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" 2>@ $f + exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" 2>@ $f puts $f "Line 3" close $f - exec [interpreter] "$path(cat)" "$path(gorp.file)" + readfile $path(gorp.file) } {Line 1 foo bar Line 3} test exec-15.5 {standard error redirection} {exec} { - exec [interpreter] "$path(echo)" "First line" > "$path(gorp.file)" - exec [interpreter] "$path(sh)" -c "\"$path(echo)\" foo bar 1>&2" 2>> "$path(gorp.file)" - exec [interpreter] "$path(cat)" "$path(gorp.file)" + exec [interpreter] $path(echo) "First line" > "$path(gorp.file)" + exec [interpreter] $path(sh) -c "\"$path(echo)\" foo bar 1>&2" 2>> "$path(gorp.file)" + readfile $path(gorp.file) } {First line foo bar} test exec-15.6 {standard error redirection} {exec stdio} { @@ -627,7 +638,7 @@ test exec-16.1 {flush output before exec} {exec} { exec [interpreter] $path(echo) "Second line" >@ $f puts $f "Third line" close $f - exec [interpreter] $path(cat) $path(gorp.file) + readfile $path(gorp.file) } {First line Second line Third line} @@ -637,7 +648,7 @@ test exec-16.2 {flush output before exec} {exec} { exec [interpreter] << {puts stderr {Second line}} >&@ $f > $path(gorp.file2) puts $f "Third line" close $f - exec [interpreter] $path(cat) $path(gorp.file) + readfile $path(gorp.file) } {First line Second line Third line} @@ -712,3 +723,7 @@ unset -nocomplain path ::tcltest::cleanupTests return + +# Local Variables: +# mode: tcl +# End: |