tcltest: do a better job of cleanup up after tests
[jimtcl.git] / tests / pid.test
blob6a534a5bdfe3fc9834c7e1af209bd4a44fd61e73
1 # Commands covered:  pid
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands.  Sourcing this file into Tcl runs the tests and
5 # generates output for errors.  No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994-1995 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: pid.test,v 1.6 2000/04/10 17:19:03 ericm Exp $
16 source [file dirname [info script]]/testing.tcl
18 needs cmd pid posix
19 needs cmd exec
20 catch {package require regexp}
21 testConstraint regexp [expr {[info commands regexp] ne {}}]
22 testConstraint socket [expr {[info commands socket] ne {}}]
23 testConstraint getpid [expr {[catch pid] == 0}]
24 # This is a proxy for tcl || tclcompat
25 testConstraint pidchan [expr {[info commands fconfigure] ne {}}]
27 file delete test1
29 test pid-1.1 {pid command} {regexp getpid} {
30     regexp {(^[0-9]+$)|(^0x[0-9a-fA-F]+$)} [pid]
31 } 1
32 test pid-1.2 {pid command} {regexp socket pidchan} {
33     set f [open {| echo foo | cat >test1} w]
34     set pids [pid $f]
35     close $f
36     catch {removeFile test1}
37     list [llength $pids] [regexp {^[0-9]+$} [lindex $pids 0]] \
38        [regexp {^[0-9]+$} [lindex $pids 1]] \
39        [expr {[lindex $pids 0] == [lindex $pids 1]}]
40 } {2 1 1 0}
41 test pid-1.3 {pid command} {socket pidchan} {
42     set f [open test1 w]
43     set pids [pid $f]
44     close $f
45     set pids
46 } {}
47 test pid-1.4 {pid command} pidchan {
48     list [catch {pid a b} msg] $msg
49 } {1 {wrong # args: should be "pid ?channelId?"}}
50 test pid-1.5 {pid command} pidchan {
51     list [catch {pid gorp} msg] $msg
52 } {1 {can not find channel named "gorp"}}
54 # cleanup
55 file delete test1
57 testreport