home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / tests / cd.test < prev    next >
Text File  |  1993-10-07  |  4KB  |  122 lines

  1. # Commands covered:  cd, pwd
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/cd.test,v 1.21 93/10/07 17:21:21 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. catch {exec rm -rf cd.dir}
  32. exec mkdir cd.dir
  33. exec cat << "Sample text" > cd.dir/test.file
  34. set cwd [exec pwd]
  35.  
  36. test cd-1.1 {simple pwd check} {
  37.     pwd
  38. } $cwd
  39.  
  40. cd cd.dir
  41. if $atBerkeley {
  42.     test cd-2.1 {changing directories} {
  43.     list [exec pwd]
  44.     } $cwd/cd.dir
  45.     test cd-2.2 {changing directories} {
  46.     pwd
  47.     } $cwd/cd.dir
  48. }
  49. test cd-2.3 {changing directories} {
  50.     exec cat test.file
  51. } "Sample text"
  52. cd ..
  53. test cd-2.4 {changing directories} {
  54.     exec pwd 
  55. } $cwd
  56. test cd-2.5 {changing directories} {
  57.     pwd 
  58. } $cwd
  59. test cd-2.6 {changing directories} {
  60.     exec cat cd.dir/test.file
  61. } "Sample text"
  62.  
  63. # The tests below seem to fail on lots of machines for a variety
  64. # of reasons, such as the auto-mounter, home directories that are
  65. # symbolic links, etc.
  66.  
  67. if $atBerkeley {
  68.     set home [exec sh -c "cd; pwd"]
  69.     test cd-2.7 {changing directories} {
  70.     cd ~
  71.     set x [list [exec pwd] [pwd]]
  72.     cd $cwd
  73.     set x
  74.     } "$home $home"
  75.     test cd-2.8 {changing directories} {
  76.     cd
  77.     set x [list [exec pwd] [pwd]]
  78.     cd $cwd
  79.     set x
  80.     } "$home $home"
  81. }
  82.  
  83. test cd-3.1 {cd return value} {
  84.     cd .
  85. } {}
  86.  
  87. test cd-4.1 {errors in cd command} {
  88.     list [catch {cd 1 2} msg] $msg $errorCode
  89. } {1 {wrong # args: should be "cd dirName"} NONE}
  90. test cd-4.2 {errors in cd command} {
  91.     string tolower [list [catch {cd _bad_dir} msg] $msg $errorCode]
  92. } {1 {couldn't change working directory to "_bad_dir": no such file or directory} {posix enoent {no such file or directory}}}
  93. test cd-4.3 {errors in cd command} {
  94.     string tolower [list [catch {cd cd.dir/test.file} msg] $msg $errorCode]
  95. } {1 {couldn't change working directory to "cd.dir/test.file": not a directory} {posix enotdir {not a directory}}}
  96. test cd-4.4 {errors in cd command} {
  97.     set home $env(HOME)
  98.     unset env(HOME)
  99.     set x [list [catch cd msg] $msg]
  100.     set env(HOME) $home
  101.     set x
  102. } {1 {couldn't find HOME environment variable to expand "~"}}
  103.  
  104. test cd-5.1 {errors in pwd command} {
  105.     list [catch {pwd a} msg] $msg
  106. } {1 {wrong # args: should be "pwd"}}
  107. if $atBerkeley {
  108.     exec mkdir cd.dir/child
  109.     cd cd.dir/child
  110.     exec chmod 111 ..
  111.     if {$user != "root"} {
  112.     test cd-5.2 {errors in pwd command} {
  113.         catch pwd msg
  114.     } 1
  115.     }
  116.     cd $cwd
  117.     exec chmod 775 cd.dir
  118. }
  119.  
  120. catch {exec rm -rf cd.dir}
  121. format ""
  122.