diff options
author | Steve Bennett <steveb@workware.net.au> | 2016-09-14 14:15:47 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-10-17 07:39:39 +1000 |
commit | 1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5 (patch) | |
tree | 78c2baa61687fa296dc418cd1b978b3e046813f6 /tests | |
parent | 4be55f10c4d2071f493b9a1b60197c5e20f3203d (diff) | |
download | jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.zip jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.gz jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.bz2 |
signal, exec, wait, pid: improvements, especially to exec
- fix popen [open "|pipeline ..."] to return meaningful status in close
(but note that stderr is not captured)
- popen pipelines can now be used as the target of exec redirection
- overally improvements to exec on windows. Now crt file descriptors
are used throughout
- add support for [pid], [wait] and popen on windows
- os.wait is now wait, and integrates with [exec ... &] to be able
to wait for running background tasks
- [socket pipe] is now also [pipe] and is supported on windows
- [file tempfile] is supported on windows
- move duplicated code between jim-aio.c and jim-exec.c to jimiocompat.c
- Fix [exec] on windows to match unix semantics wrt sharing the parent stream
unless redirected rather than using /dev/null
- On windows redirect to or from /dev/null is automatically converted to NUL:
- If signal support is disabled, implement a minimal Jim_SignalId() for exec and wait
- aio now supports getfd, to return the underlying file descriptor.
This is used by exec to support redirection, and allows popen channels
to support exec redirection.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/exec.test | 32 | ||||
-rw-r--r-- | tests/exec2.test | 26 | ||||
-rw-r--r-- | tests/pid.test | 6 |
3 files changed, 55 insertions, 9 deletions
diff --git a/tests/exec.test b/tests/exec.test index 76a1b2d..0eb218a 100644 --- a/tests/exec.test +++ b/tests/exec.test @@ -17,26 +17,23 @@ source [file dirname [info script]]/testing.tcl needs cmd exec needs cmd flush -needs cmd after eventloop testConstraint unix [expr {$tcl_platform(platform) eq {unix}}] # Sleep which supports fractions of a second if {[info commands sleep] eq {}} { proc sleep {n} { - after [expr {int($n * 1000)}] + exec {*}$::sleepx $n } } set f [open sleepx w] -puts $f "#![info nameofexecutable]" puts $f { - set seconds [lindex $argv 0] - after [expr {int($seconds * 1000)}] + sleep "$@" } close $f #catch {exec chmod +x sleepx} -set sleepx [list [info nameofexecutable] sleepx] +set sleepx [list sh sleepx] # Basic operations. @@ -416,6 +413,29 @@ test exec-16.1 {flush output before exec} -body { Second line Third line} +test exec-17.1 {redirecting from command pipeline} -setup { + makeFile "abc\nghi\njkl" gorp.file +} -body { + set f [open "|cat gorp.file | wc -l" r] + set result [lindex [exec cat <@$f] 0] + close $f + set result +} -cleanup { + file delete gorp.file +} -result {3} + +test exec-17.2 {redirecting to command pipeline} -setup { + makeFile "abc\nghi\njkl" gorp.file +} -body { + set f [open "|wc -l >gorp2.file" w] + exec cat gorp.file >@$f + flush $f + close $f + lindex [exec cat gorp2.file] 0 +} -cleanup { + file delete gorp.file gorp2.file +} -result {3} + file delete sleepx testreport diff --git a/tests/exec2.test b/tests/exec2.test index e43bba0..91108da 100644 --- a/tests/exec2.test +++ b/tests/exec2.test @@ -44,4 +44,30 @@ test exec2-2.4 "Remove all env var" { array set env [array get saveenv] +test exec2-3.1 "close pipeline return value" { + set f [open |false] + set rc [catch {close $f} msg opts] + lassign [dict get $opts -errorcode] status pid exitcode + list $rc $msg $status $exitcode +} {1 {child process exited abnormally} CHILDSTATUS 1} + +test exec2-3.2 "close pipeline return value" -body { + set f [open "|echo abc | grep def | wc" ] + set rc [catch {close $f} msg opts] + lassign [dict get $opts -errorcode] status pid exitcode + list $rc $msg $status $exitcode +} -match glob -result {1 {child killed*} CHILDKILLED SIGPIPE} + + +test exec2-3.4 "wait for background task" { + set pid [exec sleep 0.1 &] + lassign [wait $pid] status newpid exitcode + if {$pid != $newpid} { + error "Got wrong pid from wait" + } else { + list $status $exitcode + } +} {CHILDSTATUS 0} + + testreport diff --git a/tests/pid.test b/tests/pid.test index 6a534a5..56ffcf8 100644 --- a/tests/pid.test +++ b/tests/pid.test @@ -19,7 +19,7 @@ needs cmd pid posix needs cmd exec catch {package require regexp} testConstraint regexp [expr {[info commands regexp] ne {}}] -testConstraint socket [expr {[info commands socket] ne {}}] +testConstraint pipe [expr {[info commands pipe] ne {}}] testConstraint getpid [expr {[catch pid] == 0}] # This is a proxy for tcl || tclcompat testConstraint pidchan [expr {[info commands fconfigure] ne {}}] @@ -29,7 +29,7 @@ file delete test1 test pid-1.1 {pid command} {regexp getpid} { regexp {(^[0-9]+$)|(^0x[0-9a-fA-F]+$)} [pid] } 1 -test pid-1.2 {pid command} {regexp socket pidchan} { +test pid-1.2 {pid command} {regexp pipe pidchan} { set f [open {| echo foo | cat >test1} w] set pids [pid $f] close $f @@ -38,7 +38,7 @@ test pid-1.2 {pid command} {regexp socket pidchan} { [regexp {^[0-9]+$} [lindex $pids 1]] \ [expr {[lindex $pids 0] == [lindex $pids 1]}] } {2 1 1 0} -test pid-1.3 {pid command} {socket pidchan} { +test pid-1.3 {pid command} {pipe pidchan} { set f [open test1 w] set pids [pid $f] close $f |