Debian Codegraph @

tests/winPipe.test

raw
1 #
2 # winPipe.test --
3 #
4 # This file contains a collection of tests for tclWinPipe.c
5 #
6 # Sourcing this file into Tcl runs the tests and generates output for errors.
7 # No output (except for one message) means no errors were found.
8 #
9 # Copyright (c) 1996 Sun Microsystems, Inc.
10 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 #
12 # See the file "license.terms" for information on usage and redistribution of
13 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
14
15 package require tcltest 2.5
16 namespace import -force ::tcltest::*
17 unset -nocomplain path
18
19 catch {
20 ::tcltest::loadTestedCommands
21 package require -exact Tcltest [info patchlevel]
22 set ::tcltestlib [lindex [package ifneeded Tcltest [info patchlevel]] 1]
23 }
24
25 set org_pwd [pwd]
26 set bindir [file join $org_pwd [file dirname [info nameofexecutable]]]
27 set cat32 [file join $bindir cat32.exe]
28
29 # several test-cases here expect current directory == [temporaryDirectory]:
30 cd [temporaryDirectory]
31
32 testConstraint exec [llength [info commands exec]]
33 testConstraint cat32 [file exists $cat32]
34 testConstraint AllocConsole [catch {puts console1 ""}]
35 testConstraint RealConsole [expr {![testConstraint AllocConsole]}]
36 testConstraint testexcept [llength [info commands testexcept]]
37 testConstraint slowTest 0
38
39
40 set big bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n
41 append big $big
42 append big $big
43 append big $big
44 append big $big
45 append big $big
46 append big $big
47
48 set path(little) [makeFile {} little]
49 set f [open $path(little) w]
50 puts -nonewline $f "little"
51 close $f
52
53 set path(big) [makeFile {} big]
54 set f [open $path(big) w]
55 puts -nonewline $f $big
56 close $f
57
58 proc contents {file} {
59 set f [open $file r]
60 set r [read $f]
61 close $f
62 set r
63 }
64
65 set path(more) [makeFile {
66 while {[eof stdin] == 0} {
67 puts -nonewline [read stdin]
68 }
69 } more]
70
71 set path(stdout) [makeFile {} stdout]
72 set path(stderr) [makeFile {} stderr]
73
74 test winpipe-1.1 {32 bit comprehensive tests: from little file} {win exec cat32} {
75 exec $cat32 < $path(little) > $path(stdout) 2> $path(stderr)
76 list [contents $path(stdout)] [contents $path(stderr)]
77 } {little stderr32}
78 test winpipe-1.2 {32 bit comprehensive tests: from big file} {win exec cat32} {
79 exec $cat32 < $path(big) > $path(stdout) 2> $path(stderr)
80 list [contents $path(stdout)] [contents $path(stderr)]
81 } "{$big} stderr32"
82 test winpipe-1.3 {32 bit comprehensive tests: a little from pipe} {win nt exec cat32} {
83 exec [interpreter] $path(more) < $path(little) | $cat32 > $path(stdout) 2> $path(stderr)
84 list [contents $path(stdout)] [contents $path(stderr)]
85 } {little stderr32}
86 test winpipe-1.4 {32 bit comprehensive tests: a lot from pipe} {win nt exec cat32} {
87 exec [interpreter] $path(more) < $path(big) | $cat32 > $path(stdout) 2> $path(stderr)
88 list [contents $path(stdout)] [contents $path(stderr)]
89 } "{$big} stderr32"
90 test winpipe-1.6 {32 bit comprehensive tests: from console} \
91 {win cat32 AllocConsole} {
92 # would block waiting for human input
93 } {}
94 test winpipe-1.7 {32 bit comprehensive tests: from NUL} {win exec cat32} {
95 exec $cat32 < nul > $path(stdout) 2> $path(stderr)
96 list [contents $path(stdout)] [contents $path(stderr)]
97 } {{} stderr32}
98 test winpipe-1.8 {32 bit comprehensive tests: from socket} {win cat32} {
99 # doesn't work
100 } {}
101 test winpipe-1.9 {32 bit comprehensive tests: from nowhere} \
102 {win exec cat32 RealConsole} {
103 exec $cat32 > $path(stdout) 2> $path(stderr)
104 list [contents $path(stdout)] [contents $path(stderr)]
105 } {{} stderr32}
106 test winpipe-1.10 {32 bit comprehensive tests: from file handle} \
107 {win exec cat32} {
108 set f [open $path(little) r]
109 exec $cat32 <@$f > $path(stdout) 2> $path(stderr)
110 close $f
111 list [contents $path(stdout)] [contents $path(stderr)]
112 } {little stderr32}
113 test winpipe-1.11 {32 bit comprehensive tests: read from application} \
114 {win exec cat32} {
115 set f [open "|[list $cat32] < [list $path(little)]" r]
116 gets $f line
117 catch {close $f} msg
118 list $line $msg
119 } {little stderr32}
120 test winpipe-1.12 {32 bit comprehensive tests: a little to file} \
121 {win exec cat32} {
122 exec $cat32 < $path(little) > $path(stdout) 2> $path(stderr)
123 list [contents $path(stdout)] [contents $path(stderr)]
124 } {little stderr32}
125 test winpipe-1.13 {32 bit comprehensive tests: a lot to file} \
126 {win exec cat32} {
127 exec $cat32 < $path(big) > $path(stdout) 2> $path(stderr)
128 list [contents $path(stdout)] [contents $path(stderr)]
129 } "{$big} stderr32"
130 test winpipe-1.14 {32 bit comprehensive tests: a little to pipe} \
131 {win exec stdio cat32} {
132 exec $cat32 < $path(little) | [interpreter] $path(more) > $path(stdout) 2> $path(stderr)
133 list [contents $path(stdout)] [contents $path(stderr)]
134 } {little stderr32}
135 test winpipe-1.15 {32 bit comprehensive tests: a lot to pipe} \
136 {win exec stdio cat32} {
137 exec $cat32 < $path(big) | [interpreter] $path(more) > $path(stdout) 2> $path(stderr)
138 list [contents $path(stdout)] [contents $path(stderr)]
139 } "{$big} stderr32"
140 test winpipe-1.16 {32 bit comprehensive tests: to console} {win exec cat32} {
141 catch {exec $cat32 << "You should see this\n" >@stdout} msg
142 set msg
143 } stderr32
144 test winpipe-1.17 {32 bit comprehensive tests: to NUL} {win exec cat32} {
145 # some apps hang when sending a large amount to NUL. $cat32 isn't one.
146 catch {exec $cat32 < $path(big) > nul} msg
147 set msg
148 } stderr32
149 test winpipe-1.18 {32 bit comprehensive tests: to nowhere} \
150 {win exec cat32 RealConsole} {
151 exec $cat32 < $path(big) >&@stdout
152 } {}
153 test winpipe-1.19 {32 bit comprehensive tests: to file handle} {win exec cat32} {
154 set f1 [open $path(stdout) w]
155 set f2 [open $path(stderr) w]
156 exec $cat32 < $path(little) >@$f1 2>@$f2
157 close $f1
158 close $f2
159 list [contents $path(stdout)] [contents $path(stderr)]
160 } {little stderr32}
161 test winpipe-1.20 {32 bit comprehensive tests: write to application} \
162 {win exec cat32} {
163 set f [open |[list $cat32 >$path(stdout)] w]
164 puts -nonewline $f "foo"
165 catch {close $f} msg
166 list [contents $path(stdout)] $msg
167 } {foo stderr32}
168 test winpipe-1.21 {32 bit comprehensive tests: read/write application} \
169 {win exec cat32} {
170 set f [open "|[list $cat32]" r+]
171 puts $f $big
172 puts $f \032
173 flush $f
174 set r [read $f 64]
175 catch {close $f}
176 set r
177 } "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
178
179 test winpipe-4.1 {Tcl_WaitPid} {win nt exec cat32} {
180 proc readResults {f} {
181 global x result
182 if { [eof $f] } {
183 close $f
184 set x 1
185 } else {
186 set line [read $f ]
187 set result "$result$line"
188 }
189 }
190 set f [open "|[list $cat32] < $path(big) 2> $path(stderr)" r]
191 fconfigure $f -buffering none -blocking 0
192 fileevent $f readable "readResults $f"
193 set x 0
194 set result ""
195 vwait x
196 list $result $x [contents $path(stderr)]
197 } "{$big} 1 stderr32"
198 test winpipe-4.2 {Tcl_WaitPid: return of exception codes, SIGFPE} {win exec testexcept} {
199 set f [open "|[list [interpreter]]" w+]
200 set pid [pid $f]
201 puts $f "load $::tcltestlib Tcltest"
202 puts $f "testexcept float_underflow"
203 set status [catch {close $f}]
204 list $status [expr {$pid == [lindex $::errorCode 1]}] [lindex $::errorCode 2]
205 } {1 1 SIGFPE}
206 test winpipe-4.3 {Tcl_WaitPid: return of exception codes, SIGSEGV} {win exec testexcept} {
207 set f [open "|[list [interpreter]]" w+]
208 set pid [pid $f]
209 puts $f "load $::tcltestlib Tcltest"
210 puts $f "testexcept access_violation"
211 set status [catch {close $f}]
212 list $status [expr {$pid == [lindex $::errorCode 1]}] [lindex $::errorCode 2]
213 } {1 1 SIGSEGV}
214 test winpipe-4.4 {Tcl_WaitPid: return of exception codes, SIGILL} {win exec testexcept} {
215 set f [open "|[list [interpreter]]" w+]
216 set pid [pid $f]
217 puts $f "load $::tcltestlib Tcltest"
218 puts $f "testexcept illegal_instruction"
219 set status [catch {close $f}]
220 list $status [expr {$pid == [lindex $::errorCode 1]}] [lindex $::errorCode 2]
221 } {1 1 SIGILL}
222 test winpipe-4.5 {Tcl_WaitPid: return of exception codes, SIGINT} {win exec testexcept} {
223 set f [open "|[list [interpreter]]" w+]
224 set pid [pid $f]
225 puts $f "load $::tcltestlib Tcltest"
226 puts $f "testexcept ctrl+c"
227 set status [catch {close $f}]
228 list $status [expr {$pid == [lindex $::errorCode 1]}] [lindex $::errorCode 2]
229 } {1 1 SIGINT}
230
231 set path(nothing) [makeFile {} nothing]
232 close [open $path(nothing) w]
233
234 catch {set env_tmp $env(TMP)}
235 catch {set env_temp $env(TEMP)}
236
237 set env(TMP) c:/
238 set env(TEMP) c:/
239
240 test winpipe-5.1 {TclpCreateTempFile: cleanup temp files} {win exec} {
241 set x {}
242 set existing [glob -nocomplain c:/tcl*.tmp]
243 exec [interpreter] < $path(nothing)
244 foreach p [glob -nocomplain c:/tcl*.tmp] {
245 if {$p ni $existing} {
246 lappend x $p
247 }
248 }
249 set x
250 } {}
251 test winpipe-5.2 {TclpCreateTempFile: TMP and TEMP not defined} {win exec} {
252 set tmp $env(TMP)
253 set temp $env(TEMP)
254 unset env(TMP)
255 unset env(TEMP)
256 exec [interpreter] < $path(nothing)
257 set env(TMP) $tmp
258 set env(TEMP) $temp
259 set x {}
260 } {}
261 test winpipe-5.3 {TclpCreateTempFile: TMP specifies non-existent directory} \
262 {win exec } {
263 set tmp $env(TMP)
264 set env(TMP) snarky
265 exec [interpreter] < $path(nothing)
266 set env(TMP) $tmp
267 set x {}
268 } {}
269 test winpipe-5.4 {TclpCreateTempFile: TEMP specifies non-existent directory} \
270 {win exec} {
271 set tmp $env(TMP)
272 set temp $env(TEMP)
273 unset env(TMP)
274 set env(TEMP) snarky
275 exec [interpreter] < $path(nothing)
276 set env(TMP) $tmp
277 set env(TEMP) $temp
278 set x {}
279 } {}
280
281 test winpipe-6.1 {PipeSetupProc & PipeCheckProc: read threads} \
282 {win exec cat32} {
283 set f [open "|[list $cat32]" r+]
284 fconfigure $f -blocking 0
285 fileevent $f writable { set x writable }
286 set x {}
287 vwait x
288 fileevent $f writable {}
289 fileevent $f readable { lappend x readable }
290 after 100 { lappend x timeout }
291 vwait x
292 puts $f foobar
293 flush $f
294 vwait x
295 lappend x [read $f]
296 after 100 { lappend x timeout }
297 vwait x
298 fconfigure $f -blocking 1
299 lappend x [catch {close $f} msg] $msg
300 } {writable timeout readable {foobar
301 } timeout 1 stderr32}
302 test winpipe-6.2 {PipeSetupProc & PipeCheckProc: write threads} \
303 {win exec cat32} {
304 set f [open "|[list $cat32]" r+]
305 fconfigure $f -blocking 0
306 fileevent $f writable { set x writable }
307 set x {}
308 vwait x
309 puts -nonewline $f $big$big$big$big
310 flush $f
311 after 100 { lappend x timeout }
312 vwait x
313 lappend x [catch {close $f} msg] $msg
314 } {writable timeout 0 {}}
315
316 proc _testExecArgs {flags args} {
317 variable path
318 if {![info exists path(echoArgs.tcl)] || ![file exists $path(echoArgs.tcl)]} {
319 set path(echoArgs.tcl) [makeFile {
320 puts "[list [file tail $argv0] {*}$argv]"
321 } echoArgs.tcl]
322 }
323 if {![info exists path(echoArgs.bat)] || ![file exists $path(echoArgs.bat)]} {
324 set path(echoArgs.bat) [makeFile "@[file native [interpreter]] $path(echoArgs.tcl) %*" "echoArgs.bat"]
325 }
326 set cmds [list [list [interpreter] $path(echoArgs.tcl)]]
327 if {"exe-only" ni $flags} {
328 if {"batch2" ni $flags} {
329 lappend cmds [list $path(echoArgs.bat)]
330 } else {
331 if {![info exists path(echoArgs2.bat)] || ![file exists $path(echoArgs2.bat)]} {
332 set path(echoArgs2.bat) [makeFile \
333 "@[file native [interpreter]] $path(echoArgs.tcl) %*" \
334 "echo(Cmd)Test Args & Batch.bat" [makeDirectory test(Dir)Check]]
335 }
336 lappend cmds [list $path(echoArgs2.bat)]
337 }
338 }
339 set broken {}
340 foreach args $args {
341 if {"enclose" in $flags} {
342 # enclose single test-arg between 1st/3rd to be sure nothing is truncated
343 # (e. g. to cover unexpected trim by nts-zero case, and args don't recombined):
344 set args [list "1st" $args "3rd"]
345 }
346 set args [list {*}$args]; # normalized canonical list
347 foreach cmd $cmds {
348 set e [linsert $args 0 [file tail $path(echoArgs.tcl)]]
349 tcltest::DebugPuts 4 " ## test exec [file extension [lindex $cmd 0]] ($cmd) for\n ## $args"
350 if {[catch {
351 exec {*}$cmd {*}$args
352 } r]} {
353 set r "ERROR: $r"
354 }
355 if {[file extension [lindex $cmd 0]] eq ".bat"} {
356 set evm {}; foreach ev [lsort -unique [regexp -inline -all {%[A-Z]+%} $e]] {
357 set ev [string range $ev 1 end-1]
358 if {[info exists ::env($ev)]} { lappend evm %$ev% $::env($ev) }
359 }
360 set e [string map $evm $e]
361 }
362 if {$r ne $e} {
363 append broken "\[ERROR\]: exec [file extension [lindex $cmd 0]] on $args\n -- result:\n$r\n -- expected:\n$e\n"
364 }
365 }
366 }
367 return $broken
368 }
369
370 ### validate the raw output of BuildCommandLine().
371 ###
372 test winpipe-7.1 {BuildCommandLine: null arguments} {win exec} {
373 exec $env(COMSPEC) /c echo foo "" bar
374 } {foo "" bar}
375 test winpipe-7.2 {BuildCommandLine: null arguments} {win exec} {
376 exec $env(COMSPEC) /c echo foo {} bar
377 } {foo "" bar}
378 test winpipe-7.3 {BuildCommandLine: dbl quote quoting #1} {win exec} {
379 exec $env(COMSPEC) /c echo foo "\"" bar
380 } {foo \" bar}
381 test winpipe-7.4 {BuildCommandLine: dbl quote quoting #2} {win exec} {
382 exec $env(COMSPEC) /c echo foo {""} bar
383 } {foo \"\" bar}
384 test winpipe-7.5 {BuildCommandLine: dbl quote quoting #3} {win exec} {
385 exec $env(COMSPEC) /c echo foo "\" " bar
386 } {foo "\" " bar}
387 test winpipe-7.6 {BuildCommandLine: dbl quote quoting #4} {win exec} {
388 exec $env(COMSPEC) /c echo foo {a="b"} bar
389 } {foo a=\"b\" bar}
390 test winpipe-7.7 {BuildCommandLine: dbl quote quoting #5} {win exec} {
391 exec $env(COMSPEC) /c echo foo {a = "b"} bar
392 } {foo "a = \"b\"" bar}
393 test winpipe-7.8 {BuildCommandLine: dbl quote quoting #6} {win exec} {
394 exec $env(COMSPEC) /c echo {"hello"} {""hello""} {"""hello"""} {"\"hello\""} {he llo} "he \" llo"
395 } {\"hello\" \"\"hello\"\" \"\"\"hello\"\"\" \"\\\"hello\\\"\" "he llo" "he \" llo"}
396 test winpipe-7.9 {BuildCommandLine: N backslashes followed a quote rule #1} {win exec} {
397 exec $env(COMSPEC) /c echo foo \\ bar
398 } {foo \ bar}
399 test winpipe-7.10 {BuildCommandLine: N backslashes followed a quote rule #2} {win exec} {
400 exec $env(COMSPEC) /c echo foo \\\\ bar
401 } {foo \\ bar}
402 test winpipe-7.11 {BuildCommandLine: N backslashes followed a quote rule #3} {win exec} {
403 exec $env(COMSPEC) /c echo foo \\\ \\ bar
404 } {foo "\ \\" bar}
405 test winpipe-7.12 {BuildCommandLine: N backslashes followed a quote rule #4} {win exec} {
406 exec $env(COMSPEC) /c echo foo \\\ \\\\ bar
407 } {foo "\ \\\\" bar}
408 test winpipe-7.13 {BuildCommandLine: N backslashes followed a quote rule #5} {win exec} {
409 exec $env(COMSPEC) /c echo foo \\\ \\\\\\ bar
410 } {foo "\ \\\\\\" bar}
411 test winpipe-7.14 {BuildCommandLine: N backslashes followed a quote rule #6} {win exec} {
412 exec $env(COMSPEC) /c echo foo \\\ \\\" bar
413 } {foo "\ \\\"" bar}
414 test winpipe-7.15 {BuildCommandLine: N backslashes followed a quote rule #7} {win exec} {
415 exec $env(COMSPEC) /c echo foo \\\ \\\\\" bar
416 } {foo "\ \\\\\"" bar}
417 test winpipe-7.16 {BuildCommandLine: N backslashes followed a quote rule #8} {win exec} {
418 exec $env(COMSPEC) /c echo foo \\\ \\\\\\\" bar
419 } {foo "\ \\\\\\\"" bar}
420 test winpipe-7.17 {BuildCommandLine: special chars #4} {win exec} {
421 exec $env(COMSPEC) /c echo foo \{ bar
422 } "foo \{ bar"
423 test winpipe-7.18 {BuildCommandLine: special chars #5} {win exec} {
424 exec $env(COMSPEC) /c echo foo \} bar
425 } "foo \} bar"
426
427 set injectList {
428 {test"whoami} {test""whoami}
429 {test"""whoami} {test""""whoami}
430
431 "test\"whoami\\" "test\"\"whoami\\"
432 "test\"\"\"whoami\\" "test\"\"\"\"whoami\\"
433
434 {test\\&\\test} {test"\\&\\test}
435 {"test\\&\\test} {"test"\\&\\"test"}
436 {test\\"&"\\test} {test"\\"&"\\test}
437 {"test\\"&"\\test} {"test"\\"&"\\"test"}
438
439 {test\"&whoami} {test"\"&whoami}
440 {test""\"&whoami} {test"""\"&whoami}
441 {test\"\&whoami} {test"\"\&whoami}
442 {test""\"\&whoami} {test"""\"\&whoami}
443
444 {test&whoami} {test|whoami}
445 {"test&whoami} {"test|whoami}
446 {test"&whoami} {test"|whoami}
447 {"test"&whoami} {"test"|whoami}
448 {""test"&whoami} {""test"|whoami}
449
450 {test&echo "} {test|echo "}
451 {"test&echo "} {"test|echo "}
452 {test"&echo "} {test"|echo "}
453 {"test"&echo "} {"test"|echo "}
454 {""test"&echo "} {""test"|echo "}
455
456 {test&echo ""} {test|echo ""}
457 {"test&echo ""} {"test|echo ""}
458 {test"&echo ""} {test"|echo ""}
459 {"test"&echo ""} {"test"|echo ""}
460 {""test"&echo ""} {""test"|echo ""}
461
462 {test>whoami} {test<whoami}
463 {"test>whoami} {"test<whoami}
464 {test">whoami} {test"<whoami}
465 {"test">whoami} {"test"<whoami}
466 {""test">whoami} {""test"<whoami}
467 {test(whoami)} {test(whoami)}
468 {test"(whoami)} {test"(whoami)}
469 {test^whoami} {test^^echo ^^^}
470 {test"^whoami} {test"^^echo ^^^}
471 {test"^echo ^^^"} {test""^echo" ^^^"}
472
473 {test%USERDOMAIN%\%USERNAME%}
474 {test" %USERDOMAIN%\%USERNAME%}
475 {test%USERDOMAIN%\\%USERNAME%}
476 {test" %USERDOMAIN%\\%USERNAME%}
477 {test%USERDOMAIN%&%USERNAME%}
478 {test" %USERDOMAIN%&%USERNAME%}
479 {test%USERDOMAIN%\&\%USERNAME%}
480 {test" %USERDOMAIN%\&\%USERNAME%}
481
482 {test%USERDOMAIN%\&\test}
483 {test" %USERDOMAIN%\&\test}
484 {test%USERDOMAIN%\\&\\test}
485 {test" %USERDOMAIN%\\&\\test}
486
487 {test%USERDOMAIN%\&\"test}
488 {test" %USERDOMAIN%\&\"test}
489 {test%USERDOMAIN%\\&\\"test}
490 {test" %USERDOMAIN%\\&\\"test}
491 }
492
493 ### validate the pass-thru from BuildCommandLine() to the crt's parse_cmdline().
494 ###
495 test winpipe-8.1 {BuildCommandLine/parse_cmdline pass-thru: dumped arguments are equal original} \
496 -constraints {win exec} -body {
497 _testExecArgs {} \
498 [list foo "" bar] \
499 [list foo {} bar] \
500 [list foo "\"" bar] \
501 [list foo {""} bar] \
502 [list foo "\" " bar] \
503 [list foo {a="b"} bar] \
504 [list foo {a = "b"} bar] \
505 [list {"hello"} {""hello""} {"""hello"""} {"\"hello\""} {he llo} {he " llo}] \
506 [list foo \\ bar] \
507 [list foo \\\\ bar] \
508 [list foo \\\ \\ bar] \
509 [list foo \\\ \\\\ bar] \
510 [list foo \\\ \\\\\\ bar] \
511 [list foo \\\ \\\" bar] \
512 [list foo \\\ \\\\\" bar] \
513 [list foo \\\ \\\\\\\" bar] \
514 [list foo \{ bar] \
515 [list foo \} bar] \
516 [list foo * makefile.?c bar]
517 } -result {}
518
519 test winpipe-8.2 {BuildCommandLine/parse_cmdline pass-thru: check injection on special meta-chars (particular)} \
520 -constraints {win exec slowTest} -body {
521 _testExecArgs enclose {*}$injectList
522 } -result {}
523
524 test winpipe-8.3 {BuildCommandLine/parse_cmdline pass-thru: check injection on special meta-chars (jointly)} \
525 -constraints {win exec} -body {
526 _testExecArgs {} \
527 [list START {*}$injectList END] \
528 [list "START\"" {*}$injectList END] \
529 [list START {*}$injectList "\"END"] \
530 [list "START\"" {*}$injectList "\"END"]
531 } -result {}
532
533 test winpipe-8.4 {BuildCommandLine/parse_cmdline pass-thru: check injection on special meta-chars (command/jointly args)} \
534 -constraints {win exec} -body {
535 _testExecArgs batch2 \
536 [list START {*}$injectList END] \
537 [list "START\"" {*}$injectList END] \
538 [list START {*}$injectList "\"END"] \
539 [list "START\"" {*}$injectList "\"END"]
540 } -result {}
541
542 test winpipe-8.5 {BuildCommandLine/parse_cmdline pass-thru: check injection on special meta-chars (random mix)} \
543 -constraints {win exec} -body {
544 set lst {}
545 set maps {
546 {\&|^<>!()%}
547 {\&|^<>!()% }
548 {"\&|^<>!()%}
549 {"\&|^<>!()% }
550 {"""""\\\\\&|^<>!()%}
551 {"""""\\\\\&|^<>!()% }
552 }
553 set i 0
554 time {
555 set args {[incr i].}
556 time {
557 set map [lindex $maps [expr {int(rand()*[llength $maps])}]]
558 # be sure arg has some prefix (avoid special handling, like |& etc)
559 set a {x}
560 while {[string length $a] < 50} {
561 append a [string index $map [expr {int(rand()*[string length $map])}]]
562 }
563 lappend args $a
564 } 20
565 lappend lst $args
566 } 10
567 _testExecArgs {} {*}$lst
568 } -result {} -cleanup {
569 unset -nocomplain lst args a map maps
570 }
571
572 set injectList {
573 "test\"\nwhoami" "test\"\"\nwhoami"
574 "test\"\"\"\nwhoami" "test\"\"\"\"\nwhoami"
575 "test;\n&echo \"" "\"test;\n&echo \""
576 "test\";\n&echo \"" "\"test\";\n&echo \""
577 "\"\"test\";\n&echo \""
578 }
579
580 test winpipe-8.6 {BuildCommandLine/parse_cmdline pass-thru: check new-line quoted in args} \
581 -constraints {win exec} -body {
582 # test exe only, because currently there is no proper way to escape a new-line char resp.
583 # to supply a new-line to the batch-files within arguments (command line is truncated).
584 _testExecArgs exe-only \
585 [list START {*}$injectList END] \
586 [list "START\"" {*}$injectList END] \
587 [list START {*}$injectList "\"END"] \
588 [list "START\"" {*}$injectList "\"END"]
589 } -result {}
590
591 test winpipe-8.7 {BuildCommandLine/parse_cmdline pass-thru: check new-line quoted in args (batch)} \
592 -constraints {win exec knownBug} -body {
593 # this will fail if executed batch-file, because currently there is no proper way to escape a new-line char.
594 _testExecArgs {} $injectList
595 } -result {}
596
597
598 rename _testExecArgs {}
599
600 # restore old values for env(TMP) and env(TEMP)
601
602 if {[catch {set env(TMP) $env_tmp}]} {
603 unset env(TMP)
604 }
605 if {[catch {set env(TEMP) $env_temp}]} {
606 unset env(TEMP)
607 }
608
609 # cleanup
610 removeFile little
611 removeFile big
612 removeFile more
613 removeFile stdout
614 removeFile stderr
615 removeFile nothing
616 if {[info exists path(echoArgs.tcl)]} { removeFile echoArgs.tcl }
617 if {[info exists path(echoArgs.bat)]} { removeFile echoArgs.bat }
618 if {[info exists path(echoArgs2.bat)]} { removeDirectory test(Dir)Check }
619 ::tcltest::cleanupTests
620 # back to original directory:
621 cd $org_pwd; unset org_pwd
622 return
623
624 # Local Variables:
625 # mode: tcl
626 # End: