# # 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.2 2002/04/02 02:29:43 hobbs Exp $ #------------------------------------------------------------------------------ # if {[cequal [info procs Test] {}]} { source [file join [file dirname [info script]] testlib.tcl] } # # Fork without exec will not work under Tk, skip this test # if {[info exists tk_version]} { puts "****************************************************************" puts "Unix commmands tests require fork, which does not work under Tk." puts "Test skipped." 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} {unixOnly} { 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 } {1 1 1} test unixcmds-1.2 {link tests} unixOnly { list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg] } {1 {linking "link1.tmp" to "link2.tmp" failed: no such file or directory}} test unixcmds-1.3 {link tests} { list [catch {link} msg] $msg } {1 {wrong # args: link ?-sym? srcpath destpath}} # Test -sym only if we have symbolic links. test unixcmds-1.4 {link tests} {need_symlink} { 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 } {LINK1.TMP} test unixcmds-1.4 {link tests} {pcOnly} { link LINK1.TMP LINK2.TMP } {1 {link is not available on MS Windows}} # Test the times command (the best we can). test unixcmds-3.1 {times tests} {unixOnly} { llength [times] } 4 test unixcmds-3.2 {times tests} {unixOnly} { list [catch {times foo} msg] $msg } {1 {wrong # args: times}} # Test umask command. test unixcmds-4.1 {umask tests} {unixOnly} { set oldMask [umask] umask 666 set newMask [umask] umask $oldMask set newMask } 666 test unixcmds-4.2 {umask tests} { list [catch {umask 999} msg] $msg } {1 {Expected octal number got: 999}} test unixcmds-4.3 {umask tests} { list [catch {umask 7 7} msg] $msg } {1 {wrong # args: umask ?octalmask?}} # Test the system command test unixcmds-5.1 {system tests} {unixOnly} { system "ls / >/dev/null" } 0 test unixcmds-5.1.1 {system tests} {unixOnly} { system ls / >/dev/null } 0 test unixcmds-5.2 {system tests} {unixOnly} { list [catch {system} msg] $msg } {1 {wrong # args: system cmdstr1 ?cmdstr2...?}} test unixcmds-5.3 {system tests} {unixOnly} { system exit 3 } 3 test unixcmds-5.4 {system tests} {unixOnly} { system "exit 3" } 3 test unixcmds-5.5 {system tests} {unixOnly} { system "exit 101" } 101 # Test the sleep command, as well as we can. test unixcmds-6.1 {sleep tests} { sleep 1 } {} test unixcmds-6.2 {sleep tests} { list [catch {sleep} msg] $msg } {1 {wrong # args: sleep seconds}} test unixcmds-6.3 {sleep tests} { list [catch {sleep 1 2} msg] $msg } {1 {wrong # args: sleep seconds}} # cleanup ::tcltest::cleanupTests return