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

  1. # Commands covered:  glob
  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/glob.test,v 1.23 93/08/28 15:57:40 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. # First, create some subdirectories to use for testing.
  32.  
  33. exec rm -rf globTest
  34. exec mkdir globTest globTest/a1 globTest/a2 globTest/a3
  35. exec mkdir globTest/a1/b1 globTest/a1/b2 globTest/a2/b3
  36. exec cat << abc > globTest/x1.c
  37. exec cat << abc > globTest/y1.c
  38. exec cat << abc > globTest/z1.c
  39. exec cat << abc > "globTest/weird name.c"
  40. exec cat << abc > globTest/.1
  41. exec cat << abc > globTest/a1/b1/x2.c
  42. exec cat << abc > globTest/a1/b2/y2.c
  43.  
  44. test glob-1.1 {simple globbing} {
  45.     lsort [glob globTest/x1.c globTest/y1.c globTest/foo]
  46. } {globTest/x1.c globTest/y1.c}
  47. test glob-1.2 {simple globbing} {
  48.     glob {}
  49. } .
  50.  
  51. test glob-2.1 {globbing with braces} {
  52.     glob -nocomplain "{a1,a2}"
  53. } {}
  54. test glob-2.2 {globbing with braces} {
  55.     lsort [glob globTest/{a,b,x,y}1.c]
  56. } {globTest/x1.c globTest/y1.c}
  57. test glob-2.3 {globbing with braces} {
  58.     lsort [glob {globTest/{x1,y2,weird name}.c}]
  59. } {{globTest/weird name.c} globTest/x1.c}
  60. test glob-2.4 {globbing with braces} {
  61.     lsort [glob globTest/{x1.c,a1/*}]
  62. } {globTest/a1/b1 globTest/a1/b2 globTest/x1.c}
  63.  
  64. test glob-3.1 {asterisks, question marks, and brackets} {
  65.     lsort [glob g*/*.c]
  66. } {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  67. test glob-3.2 {asterisks, question marks, and brackets} {
  68.     lsort [glob globTest/?1.c]
  69. } {globTest/x1.c globTest/y1.c globTest/z1.c}
  70. test glob-3.3 {asterisks, question marks, and brackets} {
  71.     lsort [glob */*/*/*.c]
  72. } {globTest/a1/b1/x2.c globTest/a1/b2/y2.c}
  73. test glob-3.4 {asterisks, question marks, and brackets} {
  74.     lsort [glob globTest/*]
  75. } {globTest/a1 globTest/a2 globTest/a3 {globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  76. test glob-3.5 {asterisks, question marks, and brackets} {
  77.     lsort [glob globTest/.*]
  78. } {globTest/. globTest/.. globTest/.1}
  79. test glob-3.6 {asterisks, question marks, and brackets} {
  80.     lsort [glob globTest/*/*]
  81. } {globTest/a1/b1 globTest/a1/b2 globTest/a2/b3}
  82. test glob-3.7 {asterisks, question marks, and brackets} {
  83.     lsort [glob {globTest/[xyab]1.*}]
  84. } {globTest/x1.c globTest/y1.c}
  85. test glob-3.8 {asterisks, question marks, and brackets} {
  86.     lsort [glob globTest/*/]
  87. } {globTest/a1/ globTest/a2/ globTest/a3/}
  88.  
  89. # The tests immediately below can only be run at Berkeley, where
  90. # the file-system structure is well-known.
  91.  
  92. if $atBerkeley {
  93.     test glob-4.1 {tildes} {glob ~/.csh*} "/users/ouster/.cshrc"
  94.     test glob-4.2 {tildes} {glob ~ouster/.csh*} "/users/ouster/.cshrc"
  95.  
  96. test glob-5.1 {error conditions} {
  97.     list [catch {glob} msg] $msg
  98. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  99. test glob-5.2 {error conditions} {
  100.     list [catch {glob globTest/\{} msg] $msg
  101. } {1 {unmatched open-brace in file name}}
  102. test glob-5.3 {error conditions} {
  103.     list [catch {glob globTest/*/gorp} msg] $msg
  104. } {1 {no files matched glob pattern "globTest/*/gorp"}}
  105. test glob-5.4 {error conditions} {
  106.     list [catch {glob goo/* x*z foo?q} msg] $msg
  107. } {1 {no files matched glob patterns "goo/* x*z foo?q"}}
  108. test glob-5.5 {error conditions} {
  109.     list [catch {lsort [glob globTest/*.c goo/*]} msg] $msg
  110. } {0 {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}}
  111. test glob-5.6 {error conditions} {
  112.     list [catch {glob ~no-one} msg] $msg
  113. } {1 {user "no-one" doesn't exist}}
  114. test glob-5.7 {error conditions} {
  115.     set home $env(HOME)
  116.     unset env(HOME)
  117.     set x [list [catch {glob ~/*} msg] $msg]
  118.     set env(HOME) $home
  119.     set x
  120. } {1 {couldn't find HOME environment variable to expand "~/*"}}
  121. test glob-5.8 {error conditions} {
  122.     list [catch {glob globTest/{a1,a2}/\{} msg] $msg
  123. } {1 {unmatched open-brace in file name}}
  124. test glob-5.9 {error conditions} {
  125.     list [catch {glob globTest/*/\{} msg] $msg
  126. } {1 {unmatched open-brace in file name}}
  127.  
  128. exec chmod 000 globTest
  129. if {$user != "root"} {
  130.     test glob-6.1 {setting errorCode variable} {
  131.     string tolower [list [catch {glob globTest/*} msg]  $msg $errorCode]
  132.     } {1 {couldn't read directory "globtest": permission denied} {posix eacces {permission denied}}}
  133. }
  134. exec chmod 755 globTest
  135.  
  136. test glob-7.1 {-nocomplain switch} {
  137.     list [catch {glob -nocomplai} msg] $msg
  138. } {1 {bad switch "-nocomplai": must be -nocomplain or --}}
  139. test glob-7.2 {-nocomplain switch} {
  140.     list [catch {glob -nocomplain} msg] $msg
  141. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  142. test glob-7.3 {-nocomplain switch} {
  143.     list [catch {glob -nocomplain goo/*} msg] $msg
  144. } {0 {}}
  145. test glob-7.4 {-- switch} {
  146.     list [catch {glob -- -nocomplain} msg] $msg
  147. } {1 {no files matched glob patterns "-nocomplain"}}
  148. test glob-7.5 {bogus switch} {
  149.     list [catch {glob -gorp} msg] $msg
  150. } {1 {bad switch "-gorp": must be -nocomplain or --}}
  151.  
  152. exec rm -rf globTest
  153.