File: pipe.test

package info (click to toggle)
tclx8.4 8.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: ansic: 14,863; tcl: 2,090; sh: 265; makefile: 159
file content (81 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download | duplicates (9)
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
#
# pipe.test
#
# Tests for the pipe command.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: pipe.test,v 1.3 2002/04/04 06:10:30 hobbs Exp $
#------------------------------------------------------------------------------
#

if {[cequal [info procs Test] {}]} {
    source [file join [file dirname [info script]] testlib.tcl]
}

#
# Fork without exec will not work under Tk, skip this test
#
if {[info exists tk_version]} {
    puts "******************************************************************"
    puts "The pipe commands test require fork, which does not work under Tk."
    puts "Test skipped."
    puts "******************************************************************"
    return
}
# FIX: Need win95 tests for pipe.

#
# Create child process to read from the pipe and write a message
# back.
#
proc PipeChild {id numRecs readChan} {
    flush stdout  ;# Not going to exec, must clean up the buffers.
    flush stderr
    set pid [fork]
    if {$pid != 0} {
        return $pid
    }
    for {set cnt 0} {$cnt < $numRecs} {incr cnt} {
        Test filecmds-4.1 {pipe tests} {
            if {![gets $readChan msgBuf]} {
                set msgBuf "Premature eof on pipe"
                set cnt $numRecs
            }
            set msgBuf
        } 0 [GenRec $cnt]
    }
    close $readChan
    exit 0
}

test pipe-1.1 {pipe tests} {
    list [catch {pipe x y z} msg] $msg
} {1 {wrong # args: pipe ?fileId_var_r fileId_var_w?}}

test pipe-1.2 {pipe tests} {unixOnly} {
    pipe readChan writeChan

    set pid [PipeChild pipe-1.3 50 $readChan]
    for {set cnt 0} {$cnt < 50} {incr cnt} {
        puts $writeChan [GenRec $cnt]
    }
    flush $writeChan
    Test pipe-1.32 {pipe tests} {
        wait $pid
    } 0 [list $pid EXIT 0]
        
    close $readChan
    close $writeChan
} {}

# cleanup
::tcltest::cleanupTests
return