home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / unixcmds.test < prev   
Encoding:
Text File  |  1994-01-23  |  6.0 KB  |  232 lines

  1. #
  2. # unixcmds.test
  3. #
  4. # Tests for the link, unlink, times, umask, system and sleep commands.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1993 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 3.2 1994/01/23 16:58:20 markd Exp $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. #
  22. # Fork without exec will not work under Tk, skip this test
  23. #
  24. if ![lempty [info commands button]] {
  25.     puts stderr "*************************************************************"
  26.     puts stderr "Unix commmands tests are constructed in a way that does not"
  27.     puts stderr "work under Tk.  Test skipped."
  28.     puts stderr "*************************************************************"
  29.     puts stderr ""
  30.     return
  31. }
  32.  
  33.  
  34. # Proc to create a small file.
  35.  
  36. proc TestCreate {fname} {
  37.     set fh [open $fname w]
  38.     puts $fh "Hello, world"
  39.     close $fh
  40. }
  41.  
  42. # Test link and unlink commands.
  43.  
  44. Test unixcmds-1.1 {link and unlink tests} {
  45.     unlink -nocomplain LINK2.TMP
  46.     TestCreate LINK1.TMP
  47.     link LINK1.TMP LINK2.TMP
  48.     catch {unset stat}
  49.     file stat LINK1.TMP stat
  50.     set ino1 $stat(ino)
  51.     set dev1 $stat(dev)
  52.     file stat LINK2.TMP stat
  53.     set ino2 $stat(ino)
  54.     set dev2 $stat(dev)
  55.     set result [list [file exists LINK2.TMP] [expr $ino1==$ino2] \
  56.                      [expr $dev1==$dev2]]
  57.     unlink {LINK1.TMP LINK2.TMP}
  58.     set result
  59. } 0 {1 1 1}
  60.  
  61. Test unixcmds-1.2 {link and unlink tests} {
  62.     list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg]
  63. } 0 {1 {no such file or directory}}
  64.  
  65. Test unixcmds-1.3 {link and unlink tests} {
  66.     link
  67. } 1 {wrong # args: link ?-sym? srcpath destpath}
  68.  
  69. # Test -sym only if we have symbolic links.
  70.  
  71. catch {link -sym doesNotExist doesNotExist2} msg
  72. unlink -nocomplain doesNotExist2
  73. set haveSymLinks 1
  74. if {$msg == "symbolic links are not supported on this system"} {
  75.     set haveSymLinks 0
  76. }
  77.  
  78. if $haveSymLinks {
  79.     Test unixcmds-1.4 {link and unlink tests} {
  80.         unlink -nocomplain LINK2.TMP
  81.         TestCreate LINK1.TMP
  82.         link -sym LINK1.TMP LINK2.TMP
  83.         catch {unset stat}
  84.         set result [file readlink LINK2.TMP]
  85.         unlink {LINK1.TMP LINK2.TMP}
  86.         set result
  87.     } 0 {LINK1.TMP}
  88. }
  89.  
  90. # Test unlink command.
  91.  
  92. Test unixcmds-2.1 {link and unlink tests} {
  93.     set fh [open UNLINK.TMP w]
  94.     puts $fh "Hello, world"
  95.     close $fh
  96.     unlink UNLINK.TMP
  97.     file exists UNLINK.TMP
  98. } 0 0
  99.  
  100. Test unixcmds-2.2 {link and unlink tests} {
  101.     list [catch {unlink UNLINK.TMP} msg] [string tolower $msg]
  102. } 0 {1 {unlink.tmp: no such file or directory}}
  103.  
  104. Test unixcmds-2.3 {link and unlink tests} {
  105.     unlink
  106. } 1 {wrong # args: unlink ?-nocomplain? filelist}
  107.  
  108. Test unixcmds-2.4 {link and unlink tests} {
  109.     set fh [open UNLINK.TMP w]
  110.     puts $fh "Hello, world"
  111.     close $fh
  112.     unlink -nocomplain {../src/FOOWAPFOO UNLINK.TMP}
  113.     file exists UNLINK.TMP
  114. } 0 0
  115.  
  116. # Test the times command (the best we can).
  117.  
  118. Test unixcmds-3.1 {times tests} {
  119.     llength [times]
  120. } 0 4
  121.  
  122. Test unixcmds-3.2 {times tests} {
  123.     times foo
  124. } 1 {wrong # args: times}
  125.  
  126. # Test umask command.
  127.  
  128. Test unixcmds-4.1 {umask tests} {
  129.     set oldMask [umask]
  130.     umask 666
  131.     set newMask [umask]
  132.     umask $oldMask
  133.     set newMask
  134. } 0 666
  135.  
  136. Test unixcmds-4.2 {umask tests} {
  137.     umask 999
  138. } 1 {Expected octal number got: 999}
  139.  
  140. Test unixcmds-4.3 {umask tests} {
  141.     umask 7 7
  142. } 1 {wrong # args: umask ?octalmask?}
  143.  
  144. # Test the system command
  145.  
  146. Test unixcmds-5.1 {system tests} {
  147.     system "ls / >/dev/null"
  148. } 0 0
  149.  
  150. Test unixcmds-5.2 {system tests} {
  151.     system
  152. } 1 {wrong # args: system command}
  153.  
  154. Test unixcmds-5.3 {system tests} {
  155.     system x y z
  156. } 1 {wrong # args: system command}
  157.  
  158. Test unixcmds-5.4 {system tests} {
  159.     system "exit 3"
  160. } 0 3
  161.  
  162. Test unixcmds-5.5 {system tests} {
  163.     system "exit 101"
  164. } 0 101
  165.  
  166. # Test the sleep command, as well as we can.
  167.  
  168. Test unixcmds-6.1 {sleep tests} {
  169.     sleep 1
  170. } 0 {}
  171.  
  172. Test unixcmds-6.2 {sleep tests} {
  173.     sleep
  174. } 1 {wrong # args: sleep seconds}
  175.  
  176. Test unixcmds-6.3 {sleep tests} {
  177.     sleep 1 2
  178. } 1 {wrong # args: sleep seconds}
  179.  
  180. # Test mkdir and rmdir commands.
  181.  
  182. Test unixcmds-7.1 {mkdir and rmdir tests} {
  183.     catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  184.     mkdir {MKDIR1.TMP MKDIR2.TMP}
  185.     set result [list [file isdirectory MKDIR1.TMP] \
  186.                      [file isdirectory MKDIR2.TMP]]
  187.     catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  188.     set result
  189. } 0 {1 1}
  190.  
  191. Test unixcmds-7.2 {mkdir and rmdir tests} {
  192.     catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  193.     mkdir -path MKDIR1.TMP/a/b/c
  194.     set result [file isdirectory MKDIR1.TMP/a/b/c] 
  195.     catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  196.     set result
  197. } 0 1
  198.  
  199. Test unixcmds-7.3 {mkdir and rmdir tests} {
  200.     catch {mkdir {MKDIR1.TMP MKDIR2.TMP}}
  201.     rmdir {MKDIR1.TMP MKDIR2.TMP}
  202.     list [file isdirectory MKDIR1.TMP] [file isdirectory MKDIR2.TMP]
  203. } 0 {0 0}
  204.  
  205. Test unixcmds-7.4 {mkdir and rmdir tests} {
  206.     catch {mkdir MKDIR1.TMP}
  207.     set result [list [catch {mkdir MKDIR1.TMP} msg] [string tolower $msg]]
  208.     catch {rmdir MKDIR1.TMP}
  209.     set result
  210. } 0 {1 {mkdir1.tmp: file exists}}
  211.  
  212. Test unixcmds-7.5 {mkdir and rmdir tests} {
  213.     mkdir
  214. } 1 {wrong # args: mkdir ?-path? dirlist}
  215.  
  216. Test unixcmds-7.6 {mkdir and rmdir tests} {
  217.     catch {rmdir MKDIR1.TMP}
  218.     set result [list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]]
  219.     set result
  220. } 0 {1 {mkdir1.tmp: no such file or directory}}
  221.  
  222. Test unixcmds-7.7 {mkdir and rmdir tests} {
  223.     catch {rmdir MKDIR1.TMP}
  224.     rmdir -nocomplain MKDIR1.TMP
  225. } 0 {}
  226.  
  227. Test unixcmds-7.8 {mkdir and rmdir tests} {
  228.     rmdir
  229. } 1 {wrong # args: rmdir ?-nocomplain? dirlist}
  230.  
  231.  
  232.