1 | # This file contains tests for the ::tcl::tm::* commands. |
---|
2 | # |
---|
3 | # Sourcing this file into Tcl runs the tests and generates output for |
---|
4 | # errors. No output means no errors were found. |
---|
5 | # |
---|
6 | # Copyright (c) 2004 by Donal K. Fellows. |
---|
7 | # All rights reserved. |
---|
8 | # |
---|
9 | # RCS: @(#) $Id: tm.test,v 1.6 2005/08/29 21:55:27 andreas_kupries Exp $ |
---|
10 | |
---|
11 | package require Tcl 8.5 |
---|
12 | if {"::tcltest" ni [namespace children]} { |
---|
13 | package require tcltest 2 |
---|
14 | namespace import -force ::tcltest::* |
---|
15 | } |
---|
16 | |
---|
17 | test tm-1.1 {tm: path command exists} { |
---|
18 | catch { ::tcl::tm::path } |
---|
19 | info commands ::tcl::tm::path |
---|
20 | } ::tcl::tm::path |
---|
21 | test tm-1.2 {tm: path command syntax} -returnCodes error -body { |
---|
22 | ::tcl::tm::path foo |
---|
23 | } -result {unknown or ambiguous subcommand "foo": must be add, list, or remove} |
---|
24 | test tm-1.3 {tm: path command syntax} -returnCodes error -body { |
---|
25 | ::tcl::tm::path add |
---|
26 | } -result "wrong # args: should be \"::tcl::tm::path add path ...\"" |
---|
27 | test tm-1.4 {tm: path command syntax} -returnCodes error -body { |
---|
28 | ::tcl::tm::path remove |
---|
29 | } -result "wrong # args: should be \"::tcl::tm::path remove path ...\"" |
---|
30 | test tm-1.5 {tm: path command syntax} -returnCodes error -body { |
---|
31 | ::tcl::tm::path list foobar |
---|
32 | } -result "wrong # args: should be \"::tcl::tm::path list\"" |
---|
33 | |
---|
34 | test tm-2.1 {tm: roots command exists} { |
---|
35 | catch { ::tcl::tm::roots } |
---|
36 | info commands ::tcl::tm::roots |
---|
37 | } ::tcl::tm::roots |
---|
38 | test tm-2.2 {tm: roots command syntax} -returnCodes error -body { |
---|
39 | ::tcl::tm::roots |
---|
40 | } -result "wrong # args: should be \"::tcl::tm::roots paths\"" |
---|
41 | test tm-2.3 {tm: roots command syntax} -returnCodes error -body { |
---|
42 | ::tcl::tm::roots foo bar |
---|
43 | } -result "wrong # args: should be \"::tcl::tm::roots paths\"" |
---|
44 | |
---|
45 | |
---|
46 | test tm-3.1 {tm: module path management, input validation} -setup { |
---|
47 | # Save and clear the list |
---|
48 | set defaults [::tcl::tm::path list] |
---|
49 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
50 | } -cleanup { |
---|
51 | # Restore old contents of path list. |
---|
52 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
53 | foreach p $defaults {::tcl::tm::path add $p} |
---|
54 | } -returnCodes error -body { |
---|
55 | ::tcl::tm::path add foo/bar |
---|
56 | ::tcl::tm::path add foo |
---|
57 | } -result {foo is ancestor of existing module path foo/bar.} |
---|
58 | |
---|
59 | test tm-3.2 {tm: module path management, input validation} -setup { |
---|
60 | # Save and clear the list |
---|
61 | set defaults [::tcl::tm::path list] |
---|
62 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
63 | } -cleanup { |
---|
64 | # Restore old contents of path list. |
---|
65 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
66 | foreach p $defaults {::tcl::tm::path add $p} |
---|
67 | } -returnCodes error -body { |
---|
68 | ::tcl::tm::path add foo |
---|
69 | ::tcl::tm::path add foo/bar |
---|
70 | } -result {foo/bar is subdirectory of existing module path foo.} |
---|
71 | |
---|
72 | test tm-3.3 {tm: module path management, add/list interaction} -setup { |
---|
73 | # Save and clear the list |
---|
74 | set defaults [::tcl::tm::path list] |
---|
75 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
76 | } -cleanup { |
---|
77 | # Restore old contents of path list. |
---|
78 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
79 | foreach p $defaults {::tcl::tm::path add $p} |
---|
80 | } -body { |
---|
81 | ::tcl::tm::path add foo |
---|
82 | ::tcl::tm::path add bar |
---|
83 | ::tcl::tm::path list |
---|
84 | } -result {bar foo} |
---|
85 | |
---|
86 | test tm-3.4 {tm: module path management, add/list interaction} -setup { |
---|
87 | # Save and clear the list |
---|
88 | set defaults [::tcl::tm::path list] |
---|
89 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
90 | } -cleanup { |
---|
91 | # Restore old contents of path list. |
---|
92 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
93 | foreach p $defaults {::tcl::tm::path add $p} |
---|
94 | } -body { |
---|
95 | ::tcl::tm::path add foo bar baz |
---|
96 | ::tcl::tm::path list |
---|
97 | } -result {baz bar foo} |
---|
98 | |
---|
99 | test tm-3.5 {tm: module path management, input validation/list interaction} -setup { |
---|
100 | # Save and clear the list |
---|
101 | set defaults [::tcl::tm::path list] |
---|
102 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
103 | } -cleanup { |
---|
104 | # Restore old contents of path list. |
---|
105 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
106 | foreach p $defaults {::tcl::tm::path add $p} |
---|
107 | } -body { |
---|
108 | catch {::tcl::tm::path add snarf foo geode foo/bar} |
---|
109 | # Nothing is added if a problem was found. |
---|
110 | ::tcl::tm::path list |
---|
111 | } -result {} |
---|
112 | |
---|
113 | test tm-3.6 {tm: module path management, input validation/list interaction} -setup { |
---|
114 | # Save and clear the list |
---|
115 | set defaults [::tcl::tm::path list] |
---|
116 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
117 | } -cleanup { |
---|
118 | # Restore old contents of path list. |
---|
119 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
120 | foreach p $defaults {::tcl::tm::path add $p} |
---|
121 | } -body { |
---|
122 | catch {::tcl::tm::path add snarf foo/bar geode foo} |
---|
123 | # Nothing is added if a problem was found. |
---|
124 | ::tcl::tm::path list |
---|
125 | } -result {} |
---|
126 | |
---|
127 | test tm-3.7 {tm: module path management, input validation/list interaction} -setup { |
---|
128 | # Save and clear the list |
---|
129 | set defaults [::tcl::tm::path list] |
---|
130 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
131 | } -cleanup { |
---|
132 | # Restore old contents of path list. |
---|
133 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
134 | foreach p $defaults {::tcl::tm::path add $p} |
---|
135 | } -body { |
---|
136 | catch { |
---|
137 | ::tcl::tm::path add foo/bar |
---|
138 | ::tcl::tm::path add snarf geode foo |
---|
139 | } |
---|
140 | # Nothing is added if a problem was found. |
---|
141 | ::tcl::tm::path list |
---|
142 | } -result {foo/bar} |
---|
143 | |
---|
144 | test tm-3.8 {tm: module path management, input validation, ignore duplicates} -setup { |
---|
145 | # Save and clear the list |
---|
146 | set defaults [::tcl::tm::path list] |
---|
147 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
148 | } -cleanup { |
---|
149 | # Restore old contents of path list. |
---|
150 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
151 | foreach p $defaults {::tcl::tm::path add $p} |
---|
152 | } -body { |
---|
153 | # Ignore path if present |
---|
154 | ::tcl::tm::path add foo |
---|
155 | ::tcl::tm::path add snarf geode foo |
---|
156 | ::tcl::tm::path list |
---|
157 | } -result {geode snarf foo} |
---|
158 | |
---|
159 | test tm-3.9 {tm: module path management, input validation, ignore duplicates} -setup { |
---|
160 | # Save and clear the list |
---|
161 | set defaults [::tcl::tm::path list] |
---|
162 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
163 | } -cleanup { |
---|
164 | # Restore old contents of path list. |
---|
165 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
166 | foreach p $defaults {::tcl::tm::path add $p} |
---|
167 | } -body { |
---|
168 | # Ignore path if present |
---|
169 | ::tcl::tm::path add foo snarf geode foo |
---|
170 | ::tcl::tm::path list |
---|
171 | } -result {geode snarf foo} |
---|
172 | |
---|
173 | test tm-3.10 {tm: module path management, remove} -setup { |
---|
174 | # Save and clear the list |
---|
175 | set defaults [::tcl::tm::path list] |
---|
176 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
177 | } -cleanup { |
---|
178 | # Restore old contents of path list. |
---|
179 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
180 | foreach p $defaults {::tcl::tm::path add $p} |
---|
181 | } -body { |
---|
182 | ::tcl::tm::path add snarf geode foo |
---|
183 | ::tcl::tm::path remove foo |
---|
184 | ::tcl::tm::path list |
---|
185 | } -result {geode snarf} |
---|
186 | |
---|
187 | test tm-3.11 {tm: module path management, remove ignores unknown path} -setup { |
---|
188 | # Save and clear the list |
---|
189 | set defaults [::tcl::tm::path list] |
---|
190 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
191 | } -cleanup { |
---|
192 | # Restore old contents of path list. |
---|
193 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
194 | foreach p $defaults {::tcl::tm::path add $p} |
---|
195 | } -body { |
---|
196 | ::tcl::tm::path add foo snarf geode |
---|
197 | ::tcl::tm::path remove fox |
---|
198 | ::tcl::tm::path list |
---|
199 | } -result {geode snarf foo} |
---|
200 | |
---|
201 | |
---|
202 | proc genpaths {base} { |
---|
203 | # Normalizing picks up drive letters on windows [Bug 1053568] |
---|
204 | set base [file normalize $base] |
---|
205 | foreach {major minor} [split [info tclversion] .] break |
---|
206 | set results {} |
---|
207 | set base [file join $base tcl$major] |
---|
208 | lappend results [file join $base site-tcl] |
---|
209 | for {set i 0} {$i <= $minor} {incr i} { |
---|
210 | lappend results [file join $base ${major}.$i] |
---|
211 | } |
---|
212 | return $results |
---|
213 | } |
---|
214 | |
---|
215 | test tm-3.12 {tm: module path management, roots} -setup { |
---|
216 | # Save and clear the list |
---|
217 | set defaults [::tcl::tm::path list] |
---|
218 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
219 | } -cleanup { |
---|
220 | # Restore old contents of path list. |
---|
221 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
222 | foreach p $defaults {::tcl::tm::path add $p} |
---|
223 | } -body { |
---|
224 | ::tcl::tm::roots /FOO |
---|
225 | ::tcl::tm::path list |
---|
226 | } -result [genpaths /FOO] |
---|
227 | |
---|
228 | test tm-3.13 {tm: module path management, roots} -setup { |
---|
229 | # Save and clear the list |
---|
230 | set defaults [::tcl::tm::path list] |
---|
231 | foreach p $defaults {::tcl::tm::path remove $p} |
---|
232 | } -cleanup { |
---|
233 | # Restore old contents of path list. |
---|
234 | foreach p [::tcl::tm::path list] {::tcl::tm::path remove $p} |
---|
235 | foreach p $defaults {::tcl::tm::path add $p} |
---|
236 | } -body { |
---|
237 | ::tcl::tm::roots [list /FOO /BAR] |
---|
238 | ::tcl::tm::path list |
---|
239 | } -result [concat [genpaths /BAR] [genpaths /FOO]] |
---|
240 | |
---|
241 | rename genpaths {} |
---|
242 | ::tcltest::cleanupTests |
---|
243 | return |
---|
244 | |
---|
245 | # Local Variables: |
---|
246 | # mode: tcl |
---|
247 | # End: |
---|