Debian Codegraph @

tests/tm.test

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