1 # These tests are design especially for the vfork() implementation
2 # of exec where sh -c must be used and thus we must take extra care
3 # in quoting arguments to exec.
5 source [file dirname [info script]]/testing.tcl
8 foreach i {pipe signal wait} {
9 testConstraint $i [expr {[info commands $i] ne ""}]
11 # Some Windows platforms (e.g. AppVeyor) produce ENOSPC rather than killing
12 # the child with SIGPIPE). So turn off this test for that platform
13 if {[info exists env(MSYSTEM)] && $env(MSYSTEM) eq "MINGW32"} {
14 testConstraint nomingw32 0
16 testConstraint nomingw32 1
23 array set saveenv [array get env]
25 test exec2-1.1 "Quoting - Result" {
26 exec echo ${d}double quoted${d} ${s}single quoted${s} ${b}backslash quoted${b}
27 } "\"double\ quoted\"\ 'single quoted'\ \\backslash\ quoted\\"
29 test exec2-1.2 "Quoting - Word Grouping" {
30 string trim [exec echo ${d}double quoted${d} ${s}single quoted${s} ${b}backslash quoted${b} | wc -w]
33 test exec2-2.1 "Add to exec environment" {
34 set env(TESTENV) "the value"
35 exec printenv | sed -n -e /^TESTENV=/p
38 test exec2-2.2 "Remove from exec environment" {
39 set env(TESTENV2) "new value"
41 exec printenv | sed -n -e /^TESTENV=/p
45 test exec2-2.3 "Remove all exec environment" {
47 exec printenv | sed -n -e /^TESTENV2=/p
50 test exec2-2.4 "Remove all env var" {
52 exec printenv | sed -n -e /^TESTENV2=/p
55 array set env [array get saveenv]
57 test exec2-3.1 "close pipeline return value" {
59 set rc [catch {close $f} msg opts]
60 lassign [dict get $opts -errorcode] status pid exitcode
61 list $rc $msg $status $exitcode
62 } {1 {child process exited abnormally} CHILDSTATUS 1}
64 test exec2-3.2 "close pipeline return value" -constraints {pipe nomingw32} -body {
65 # Create a pipe and immediately close the read end
68 # Write more than 64KB which is maximum size of the pipe buffers
69 # on all systems we have seen
70 set bigstring [string repeat a 100000]
71 set f [open [list |cat << $bigstring >$@w]]
72 set rc [catch {close $f} msg opts]
73 lassign [dict get $opts -errorcode] status pid exitcode
74 list $rc $msg $status $exitcode
75 } -match glob -result {1 {child killed*} CHILDKILLED SIGPIPE}
77 test exec2-3.3 "close pipeline with SIGPIPE blocked" -constraints {pipe signal nomingw32} -body {
78 # Create a pipe and immediately close the read end
82 # Write more than 64KB which is maximum size of the pipe buffers
83 # on all systems we have seen
84 set bigstring [string repeat a 100000]
85 set f [open [list |cat << $bigstring >$@w 2>/dev/null]]
86 set rc [catch {close $f} msg opts]
87 lassign [dict get $opts -errorcode] status pid exitcode
88 list $rc $msg $status $exitcode
89 } -match glob -result {1 {child process exited*} CHILDSTATUS 1} -cleanup {
90 signal default SIGPIPE
93 test exec2-3.4 "wait for background task" -constraints wait -body {
94 set pid [exec sleep 0.1 &]
95 lassign [wait $pid] status newpid exitcode
96 if {$pid != $newpid} {
97 error "Got wrong pid from wait"
99 list $status $exitcode
101 } -result {CHILDSTATUS 0}