#
# unixcmds.test
#
# Tests for the link, times, umask, system and sleep 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: unixcmds.test,v 1.1.1.1 1999/06/28 20:35:29 damon Exp $
#------------------------------------------------------------------------------
#

if {[info procs test] != "test"} then {source testlib.tcl}

#
# Fork without exec will not work under Tk, skip this test
#
if ![lempty [info commands button]] {
    puts "*************************************************************"
    puts "Unix commmands tests are constructed in a way that does not"
    puts "work under Tk.  Test skipped."
    puts "*************************************************************"
    puts ""
    return
}

TestRemove MKDIR1.TMP MKDIR2.TMP

# Proc to create a small file.

proc TestCreate {fname} {
    set fh [open $fname w]
    puts $fh "Hello, world"
    close $fh
}

# Test the link command.

Test unixcmds-1.1 {link tests} {
    TestRemove LINK2.TMP
    TestCreate LINK1.TMP
    link LINK1.TMP LINK2.TMP
    catch {unset stat}
    file stat LINK1.TMP stat
    set ino1 $stat(ino)
    set dev1 $stat(dev)
    file stat LINK2.TMP stat
    set ino2 $stat(ino)
    set dev2 $stat(dev)
    set result [list [file exists LINK2.TMP] [expr $ino1==$ino2] \
                     [expr $dev1==$dev2]]
    TestRemove LINK1.TMP LINK2.TMP
    set result
} 0 {1 1 1} {unixOnly}

Test unixcmds-1.2 {link tests} {
    list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg]
} 0 {1 {linking "link1.tmp" to "link2.tmp" failed: no such file or directory}} {unixOnly}

Test unixcmds-1.3 {link tests} {
    link
} 1 {wrong # args: link ?-sym? srcpath destpath}

# Test -sym only if we have symbolic links.

if [infox have_symlink] {
    Test unixcmds-1.4 {link tests} {
        TestRemove LINK2.TMP
        TestCreate LINK1.TMP
        link -sym LINK1.TMP LINK2.TMP
        catch {unset stat}
        set result [file readlink LINK2.TMP]
        TestRemove LINK1.TMP LINK2.TMP
        set result
    } 0 {LINK1.TMP} {unixOnly}
}

Test unixcmds-1.4 {link tests} {
    link LINK1.TMP LINK2.TMP
} 1 {link is not available on MS Windows} {pcOnly}

# Test the times command (the best we can).

if [cequal $tcl_platform(platform) windows] { ;# WIN32???
    echo "    * The times command has not been ported to Win32" 
} else {

Test unixcmds-3.1 {times tests} {
    llength [times]
} 0 4

Test unixcmds-3.2 {times tests} {
    times foo
} 1 {wrong # args: times}
}

# Test umask command.

Test unixcmds-4.1 {umask tests} {
    set oldMask [umask]
    umask 666
    set newMask [umask]
    umask $oldMask
    set newMask
} 0 666 {unixOnly}

Test unixcmds-4.2 {umask tests} {
    umask 999
} 1 {Expected octal number got: 999}

Test unixcmds-4.3 {umask tests} {
    umask 7 7
} 1 {wrong # args: umask ?octalmask?}

if [cequal $tcl_platform(platform) windows] { ;# WIN32???
    echo "    * Note: The system command has not been ported to Win32" 
}

# Test the system command

Test unixcmds-5.1 {system tests} {
    system "ls / >/dev/null"
} 0 0 {unixOnly}

Test unixcmds-5.1.1 {system tests} {
    system ls / >/dev/null
} 0 0 {unixOnly}

Test unixcmds-5.2 {system tests} {
    system
} 1 {wrong # args: system cmdstr1 ?cmdstr2...?}

Test unixcmds-5.3 {system tests} {
    system exit 3
} 0 3 {unixOnly}

Test unixcmds-5.4 {system tests} {
    system "exit 3"
} 0 3 {unixOnly}

Test unixcmds-5.5 {system tests} {
    system "exit 101"
} 0 101 {unixOnly}

# Test the sleep command, as well as we can.

Test unixcmds-6.1 {sleep tests} {
    sleep 1
} 0 {}

Test unixcmds-6.2 {sleep tests} {
    sleep
} 1 {wrong # args: sleep seconds}

Test unixcmds-6.3 {sleep tests} {
    sleep 1 2
} 1 {wrong # args: sleep seconds}



