sl@0: # Commands covered:  pid
sl@0: #
sl@0: # This file contains a collection of tests for one or more of the Tcl
sl@0: # built-in commands.  Sourcing this file into Tcl runs the tests and
sl@0: # generates output for errors.  No output means no errors were found.
sl@0: #
sl@0: # Copyright (c) 1991-1993 The Regents of the University of California.
sl@0: # Copyright (c) 1994-1995 Sun Microsystems, Inc.
sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0: #
sl@0: # See the file "license.terms" for information on usage and redistribution
sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0: #
sl@0: # RCS: @(#) $Id: pid.test,v 1.8.2.2 2004/02/25 23:38:17 dgp Exp $
sl@0: 
sl@0: if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0:     package require tcltest 2
sl@0:     namespace import -force ::tcltest::*
sl@0: }
sl@0: 
sl@0: # If pid is not defined just return with no error
sl@0: # Some platforms may not have the pid command implemented
sl@0: if {[info commands pid] == ""} {
sl@0:     puts "pid is not implemented for this machine"
sl@0:     ::tcltest::cleanupTests
sl@0:     return
sl@0: }
sl@0: 
sl@0: test pid-1.1 {pid command} {
sl@0:     regexp {(^[0-9]+$)|(^0x[0-9a-fA-F]+$)} [pid]
sl@0: } 1
sl@0: test pid-1.2 {pid command} -constraints {unixOrPc unixExecs} -setup {
sl@0:     set path(test1) [makeFile {} test1]
sl@0:     file delete $path(test1)
sl@0: } -body {
sl@0:     set f [open |[list echo foo | cat >$path(test1)] w]
sl@0:     set pids [pid $f]
sl@0:     close $f
sl@0:     list [llength $pids] [regexp {^[0-9]+$} [lindex $pids 0]] \
sl@0:        [regexp {^[0-9]+$} [lindex $pids 1]] \
sl@0:        [expr {[lindex $pids 0] == [lindex $pids 1]}]
sl@0: } -cleanup {
sl@0:     removeFile test1
sl@0: } -result {2 1 1 0}
sl@0: test pid-1.3 {pid command} -setup {
sl@0:     set path(test1) [makeFile {} test1]
sl@0:     file delete $path(test1)
sl@0: } -body {
sl@0:     set f [open $path(test1) w]
sl@0:     set pids [pid $f]
sl@0:     close $f
sl@0:     set pids
sl@0: } -cleanup {
sl@0:     removeFile test1
sl@0: } -result {}
sl@0: test pid-1.4 {pid command} {
sl@0:     list [catch {pid a b} msg] $msg
sl@0: } {1 {wrong # args: should be "pid ?channelId?"}}
sl@0: test pid-1.5 {pid command} {
sl@0:     list [catch {pid gorp} msg] $msg
sl@0: } {1 {can not find channel named "gorp"}}
sl@0: 
sl@0: # cleanup
sl@0: ::tcltest::cleanupTests
sl@0: return
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: