#
# chmod.test
#
# Tests for the chmod, chown and chgrp commands.
#---------------------------------------------------------------------------
# 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: chmod.test,v 1.1.1.1 1999/06/28 20:35:24 damon Exp $
#------------------------------------------------------------------------------
#

if [cequal [info procs Test] {}] {source testlib.tcl}

if [cequal $tcl_platform(platform) windows] {
    echo "    * The chmod, chown and chgrp commands have not been ported to Win32" 
    return
}

#-----------------------------------------------------------------------------
# This routine to the the mode of a file.  It is returned formated in octal.
 
proc GetMode {filename} {
    file stat $filename stat
    return [format "%o" [expr {$stat(mode) & 07777}]]
}

#-----------------------------------------------------------------------------
# Certain Unix systems don't handle chmod the same.  This routine test if the
# system chmod produces the expected results.
#   o mode - symbolic mode to set the file to.
#   o args - list of valid expected result from ls.
#
proc CheckChmod {mode args} {
    global chmodTestsSkipped

    set stat 0
    if {[catch {
        chmod 000 CHECK.TMP
        exec chmod $mode CHECK.TMP
        set sysMode [lindex [exec ls -l CHECK.TMP] 0]
    }] == 0} {
        if {[lsearch -exact $args $sysMode] >= 0} {
            set stat 1
        }
    }
    if !$stat {
        incr chmodTestsSkipped
    }
    return $stat
}

global chmodTestsSkipped
set chmodTestsSkipped 0

#-----------------------------------------------------------------------------
# Procedure to return the uid of a file.

proc GetUID {file} {
    file stat $file stat
    return $stat(uid)
}

#-----------------------------------------------------------------------------
# Procedure to return the gid of a file.

proc GetGID {file} {
    file stat $file stat
    return $stat(gid)
}

#-----------------------------------------------------------------------------
# Procedure to return the uid and gid of a file.

proc GetUIDGID {file} {
    file stat $file stat
    return [list $stat(uid) $stat(gid)]
}


#-----------------------------------------------------------------------------
# If a user does not have a group name assigned, then some tests will not work,
# just blow off the tests and let the user make things right. 

if {[catch {id group}] != 0} {
    echo "User '[id user]' does not have group name. Chmod tests skipped"
    return
}

#-----------------------------------------------------------------------------
# Purge existing test files and recreate them.
#
proc SetUpTestFiles {} {
    foreach f {CHECK.TMP CHMOD.TMP CHMOD2.TMP} {
        catch {
            chmod a+w $f
            file delete $f
        }
        close [open $f w]
    }
}

SetUpTestFiles

# Set the umask so that no bits are masked.  Some system chmods use umask
# if u, g, o or a are not specified in a symbolic chmod.

umask 000

Test chmod-1.1 {chmod absolute mode tests} {
    chmod 0000 CHMOD.TMP
    chmod 0101 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {101}

Test chmod-1.2 {chmod absolute mode tests} {
    chmod 0000 CHMOD.TMP
    chmod 0010 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {10}

Test chmod-1.3 {chmod absolute mode tests} {
    chmod 0000 CHMOD.TMP
    chmod 0777 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {777}

Test chmod-1.4 {chmod absolute mode tests} {
    chmod 0000 CHMOD.TMP
    chmod 0666 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {666}

Test chmod-1.5 {chmod absolute mode tests} {
    chmod 0000 CHMOD.TMP
    chmod 0705 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {705}

Test chmod-1.7 {chmod absolute mode tests} {
    chmod  0000 CHMOD.TMP
    chmod 04111 CHMOD.TMP
    GetMode     CHMOD.TMP
} 0 {4111}

if [infox have_fchmod] {
    Test chmod-1.9 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 0101 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {101}

    Test chmod-1.10 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 0010 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {10}

    Test chmod-1.11 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 0777 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {777}

    Test chmod-1.12 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 0666 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {666}

    Test chmod-1.13 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 0705 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {705}

    Test chmod-1.14 {chmod absolute mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 0000 $fh
        chmod -fileid 04111 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {4111}
}

Test chmod-2.1 {chmod absolute integer mode tests} {
    chmod   0 {CHMOD.TMP CHMOD2.TMP}
    chmod  65 {CHMOD.TMP CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {101 101}

Test chmod-2.2 {chmod absolute integer mode tests} {
    chmod 0 {CHMOD.TMP CHMOD2.TMP}
    chmod 8 {CHMOD.TMP CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {10 10}

Test chmod-2.3 {chmod absolute integer mode tests} {
    chmod   0 {CHMOD.TMP CHMOD2.TMP}
    chmod 511 {CHMOD.TMP CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {777 777}

Test chmod-2.4 {chmod absolute integer mode tests} {
    chmod   0 {CHMOD.TMP CHMOD2.TMP}
    chmod 438 {CHMOD.TMP CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {666 666}

Test chmod-2.5 {chmod absolute integer mode tests} {
    chmod   0 {CHMOD.TMP CHMOD2.TMP}
    chmod 453 {CHMOD.TMP  CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {705 705}

Test chmod-2.6 {chmod absolute integer mode tests} {
    chmod 0    CHMOD.TMP
    chmod 2121 CHMOD.TMP
    GetMode    CHMOD.TMP
} 0 {4111}

if [infox have_fchmod] {
    Test chmod-2.7 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chmod -fileid   0 [list $fh1 $fh2]
        chmod -fileid  65 [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
    } 0 {101 101}

    Test chmod-2.8 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chmod -fileid 0 [list $fh1 $fh2]
        chmod -fileid 8 [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
    } 0 {10 10}

    Test chmod-2.9 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chmod -fileid   0 [list $fh1 $fh2]
        chmod -fileid 511 [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
    } 0 {777 777}

    Test chmod-2.10 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chmod -fileid   0 [list $fh1 $fh2]
        chmod -fileid 438 [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
    } 0 {666 666}

    Test chmod-2.11 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chmod -fileid   0 [list $fh1 $fh2]
        chmod -fileid 453 [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
    } 0 {705 705}

    Test chmod-2.12 {chmod absolute integer mode tests} {
        chmod 0600 {CHMOD.TMP CHMOD2.TMP}
        set fh [open CHMOD.TMP w]
        chmod -fileid 0    $fh
        chmod -fileid 2121 $fh
        close $fh
        GetMode CHMOD.TMP
    } 0 {4111}
}

# Test symbolic mode.

Test chmod-3.1 {chmod symbolic mode tests} {
    chmod 000 CHMOD.TMP
    chmod +r  CHMOD.TMP
    GetMode   CHMOD.TMP
} 0 {444}

Test chmod-3.2 {chmod symbolic mode tests} {
    chmod 000 CHMOD.TMP
    chmod +r  CHMOD.TMP
    chmod +w  CHMOD.TMP
    GetMode   CHMOD.TMP
} 0 {666}

Test chmod-3.3 {chmod symbolic mode tests} {
    chmod 000 CHMOD.TMP
    chmod +r  CHMOD.TMP
    chmod +w  CHMOD.TMP
    chmod +x  CHMOD.TMP
    GetMode   CHMOD.TMP
} 0 {777}

Test chmod-3.4 {chmod symbolic mode tests} {
    chmod 000 CHMOD.TMP
    chmod +r  CHMOD.TMP
    chmod +w  CHMOD.TMP
    chmod +x  CHMOD.TMP
    chmod -r  CHMOD.TMP
    GetMode   CHMOD.TMP
} 0 {333}

Test chmod-3.5 {chmod symbolic mode tests} {
    chmod 000 CHMOD.TMP
    chmod +r  CHMOD.TMP
    chmod +w  CHMOD.TMP
    chmod +x  CHMOD.TMP
    chmod -r  CHMOD.TMP
    chmod -w  CHMOD.TMP
    GetMode   CHMOD.TMP
} 0 {111}

Test chmod-3.6 {chmod symbolic mode tests} {
    chmod 000 {CHMOD.TMP CHMOD2.TMP}
    chmod +r  {CHMOD.TMP CHMOD2.TMP}
    chmod +w  {CHMOD.TMP CHMOD2.TMP}
    chmod +x  {CHMOD.TMP CHMOD2.TMP}
    chmod -r  {CHMOD.TMP CHMOD2.TMP}
    chmod -w  {CHMOD.TMP CHMOD2.TMP}
    chmod -x  {CHMOD.TMP  CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {0 0}

Test chmod-3.7 {chmod symbolic mode tests} {
    chmod 000     CHMOD.TMP
    chmod u+x,g+x CHMOD.TMP
    GetMode       CHMOD.TMP
} 0 {110}

Test chmod-3.8 {chmod symbolic mode tests} {
    chmod 000     {CHMOD.TMP CHMOD2.TMP}
    chmod u+x,g+x {CHMOD.TMP CHMOD2.TMP}
    chmod u-x,g-x {CHMOD.TMP CHMOD2.TMP}
    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} 0 {0 0}

# Can't +s on some systems

if [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
    Test chmod-3.9 {chmod symbolic mode tests} {
        chmod 000        CHMOD.TMP
        chmod ugo+x,ug+s CHMOD.TMP
        GetMode          CHMOD.TMP
    } 0 {6111}
}

Test chmod-3.10 {chmod symbolic mode tests} {
    chmod 000   CHMOD.TMP
    chmod a+rwx CHMOD.TMP
    GetMode     CHMOD.TMP
} 0 {777}

Test chmod-3.11 {chmod symbolic mode tests} {
    chmod 000   CHMOD.TMP
    chmod a+rwx CHMOD.TMP
    chmod a-rw  CHMOD.TMP
    GetMode     CHMOD.TMP
} 0 {111}

Test chmod-3.12 {chmod symbolic mode tests} {
    chmod 000   CHMOD.TMP
    chmod a=rwx CHMOD.TMP
    GetMode     CHMOD.TMP
} 0 {777}

Test chmod-3.13 {chmod symbolic mode tests} {
    chmod 000         CHMOD.TMP
    chmod u=rwx,go=rx CHMOD.TMP
    GetMode           CHMOD.TMP
} 0 {755}

if [infox have_fchmod] {
    Test chmod-3.14 {chmod symbolic mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 000 $fh
        chmod -fileid +r  $fh
        close $fh
        GetMode   CHMOD.TMP
    } 0 {444}

    Test chmod-3.2 {chmod symbolic mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 000 $fh
        chmod -fileid +r  $fh
        chmod -fileid +w  $fh
        close $fh
        GetMode   CHMOD.TMP
    } 0 {666}

    Test chmod-3.15 {chmod symbolic mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 000 $fh
        chmod -fileid +r  $fh
        chmod -fileid +w  $fh
        chmod -fileid +x  $fh
        close $fh
        GetMode   CHMOD.TMP
    } 0 {777}

    Test chmod-3.16 {chmod symbolic mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 000 $fh
        chmod -fileid +r  $fh
        chmod -fileid +w  $fh
        chmod -fileid +x  $fh
        chmod -fileid -r  $fh
        close $fh
        GetMode   CHMOD.TMP
    } 0 {333}

    Test chmod-3.17 {chmod symbolic mode tests} {
        chmod 0600 CHMOD.TMP
        set fh [open CHMOD.TMP w]
        chmod -fileid 000 $fh
        chmod -fileid +r  $fh
        chmod -fileid +w  $fh
        chmod -fileid +x  $fh
        chmod -fileid -r  $fh
        chmod -fileid -w  $fh
        close $fh
        GetMode   CHMOD.TMP
    } 0 {111}
}

# +t is dificult to test if not root, just make sure it execute and hope
# for the best.  Doesn't even work on some systems

if [CheckChmod "u+t" "----------" "---------T"] {

    Test chmod-3.14 {chmod symbolic mode tests} {
        chmod 000 CHMOD.TMP
        chmod u+x CHMOD.TMP
        chmod u+t CHMOD.TMP
        set mode [GetMode CHMOD.TMP]
        expr "($mode == 100) || ($mode == 1100)"
    } 0 {1}

    Test chmod-3.14 {chmod symbolic mode tests} {
        chmod 000 CHMOD.TMP
        chmod u+x CHMOD.TMP
        chmod u+t CHMOD.TMP
    } 0 {}

    Test chmod-3.15 {chmod symbolic mode tests} {
        chmod 000   CHMOD.TMP
        chmod u+x   CHMOD.TMP
        chmod u+t   CHMOD.TMP
        chmod u-t   CHMOD.TMP
    } 0 {}
}

Test chmod-3.16 {chmod symbolic mode tests} {
    chmod 000         CHMOD.TMP
    chmod a+rwx       CHMOD.TMP
    chmod u-r,g-w,o-x CHMOD.TMP
    GetMode           CHMOD.TMP
} 0 {356}

Test chmod-4.1 {chmod error tests} {
    chmod +z CHMOD.TMP
} 1 {invalid file mode "+z"}

Test chmod-4.2 {chmod error tests} {
    chmod
} 1 {wrong # args: chmod [-fileid] mode filelist}

if [infox have_fchmod] {
    Test chmod-4.3 {chmod error tests} {
        chmod -fileid +w BAD
    } 1 {can not find channel named "BAD"}

    Test chmod-4.4 {chmod error tests} {
        chmod -file -w CHMOD.TMP
    } 1 {wrong # args: chmod [-fileid] mode filelist}
}

# chown and chgrp tests

set myUID [id userid]
set myGID [id groupid]


#
# Some machines have problems with changing group ids on files (even to your
# own) if you are not root. On some it works for chown but not fchown (Ultix).
#

SetUpTestFiles

set broken_chown 0
if {[catch {chown [id userid]  CHMOD.TMP} msg ] ||
    [catch {chgrp [id groupid] CHMOD.TMP} msg ]} {
    puts "********************************************************************"
    puts "Can't do chown or chgrp even when current and new group id are"
    puts "ours.  You probably have to be root.  Some chown/chgrp tests skipped"
    puts "on this system."
    puts "    $msg"
    puts "********************************************************************"
    set broken_chown 1
}

set broken_fchown 0
if [infox have_fchown] {
    set fh [open CHMOD.TMP w]
    if {[catch {chown -fileid [id userid]  $fh} msg ] ||
        [catch {chgrp -fileid [id groupid] $fh} msg ]} {
        puts "********************************************************************"
        puts "Can't do chown or chgrp with -fileid even when current and new"
        puts "groupid are ours. You probably have to be root. Some chown/chgrp"
        puts "tests skipped on this system."
        puts "    $msg"
        puts "********************************************************************"
        set broken_fchown 1
    }
    close $fh
}

if !$broken_chown {
    Test chmod-5.1 {chown tests} {
        SetUpTestFiles
        chown [id user] {CHMOD.TMP CHMOD2.TMP}
        list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
    } 0 [list $myUID $myUID]

    Test chmod-5.2 {chown tests} {
        chown [id userid] {CHMOD.TMP CHMOD2.TMP}
        list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
    } 0 [list $myUID $myUID]

    Test chmod-5.3 {chown tests} {
        chown [list [id userid] [id groupid]] {CHMOD.TMP CHMOD2.TMP}
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]

    Test chmod-5.4 {chown tests} {
        chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]

    Test chmod-5.5 {chown tests} {
        chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]
}

if {[infox have_fchown] && !$broken_fchown} {
    Test chmod-5.6 {chown tests} {
        SetUpTestFiles
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chown -fileid [id user] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
    } 0 [list $myUID $myUID]

    Test chmod-5.7 {chown tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chown -fileid [id userid] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
    } 0 [list $myUID $myUID]

    Test chmod-5.8 {chown tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chown -fileid [list [id userid] [id groupid]] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]

    Test chmod-5.9 {chown tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]

    Test chmod-5.10 {chown tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
    } 0 [list [list $myUID $myGID] [list $myUID $myGID]]
}

SetUpTestFiles

Test chmod-6.1 {chown error tests} {
    chown XXXXXXXXX CHMOD.TMP
} 1 {unknown user id: XXXXXXXXX}

Test chmod-6.2 {chown error tests} {
    chown [list XXXXXXXXX [id groupid]] CHMOD.TMP
} 1 {unknown user id: XXXXXXXXX}

Test chmod-6.3 {chown error tests} {
    chown [list [id user] XXXXXXXXX] CHMOD.TMP
} 1 {unknown group id: XXXXXXXXX}

Test chmod-6.4 {chown error tests} {
    chown {XXXXXXXXX YYYY} CHMOD.TMP
} 1 {unknown user id: XXXXXXXXX}

Test chmod-6.5 {chown error tests} {
    chown
} 1 {wrong # args: chown [-fileid] user|{user group} filelist}

if [infox have_fchown] {
    Test chmod-6.6 {chown error tests} {
        chown -fileid $myUID BAD
    } 1 {can not find channel named "BAD"}

    Test chmod-6.6 {chown error tests} {
        chown -fid $myUID CHMOD.TMP
    } 1 {Invalid option "-fid", expected "-fileid"}
}

if !$broken_chown {
    Test chmod-7.1 {chgrp tests} {
        chgrp [id group]  {CHMOD.TMP CHMOD2.TMP}
        list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
    } 0 [list $myGID $myGID]

    Test chmod-7.2 {chgrp tests} {
        chgrp [id groupid] {CHMOD.TMP CHMOD2.TMP}
        list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
    } 0 [list $myGID $myGID]
}

if {[infox have_fchown] && !$broken_fchown} {
    Test chmod-7.3 {chgrp tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chgrp -fileid [id group] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
    } 0 [list $myGID $myGID]

    Test chmod-7.4 {chgrp tests} {
        set fh1 [open CHMOD.TMP w]
        set fh2 [open CHMOD2.TMP w]
        chgrp -fileid [id groupid] [list $fh1 $fh2]
        close $fh1
        close $fh2
        list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
    } 0 [list $myGID $myGID]
}

Test chmod-8.1 {chgrp error tests} {
    chgrp
} 1 {wrong # args: chgrp [-fileid] group filelist}

Test chmod-8.2 {chgrp error tests} {
    chgrp XXXXXXXXX CHMOD.TMP
} 1 {unknown group id: XXXXXXXXX}

if [infox have_fchown] {
    Test chmod-8.3 {chown error tests} {
        chgrp -fileid $myGID BAD
    } 1 {can not find channel named "BAD"}

    Test chmod-8.4 {chown error tests} {
        chgrp -fid $myGID CHMOD.TMP
    } 1 {Invalid option "-fid", expected "-fileid"}
}


TestRemove CHECK.TMP CHMOD.TMP CHMOD2.TMP

# If this is a TclX development system, then give a warning about skipped
# tests.

if {[file exists RCS] && ($chmodTestsSkipped > 0)} {
    puts "WARNING: $chmodTestsSkipped chmod tests skipped due to system strangeness"
}


