diff options
Diffstat (limited to 'tests/exec.test')
| -rw-r--r-- | tests/exec.test | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/exec.test b/tests/exec.test index 06d6bea..fc5f1fa 100644 --- a/tests/exec.test +++ b/tests/exec.test @@ -32,6 +32,8 @@ if {[testConstraint win] && ![info exists ::env(CI)] && testConstraint haveWinget 1 } +testConstraint testhandlecount [expr {[llength [info commands testhandlecount]] != 0}] + unset -nocomplain path # Utilities that are like Bourne shell stalwarts, but cross-platform. @@ -154,6 +156,12 @@ test exec-1.4 {long command lines} {exec} { exec [interpreter] $path(echo) $arg } $arg set arg {} +test exec-1.5 {pipelining - handle leaks} -constraints {exec stdio testhandlecount} -body { + set numHandles [testhandlecount] + set a [exec [interpreter] $path(echo) a b c d | [interpreter] $path(cat) | [interpreter] $path(wc)] + list [scan $a "%d %d %d" b c d] $b $c [expr {[testhandlecount] - $numHandles}] +} -result {3 1 4 0} + # I/O redirection: input from Tcl command. @@ -190,6 +198,13 @@ test exec-2.6 {redirecting input from immediate source, with UTF} -setup { encoding system $sysenc rename quotenonascii {} } -result {\xE9\xE0\xFC\xF1} +test exec-2.7 {handle count redirecting input from immediate source} -constraints { + exec stdio testhandlecount +} -body { + set numHandles [testhandlecount] + list [exec [interpreter] $path(cat) | [interpreter] $path(cat) << "Sample text"] \ + [expr {[testhandlecount] - $numHandles}] +} -result [list {Sample text} 0] # I/O redirection: output to file. @@ -232,6 +247,14 @@ test exec-3.7 {redirecting output to file} {exec} { close $f exec [interpreter] $path(cat) $path(gorp.file) } "Line 1\nMore text\nEven more\nLine 3" +test exec-3.8 {handle count redirecting output to file} -constraints { + exec stdio testhandlecount +} -body { + set numHandles [testhandlecount] + exec > $path(gorp.file) [interpreter] $path(echo) "Different simple words" | [interpreter] $path(cat) | [interpreter] $path(cat) + list [exec [interpreter] $path(cat) $path(gorp.file)] \ + [expr {[testhandlecount] - $numHandles}] +} -result [list "Different simple words" 0] # I/O redirection: output and stderr to file. @@ -303,6 +326,13 @@ test exec-5.7 {redirecting input from file} -constraints {exec} -body { } -cleanup { close $f } -result {Just a few thoughts} +test exec-5.8 {handle count redirecting input from file} -constraints { + exec stdio testhandlecount +} -body { + set numHandles [testhandlecount] + list [exec [interpreter] $path(cat) | [interpreter] $path(cat) < $path(gorp.file)] \ + [expr {[testhandlecount] - $numHandles}] +} -result [list {Just a few thoughts} 0] # I/O redirection: standard error through a pipeline. @@ -484,6 +514,15 @@ test exec-11.5 {commands in background} {exec} { close $f exec [interpreter] $path(gorp.file) } foo +test exec-11.6 {commands in background} -constraints { + exec stdio testhandlecount +} -body { + set numHandles [testhandlecount] + set n [llength [exec [interpreter] $path(sleep) 1 | [interpreter] $path(sleep) 1 | [interpreter] $path(sleep) 1 &]] + after 1100 + tcl::process::purge + list $n [expr {([testhandlecount] - $numHandles) <= 0}]; # Could be < 0 if prior processes were reaped +} -result {3 1} # Make sure that background commands are properly reaped when they # eventually die. |
