1# Commands covered:  pid
2#
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.
6#
7# Copyright © 1991-1993 The Regents of the University of California.
8# Copyright © 1994-1995 Sun Microsystems, Inc.
9# Copyright © 1998-1999 Scriptics Corporation.
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
14if {"::tcltest" ni [namespace children]} {
15    package require tcltest 2.5
16    namespace import -force ::tcltest::*
17}
18
19testConstraint pidDefined [llength [info commands pid]]
20
21test pid-1.1 {pid command} pidDefined {
22    regexp {(^[0-9]+$)|(^0x[0-9a-fA-F]+$)} [pid]
23} 1
24test pid-1.2 {pid command} -constraints {unixOrWin unixExecs pidDefined} -setup {
25    set path(test1) [makeFile {} test1]
26    file delete $path(test1)
27} -body {
28    set f [open |[list echo foo | cat >$path(test1)] w]
29    set pids [pid $f]
30    close $f
31    list [llength $pids] [regexp {^[0-9]+$} [lindex $pids 0]] \
32       [regexp {^[0-9]+$} [lindex $pids 1]] \
33       [expr {[lindex $pids 0] == [lindex $pids 1]}]
34} -cleanup {
35    removeFile test1
36} -result {2 1 1 0}
37test pid-1.3 {pid command} -constraints pidDefined -setup {
38    set path(test1) [makeFile {} test1]
39    file delete $path(test1)
40} -body {
41    set f [open $path(test1) w]
42    set pids [pid $f]
43    close $f
44    set pids
45} -cleanup {
46    removeFile test1
47} -result {}
48test pid-1.4 {pid command} pidDefined {
49    list [catch {pid a b} msg] $msg
50} {1 {wrong # args: should be "pid ?channelId?"}}
51test pid-1.5 {pid command} pidDefined {
52    list [catch {pid gorp} msg] $msg
53} {1 {can not find channel named "gorp"}}
54
55# cleanup
56::tcltest::cleanupTests
57return
58