aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/obm/Tcl/tests/glob.test
blob: ba134ed86403fdabd9d0b422658ea4e79dd02451 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Commands covered:  glob
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1991-1993 The Regents of the University of California.
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
# $Header: /user6/ouster/tcl/tests/RCS/glob.test,v 1.23 93/08/28 15:57:40 ouster Exp $ (Berkeley)

if {[string compare test [info procs test]] == 1} then {source defs}

# First, create some subdirectories to use for testing.

exec rm -rf globTest
exec mkdir globTest globTest/a1 globTest/a2 globTest/a3
exec mkdir globTest/a1/b1 globTest/a1/b2 globTest/a2/b3
exec cat << abc > globTest/x1.c
exec cat << abc > globTest/y1.c
exec cat << abc > globTest/z1.c
exec cat << abc > "globTest/weird name.c"
exec cat << abc > globTest/.1
exec cat << abc > globTest/a1/b1/x2.c
exec cat << abc > globTest/a1/b2/y2.c

test glob-1.1 {simple globbing} {
    lsort [glob globTest/x1.c globTest/y1.c globTest/foo]
} {globTest/x1.c globTest/y1.c}
test glob-1.2 {simple globbing} {
    glob {}
} .

test glob-2.1 {globbing with braces} {
    glob -nocomplain "{a1,a2}"
} {}
test glob-2.2 {globbing with braces} {
    lsort [glob globTest/{a,b,x,y}1.c]
} {globTest/x1.c globTest/y1.c}
test glob-2.3 {globbing with braces} {
    lsort [glob {globTest/{x1,y2,weird name}.c}]
} {{globTest/weird name.c} globTest/x1.c}
test glob-2.4 {globbing with braces} {
    lsort [glob globTest/{x1.c,a1/*}]
} {globTest/a1/b1 globTest/a1/b2 globTest/x1.c}

test glob-3.1 {asterisks, question marks, and brackets} {
    lsort [glob g*/*.c]
} {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
test glob-3.2 {asterisks, question marks, and brackets} {
    lsort [glob globTest/?1.c]
} {globTest/x1.c globTest/y1.c globTest/z1.c}
test glob-3.3 {asterisks, question marks, and brackets} {
    lsort [glob */*/*/*.c]
} {globTest/a1/b1/x2.c globTest/a1/b2/y2.c}
test glob-3.4 {asterisks, question marks, and brackets} {
    lsort [glob globTest/*]
} {globTest/a1 globTest/a2 globTest/a3 {globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
test glob-3.5 {asterisks, question marks, and brackets} {
    lsort [glob globTest/.*]
} {globTest/. globTest/.. globTest/.1}
test glob-3.6 {asterisks, question marks, and brackets} {
    lsort [glob globTest/*/*]
} {globTest/a1/b1 globTest/a1/b2 globTest/a2/b3}
test glob-3.7 {asterisks, question marks, and brackets} {
    lsort [glob {globTest/[xyab]1.*}]
} {globTest/x1.c globTest/y1.c}
test glob-3.8 {asterisks, question marks, and brackets} {
    lsort [glob globTest/*/]
} {globTest/a1/ globTest/a2/ globTest/a3/}

# The tests immediately below can only be run at Berkeley, where
# the file-system structure is well-known.

if $atBerkeley {
    test glob-4.1 {tildes} {glob ~/.csh*} "/users/ouster/.cshrc"
    test glob-4.2 {tildes} {glob ~ouster/.csh*} "/users/ouster/.cshrc"
} 

test glob-5.1 {error conditions} {
    list [catch {glob} msg] $msg
} {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
test glob-5.2 {error conditions} {
    list [catch {glob globTest/\{} msg] $msg
} {1 {unmatched open-brace in file name}}
test glob-5.3 {error conditions} {
    list [catch {glob globTest/*/gorp} msg] $msg
} {1 {no files matched glob pattern "globTest/*/gorp"}}
test glob-5.4 {error conditions} {
    list [catch {glob goo/* x*z foo?q} msg] $msg
} {1 {no files matched glob patterns "goo/* x*z foo?q"}}
test glob-5.5 {error conditions} {
    list [catch {lsort [glob globTest/*.c goo/*]} msg] $msg
} {0 {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}}
test glob-5.6 {error conditions} {
    list [catch {glob ~no-one} msg] $msg
} {1 {user "no-one" doesn't exist}}
test glob-5.7 {error conditions} {
    set home $env(HOME)
    unset env(HOME)
    set x [list [catch {glob ~/*} msg] $msg]
    set env(HOME) $home
    set x
} {1 {couldn't find HOME environment variable to expand "~/*"}}
test glob-5.8 {error conditions} {
    list [catch {glob globTest/{a1,a2}/\{} msg] $msg
} {1 {unmatched open-brace in file name}}
test glob-5.9 {error conditions} {
    list [catch {glob globTest/*/\{} msg] $msg
} {1 {unmatched open-brace in file name}}

exec chmod 000 globTest
if {$user != "root"} {
    test glob-6.1 {setting errorCode variable} {
	string tolower [list [catch {glob globTest/*} msg]  $msg $errorCode]
    } {1 {couldn't read directory "globtest": permission denied} {posix eacces {permission denied}}}
}
exec chmod 755 globTest

test glob-7.1 {-nocomplain switch} {
    list [catch {glob -nocomplai} msg] $msg
} {1 {bad switch "-nocomplai": must be -nocomplain or --}}
test glob-7.2 {-nocomplain switch} {
    list [catch {glob -nocomplain} msg] $msg
} {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
test glob-7.3 {-nocomplain switch} {
    list [catch {glob -nocomplain goo/*} msg] $msg
} {0 {}}
test glob-7.4 {-- switch} {
    list [catch {glob -- -nocomplain} msg] $msg
} {1 {no files matched glob patterns "-nocomplain"}}
test glob-7.5 {bogus switch} {
    list [catch {glob -gorp} msg] $msg
} {1 {bad switch "-gorp": must be -nocomplain or --}}

exec rm -rf globTest