summaryrefslogtreecommitdiffstats
path: root/tests/winPipe.test
blob: 6e1cb856e984946d19bf4c61a4808832d2c0b10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# 
# winPipe.test --
#
# This file contains a collection of tests for tclWinPipe.c

# Sourcing this file into Tcl runs the tests and generates output for 
# errors.  No output means no errors were found.
#
# Copyright (c) 1996 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: winPipe.test,v 1.5 1999/02/03 19:12:27 stanton Exp $

if {$tcl_platform(platform) != "windows"} {
    return
}

set bindir [file join [pwd] [file dirname [info nameofexecutable]]]
set cat16 [file join  $bindir cat16.exe]
set cat32 [file join $bindir cat32.exe]

if {[string compare test [info procs test]] == 1} then {source defs}

if [catch {puts console1 ""}] {
    set testConfig(AllocConsole) 1
} else {
    set testConfig(.console) 1
}

set big aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
append big $big
append big $big	
append big $big
append big $big
append big $big
append big $big

set f [open "little" w] 
puts -nonewline $f "little"
close $f

set f [open "big" w]
puts -nonewline $f $big
close $f

proc contents {file} {
    set f [open $file r]
    set r [read $f]
    close $f
    set r
}

if {$testConfig(stdio) && [file exists $cat32]} {
test winpipe-1.1 {32 bit comprehensive tests: from little file} {
    exec $cat32 < little > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "little stderr32"
test winpipe-1.2 {32 bit comprehensive tests: from big file} {
    exec $cat32 < big > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big} stderr32"
test winpipe-1.3 {32 bit comprehensive tests: a little from pipe} {nt} {
    exec more < little | $cat32 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{little\n} stderr32"
test winpipe-1.4 {32 bit comprehensive tests: a little from pipe} {95} {
    exec more < little |& $cat32 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\nlittle} stderr32"
test winpipe-1.5 {32 bit comprehensive tests: a lot from pipe} {nt} {
    exec more < big | $cat32 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big} stderr32"
test winpipe-1.6 {32 bit comprehensive tests: a lot from pipe} {95} {
    exec command /c type big |& $cat32 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big} stderr32"
test winpipe-1.7 {32 bit comprehensive tests: from console} {AllocConsole} {
    # would block waiting for human input
} {}
test winpipe-1.8 {32 bit comprehensive tests: from NUL} {
    exec $cat32 < nul > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{} stderr32"
test winpipe-1.9 {32 bit comprehensive tests: from socket} {
    # doesn't work
} {}
test winpipe-1.10 {32 bit comprehensive tests: from nowhere} {.console} {
    exec $cat32 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{} stderr32"
test winpipe-1.11 {32 bit comprehensive tests: from file handle} {
    set f [open "little" r]
    exec $cat32 <@$f > stdout 2> stderr
    close $f
    list [contents stdout] [contents stderr]
} "little stderr32"
test winpipe-1.12 {32 bit comprehensive tests: read from application} {
    set f [open "|$cat32 < little" r]
    gets $f line
    catch {close $f} msg
    list $line $msg
} "little stderr32"
test winpipe-1.13 {32 bit comprehensive tests: a little to file} {
    exec $cat32 < little > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "little stderr32"
test winpipe-1.14 {32 bit comprehensive tests: a lot to file} {
    exec $cat32 < big > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big} stderr32"
test winpipe-1.15 {32 bit comprehensive tests: a little to pipe} {nt} {
    exec $cat32 < little | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{little\n} stderr32"
test winpipe-1.16 {32 bit comprehensive tests: a little to pipe} {95} {
    exec $cat32 < little | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\nlittle} stderr32"
test winpipe-1.17 {32 bit comprehensive tests: a lot to pipe} {nt} {
    exec $cat32 < big | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big\n} stderr32"
test winpipe-1.18 {32 bit comprehensive tests: a lot to pipe} {95} {
    exec $cat32 < big | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\n$big} stderr32"
test winpipe-1.19 {32 bit comprehensive tests: to console} {
    catch {exec $cat32 << "You should see this\n" >@stdout} msg
    set msg
} stderr32
test winpipe-1.20 {32 bit comprehensive tests: to NUL} {
    # some apps hang when sending a large amount to NUL.  $cat32 isn't one.
    catch {exec $cat32 < big > nul} msg
    set msg
} stderr32
test winpipe-1.21 {32 bit comprehensive tests: to nowhere} {.console} {
    exec $cat32 < big >&@stdout 
} {}
test winpipe-1.22 {32 bit comprehensive tests: to file handle} {
    set f1 [open "stdout" w]
    set f2 [open "stderr" w]
    exec $cat32 < little >@$f1 2>@$f2
    close $f1
    close $f2
    list [contents stdout] [contents stderr]
} "little stderr32"
test winpipe-1.23 {32 bit comprehensive tests: write to application} {
    set f [open "|$cat32 > stdout" w]
    puts -nonewline $f "foo"
    catch {close $f} msg
    list [contents stdout] $msg
} "foo stderr32"
test winpipe-1.24 {32 bit comprehensive tests: read/write application} {
    set f [open "|$cat32" r+]
    puts $f $big
    puts $f \032
    flush $f
    set r [read $f 64]
    catch {close $f}
    set r
} "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}

set stderr16 "stderr16"
if {$tcl_platform(os) == "Win32s"} {
    set stderr16 "{}"
}
if [file exists $cat16] {
test winpipe-2.1 {16 bit comprehensive tests: from little file} {
    exec $cat16 < little > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "little $stderr16"
test winpipe-2.2 {16 bit comprehensive tests: from big file} {
    exec $cat16 < big > stdout 2> stderr
    list [contents stdout] [contents stderr] 
} "{$big} $stderr16"
test winpipe-2.3 {16 bit comprehensive tests: a little from pipe} {nt} {
    exec more < little | $cat16 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{little\n} stderr16"
test winpipe-2.4 {16 bit comprehensive tests: a little from pipe} {95} {
    exec more < little | $cat16 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\nlittle} stderr16"
test winpipe-2.5 {16 bit comprehensive tests: a lot from pipe} {nt} {
    exec $cat16 < big | $cat16 > stdout 2> stderr
    list [contents stdout] [contents stderr] 
} "{$big} stderr16stderr16"
test winpipe-2.6 {16 bit comprehensive tests: a lot from pipe} {95} {
    exec more < big | $cat16 > stdout 2> stderr
    list [contents stdout] [contents stderr] 
} "{\n$big} stderr16"
test winpipe-2.7 {16 bit comprehensive tests: from console} {AllocConsole} {
    # would block waiting for human input
} {}		     
test winpipe-2.8 {16 bit comprehensive tests: from NUL} {nt} {
    exec $cat16 < nul > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{} stderr16"
test winpipe-2.9 {16 bit comprehensive tests: from socket} {
    # doesn't work
} {}
test winpipe-2.10 {16 bit comprehensive tests: from nowhere} {.console} {
    exec $cat16 > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{} stderr16"
test winpipe-2.11 {16 bit comprehensive tests: from file handle} {
    set f [open "little" r]
    exec $cat16 <@$f > stdout 2> stderr
    close $f
    list [contents stdout] [contents stderr]
} "little $stderr16"
test winpipe-2.12 {16 bit comprehensive tests: read from application} {
    set f [open "|$cat16 < little" r]
    gets $f line
    catch {close $f} msg
    list $line $msg
} "little $stderr16"
test winpipe-2.13 {16 bit comprehensive tests: a little to file} {
    exec $cat16 < little > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "little $stderr16"
test winpipe-2.14 {16 bit comprehensive tests: a lot to file} {
    exec $cat16 < big > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{$big} $stderr16"
test winpipe-2.15 {16 bit comprehensive tests: a little to pipe} {nt} {
    catch {exec $cat16 < little | more > stdout 2> stderr}
    list [contents stdout] [contents stderr]
} "{little\n} stderr16"
test winpipe-2.16 {16 bit comprehensive tests: a little to pipe} {95} {
    exec $cat16 < little | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\nlittle} stderr16"
test winpipe-2.17 {16 bit comprehensive tests: a lot to pipe} {nt} {
    catch {exec $cat16 < big | more > stdout 2> stderr}
    list [contents stdout] [contents stderr]
} "{$big\n} stderr16"
test winpipe-2.18 {16 bit comprehensive tests: a lot to pipe} {95} {
    exec $cat16 < big | more > stdout 2> stderr
    list [contents stdout] [contents stderr]
} "{\n$big} stderr16"
test winpipe-2.19 {16 bit comprehensive tests: to console} {
    catch {exec $cat16 << "You should see this\n" >@stdout} msg
    set msg
} [lindex $stderr16 0]
test winpipe-2.20 {16 bit comprehensive tests: to NUL} {nt} {
    # some apps hang when sending a large amount to NUL.  cat16 isn't one.
    catch {exec $cat16 < big > nul} msg
    set msg
} stderr16
test winpipe-2.21 {16 bit comprehensive tests: to nowhere} {.console} {
    exec $cat16 < big >&@stdout 
} {}
test winpipe-2.22 {16 bit comprehensive tests: to file handle} {
    set f1 [open "stdout" w]
    set f2 [open "stderr" w]
    exec $cat16 < little >@$f1 2>@$f2
    close $f1
    close $f2
    list [contents stdout] [contents stderr]
} "little $stderr16"
test winpipe-2.23 {16 bit comprehensive tests: write to application} {!win32s} {
    set f [open "|$cat16 > stdout" w]
    puts -nonewline $f "foo"
    catch {close $f} msg
    list [contents stdout] $msg
} "foo stderr16"
test winpipe-2.24 {16 bit comprehensive tests: read/write application} {nt} {
    set f [open "|$cat16" r+]
    puts $f $big
    puts $f \032
    flush $f
    set r [read $f 64]
    catch {close $f}
    set r
} "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}

test winpipe-4.1 {Tcl_WaitPid} {nt} {
    proc readResults {f} {
	global x result
	if { [eof $f] } {
	    close $f
	    set x 1
	} else {
	    set line [read $f ]
	    set result "$result$line"
	}
    }

    set f [open "|$cat32 < big 2> stderr" r]
    fconfigure $f  -buffering none -blocking 0
    fileevent $f readable "readResults $f"
    set x 0
    set result ""
    vwait x
    list $result $x [contents stderr]
} "{$big} 1 stderr32"

close [open nothing w]

catch {set env_tmp $env(TMP)}
catch {set env_temp $env(TEMP)}

set env(TMP) c:/
set env(TEMP) c:/

test winpipe-3.1 {TclpCreateTempFile: cleanup temp files} {
    set x {}
    set existing [glob -nocomplain c:/tcl*.tmp]
    exec $tcltest < nothing 
    foreach p [glob -nocomplain c:/tcl*.tmp] {
	if {[lsearch $existing $p] != -1} {
	    lappend x $p
	}
    }
    set x
} {}
test winpipe-3.2 {TclpCreateTempFile: TMP and TEMP not defined} {
    set tmp $env(TMP)
    set temp $env(TEMP)
    unset env(TMP)
    unset env(TEMP)
    exec $tcltest < nothing
    set env(TMP) $tmp
    set env(TEMP) $temp
    set x {}
} {}
test winpipe-3.3 {TclpCreateTempFile: TMP specifies non-existent directory} {
    set tmp $env(TMP)
    set env(TMP) snarky
    exec $tcltest < nothing
    set env(TMP) $tmp
    set x {}
} {}
test winpipe-3.3 {TclpCreateTempFile: TEMP specifies non-existent directory} {
    set tmp $env(TMP)
    set temp $env(TEMP)
    unset env(TMP)
    set env(TEMP) snarky
    exec $tcltest < nothing
    set env(TMP) $tmp
    set env(TEMP) $temp
    set x {}
} {}

makeFile {
    puts "[list $argv0 $argv]"
} echoArgs.tcl

test winpipe-4.1 {BuildCommandLine: null arguments} {
    exec $tcltest echoArgs.tcl foo "" bar
} {echoArgs.tcl {foo {} bar}}
test winpipe-4.1 {BuildCommandLine: null arguments} {
    exec $tcltest echoArgs.tcl foo \" bar
} {echoArgs.tcl {foo {"} bar}}

# restore old values fro env(TMP) and env(TEMP)

if {[catch {set env(TMP) $env_tmp}]} {
    unset $env(TMP)
}
if {[catch {set env(TEMP) $env_temp}]} {
    unset $env(TEMP)
}

file delete big little stdout stderr nothing dummy.tcl echoArgs.tcl