home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tclX6.5c / tests / unixcmds.test < prev    next >
Encoding:
Text File  |  1992-12-19  |  5.5 KB  |  212 lines

  1. #
  2. # unixcmds.test
  3. #
  4. # Tests for the link, unlink, times, umask, system and sleep commands.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: unixcmds.test,v 2.0 1992/10/16 04:50:19 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21.  
  22. # Proc to create a small file.
  23.  
  24. proc TestCreate {fname} {
  25.     set fh [open $fname w]
  26.     puts $fh "Hello, world"
  27.     close $fh
  28. }
  29.  
  30. # Test link and unlink commands.
  31.  
  32. Test unixcmds-1.1 {link and unlink tests} {
  33.     unlink -nocomplain LINK2.TMP
  34.     TestCreate LINK1.TMP
  35.     link LINK1.TMP LINK2.TMP
  36.     catch {unset stat}
  37.     file stat LINK1.TMP stat
  38.     set ino1 $stat(ino)
  39.     set dev1 $stat(dev)
  40.     file stat LINK2.TMP stat
  41.     set ino2 $stat(ino)
  42.     set dev2 $stat(dev)
  43.     set result [list [file exists LINK2.TMP] [expr $ino1==$ino2] \
  44.                      [expr $dev1==$dev2]]
  45.     unlink {LINK1.TMP LINK2.TMP}
  46.     set result
  47. } 0 {1 1 1}
  48.  
  49. Test unixcmds-1.2 {link and unlink tests} {
  50.     list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg]
  51. } 0 {1 {no such file or directory}}
  52.  
  53. Test unixcmds-1.3 {link and unlink tests} {
  54.     link
  55. } 1 {wrong # args: link [-sym] srcpath destpath}
  56.  
  57. # Test -sym only if we have symbolic links.
  58.  
  59. catch {link -sym doesNotExist doesNotExist2} msg
  60. unlink -nocomplain doesNotExist2
  61. set haveSymLinks 1
  62. if {$msg == "symbolic links are not supported on this system"} {
  63.     set haveSymLinks 0
  64. }
  65.  
  66. if $haveSymLinks {
  67.     Test unixcmds-1.4 {link and unlink tests} {
  68.         unlink -nocomplain LINK2.TMP
  69.         TestCreate LINK1.TMP
  70.         link -sym LINK1.TMP LINK2.TMP
  71.         catch {unset stat}
  72.         set result [file readlink LINK2.TMP]
  73.         unlink {LINK1.TMP LINK2.TMP}
  74.         set result
  75.     } 0 {LINK1.TMP}
  76. }
  77.  
  78. # Test unlink command.
  79.  
  80. Test unixcmds-2.1 {link and unlink tests} {
  81.     set fh [open UNLINK.TMP w]
  82.     puts $fh "Hello, world"
  83.     close $fh
  84.     unlink UNLINK.TMP
  85.     file exists UNLINK.TMP
  86. } 0 0
  87.  
  88. Test unixcmds-2.2 {link and unlink tests} {
  89.     list [catch {unlink UNLINK.TMP} msg] [string tolower $msg]
  90. } 0 {1 {unlink.tmp: no such file or directory}}
  91.  
  92. Test unixcmds-2.3 {link and unlink tests} {
  93.     unlink
  94. } 1 {wrong # args: unlink [-nocomplain] filelist}
  95.  
  96. Test unixcmds-2.4 {link and unlink tests} {
  97.     set fh [open UNLINK.TMP w]
  98.     puts $fh "Hello, world"
  99.     close $fh
  100.     unlink -nocomplain {../src/FOOWAPFOO UNLINK.TMP}
  101.     file exists UNLINK.TMP
  102. } 0 0
  103.  
  104. # Test the times command (the best we can).
  105.  
  106. Test unixcmds-3.1 {times tests} {
  107.     llength [times]
  108. } 0 4
  109.  
  110. Test unixcmds-3.2 {times tests} {
  111.     times foo
  112. } 1 {wrong # args: times}
  113.  
  114. # Test umask command.
  115.  
  116. Test unixcmds-4.1 {umask tests} {
  117.     set oldMask [umask]
  118.     umask 666
  119.     set newMask [umask]
  120.     umask $oldMask
  121.     set newMask
  122. } 0 666
  123.  
  124. Test unixcmds-4.2 {umask tests} {
  125.     umask 999
  126. } 1 {Expected octal number got: 999}
  127.  
  128. Test unixcmds-4.3 {umask tests} {
  129.     umask 7 7
  130. } 1 {wrong # args: umask octalmask}
  131.  
  132. # Test the system command
  133.  
  134. Test unixcmds-5.1 {system tests} {
  135.     system "ls / >/dev/null"
  136. } 0 0
  137.  
  138. Test unixcmds-5.2 {system tests} {
  139.     system
  140. } 1 {wrong # args: system command}
  141.  
  142. Test unixcmds-5.3 {system tests} {
  143.     system x y z
  144. } 1 {wrong # args: system command}
  145.  
  146. # Test the sleep command, as well as we can.
  147.  
  148. Test unixcmds-6.1 {sleep tests} {
  149.     sleep 1
  150. } 0 {}
  151.  
  152. Test unixcmds-6.2 {sleep tests} {
  153.     sleep
  154. } 1 {wrong # args: sleep seconds}
  155.  
  156. Test unixcmds-6.3 {sleep tests} {
  157.     sleep 1 2
  158. } 1 {wrong # args: sleep seconds}
  159.  
  160. # Test mkdir and rmdir commands.
  161.  
  162. Test unixcmds-7.1 {mkdir and rmdir tests} {
  163.     catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  164.     mkdir {MKDIR1.TMP MKDIR2.TMP}
  165.     set result [list [file isdirectory MKDIR1.TMP] \
  166.                      [file isdirectory MKDIR2.TMP]]
  167.     catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  168.     set result
  169. } 0 {1 1}
  170.  
  171. Test unixcmds-7.2 {mkdir and rmdir tests} {
  172.     catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  173.     mkdir -path MKDIR1.TMP/a/b/c
  174.     set result [file isdirectory MKDIR1.TMP/a/b/c] 
  175.     catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  176.     set result
  177. } 0 1
  178.  
  179. Test unixcmds-7.3 {mkdir and rmdir tests} {
  180.     catch {mkdir {MKDIR1.TMP MKDIR2.TMP}}
  181.     rmdir {MKDIR1.TMP MKDIR2.TMP}
  182.     list [file isdirectory MKDIR1.TMP] [file isdirectory MKDIR2.TMP]
  183. } 0 {0 0}
  184.  
  185. Test unixcmds-7.4 {mkdir and rmdir tests} {
  186.     catch {mkdir MKDIR1.TMP}
  187.     set result [list [catch {mkdir MKDIR1.TMP} msg] [string tolower $msg]]
  188.     catch {rmdir MKDIR1.TMP}
  189.     set result
  190. } 0 {1 {mkdir1.tmp: file exists}}
  191.  
  192. Test unixcmds-7.5 {mkdir and rmdir tests} {
  193.     mkdir
  194. } 1 {wrong # args: mkdir [-path] dirlist}
  195.  
  196. Test unixcmds-7.6 {mkdir and rmdir tests} {
  197.     catch {rmdir MKDIR1.TMP}
  198.     set result [list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]]
  199.     set result
  200. } 0 {1 {mkdir1.tmp: no such file or directory}}
  201.  
  202. Test unixcmds-7.7 {mkdir and rmdir tests} {
  203.     catch {rmdir MKDIR1.TMP}
  204.     rmdir -nocomplain MKDIR1.TMP
  205. } 0 {}
  206.  
  207. Test unixcmds-7.8 {mkdir and rmdir tests} {
  208.     rmdir
  209. } 1 {wrong # args: rmdir [-nocomplain] dirlist}
  210.  
  211.  
  212.