- #
- # 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.
- # Copyright (c) 1998-1999 by Scriptics Corporation.
- #
- # 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.22.2.4 2005/04/20 00:14:54 hobbs Exp $
- package require tcltest
- namespace import -force ::tcltest::*
- unset -nocomplain path
- testConstraint exec [llength [info commands exec]]
- set bindir [file join [pwd] [file dirname [info nameofexecutable]]]
- set cat32 [file join $bindir cat32.exe]
- set ::tcltest::testConstraints(cat32) [file exists $cat32]
- if {[catch {puts console1 ""}]} {
- set ::tcltest::testConstraints(AllocConsole) 1
- } else {
- set ::tcltest::testConstraints(.console) 1
- }
- set big bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbn
- append big $big
- append big $big
- append big $big
- append big $big
- append big $big
- append big $big
- set path(little) [makeFile {} little]
- set f [open $path(little) w]
- puts -nonewline $f "little"
- close $f
- set path(big) [makeFile {} big]
- set f [open $path(big) w]
- puts -nonewline $f $big
- close $f
- proc contents {file} {
- set f [open $file r]
- set r [read $f]
- close $f
- set r
- }
- set path(more) [makeFile {
- while {[eof stdin] == 0} {
- puts -nonewline [read stdin]
- }
- } more]
- set path(stdout) [makeFile {} stdout]
- set path(stderr) [makeFile {} stderr]
- test winpipe-1.1 {32 bit comprehensive tests: from little file} {pcOnly exec cat32} {
- exec $cat32 < $path(little) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.2 {32 bit comprehensive tests: from big file} {pcOnly exec cat32} {
- exec $cat32 < $path(big) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } "{$big} stderr32"
- test winpipe-1.3 {32 bit comprehensive tests: a little from pipe} {pcOnly nt exec cat32} {
- exec [interpreter] more < little | $cat32 > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.4 {32 bit comprehensive tests: a lot from pipe} {pcOnly nt exec cat32} {
- exec [interpreter] more < big | $cat32 > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } "{$big} stderr32"
- test winpipe-1.5 {32 bit comprehensive tests: a lot from pipe} {pcOnly 95 exec cat32} {
- exec command /c type big |& $cat32 > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } "{$big} stderr32"
- test winpipe-1.6 {32 bit comprehensive tests: from console}
- {pcOnly cat32 AllocConsole} {
- # would block waiting for human input
- } {}
- test winpipe-1.7 {32 bit comprehensive tests: from NUL} {pcOnly exec cat32} {
- exec $cat32 < nul > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {{} stderr32}
- test winpipe-1.8 {32 bit comprehensive tests: from socket} {pcOnly cat32} {
- # doesn't work
- } {}
- test winpipe-1.9 {32 bit comprehensive tests: from nowhere}
- {pcOnly exec cat32 .console} {
- exec $cat32 > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {{} stderr32}
- test winpipe-1.10 {32 bit comprehensive tests: from file handle}
- {pcOnly exec cat32} {
- set f [open $path(little) r]
- exec $cat32 <@$f > $path(stdout) 2> $path(stderr)
- close $f
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.11 {32 bit comprehensive tests: read from application}
- {pcOnly exec cat32} {
- set f [open "|[list $cat32] < $path(little)" r]
- gets $f line
- catch {close $f} msg
- list $line $msg
- } {little stderr32}
- test winpipe-1.12 {32 bit comprehensive tests: a little to file}
- {pcOnly exec cat32} {
- exec $cat32 < $path(little) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.13 {32 bit comprehensive tests: a lot to file}
- {pcOnly exec cat32} {
- exec $cat32 < $path(big) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } "{$big} stderr32"
- test winpipe-1.14 {32 bit comprehensive tests: a little to pipe}
- {pcOnly exec stdio cat32} {
- exec $cat32 < $path(little) | [interpreter] $path(more) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.15 {32 bit comprehensive tests: a lot to pipe}
- {pcOnly exec stdio cat32} {
- exec $cat32 < $path(big) | [interpreter] $path(more) > $path(stdout) 2> $path(stderr)
- list [contents $path(stdout)] [contents $path(stderr)]
- } "{$big} stderr32"
- test winpipe-1.16 {32 bit comprehensive tests: to console} {pcOnly exec cat32} {
- catch {exec $cat32 << "You should see thisn" >@stdout} msg
- set msg
- } stderr32
- test winpipe-1.17 {32 bit comprehensive tests: to NUL} {pcOnly exec cat32} {
- # some apps hang when sending a large amount to NUL. $cat32 isn't one.
- catch {exec $cat32 < $path(big) > nul} msg
- set msg
- } stderr32
- test winpipe-1.18 {32 bit comprehensive tests: to nowhere}
- {pcOnly exec cat32 .console} {
- exec $cat32 < $path(big) >&@stdout
- } {}
- test winpipe-1.19 {32 bit comprehensive tests: to file handle} {pcOnly exec cat32} {
- set f1 [open $path(stdout) w]
- set f2 [open $path(stderr) w]
- exec $cat32 < $path(little) >@$f1 2>@$f2
- close $f1
- close $f2
- list [contents $path(stdout)] [contents $path(stderr)]
- } {little stderr32}
- test winpipe-1.20 {32 bit comprehensive tests: write to application}
- {pcOnly exec cat32} {
- set f [open |[list $cat32 >$path(stdout)] w]
- puts -nonewline $f "foo"
- catch {close $f} msg
- list [contents $path(stdout)] $msg
- } {foo stderr32}
- test winpipe-1.21 {32 bit comprehensive tests: read/write application}
- {pcOnly exec cat32} {
- set f [open "|[list $cat32]" r+]
- puts $f $big
- puts $f