1 |
578 |
markom |
# This file contains tests for the pkg_mkIndex command.
|
2 |
|
|
# Note that the tests are limited to Tcl scripts only, there are no shared
|
3 |
|
|
# libraries against which to test.
|
4 |
|
|
#
|
5 |
|
|
# Sourcing this file into Tcl runs the tests and generates output for
|
6 |
|
|
# errors. No output means no errors were found.
|
7 |
|
|
#
|
8 |
|
|
# Copyright (c) 1998 by Scriptics Corporation.
|
9 |
|
|
# All rights reserved.
|
10 |
|
|
#
|
11 |
|
|
# RCS: @(#) $Id: pkgMkIndex.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
|
12 |
|
|
|
13 |
|
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
14 |
|
|
|
15 |
|
|
# Add the pkg1 directory to auto_path, so that its packages can be found.
|
16 |
|
|
# packages in pkg1 are used to test indexing of packages in pkg.
|
17 |
|
|
# Make sure that the path to pkg1 is absolute.
|
18 |
|
|
|
19 |
|
|
set scriptDir [file dirname [info script]]
|
20 |
|
|
set oldDir [pwd]
|
21 |
|
|
lappend auto_path [file join [pwd] $scriptDir pkg1]
|
22 |
|
|
|
23 |
|
|
namespace eval pkgtest {
|
24 |
|
|
# Namespace for procs we can discard
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
# pkgtest::parseArgs --
|
28 |
|
|
#
|
29 |
|
|
# Parse an argument list.
|
30 |
|
|
#
|
31 |
|
|
# Arguments:
|
32 |
|
|
# (optional) arguments starting with a dash are collected
|
33 |
|
|
# as options to pkg_mkIndex and passed to pkg_mkIndex.
|
34 |
|
|
# dirPath the directory to index
|
35 |
|
|
# pattern0 pattern to index
|
36 |
|
|
# ... pattern to index
|
37 |
|
|
# patternN pattern to index
|
38 |
|
|
#
|
39 |
|
|
# Results:
|
40 |
|
|
# Returns a three element list:
|
41 |
|
|
# 0: the options
|
42 |
|
|
# 1: the directory to index
|
43 |
|
|
# 2: the patterns list
|
44 |
|
|
|
45 |
|
|
proc pkgtest::parseArgs { args } {
|
46 |
|
|
set options ""
|
47 |
|
|
|
48 |
|
|
set argc [llength $args]
|
49 |
|
|
for {set iarg 0} {$iarg < $argc} {incr iarg} {
|
50 |
|
|
set a [lindex $args $iarg]
|
51 |
|
|
if {[regexp {^-} $a]} {
|
52 |
|
|
lappend options $a
|
53 |
|
|
if {[string compare -load $a] == 0} {
|
54 |
|
|
incr iarg
|
55 |
|
|
lappend options [lindex $args $iarg]
|
56 |
|
|
}
|
57 |
|
|
} else {
|
58 |
|
|
break
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
set dirPath [lindex $args $iarg]
|
63 |
|
|
incr iarg
|
64 |
|
|
set patternList [lrange $args $iarg end]
|
65 |
|
|
|
66 |
|
|
return [list $options $dirPath $patternList]
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
# pkgtest::parseIndex --
|
70 |
|
|
#
|
71 |
|
|
# Loads a pkgIndex.tcl file, records all the calls to "package ifneeded".
|
72 |
|
|
#
|
73 |
|
|
# Arguments:
|
74 |
|
|
# filePath path to the pkgIndex.tcl file.
|
75 |
|
|
#
|
76 |
|
|
# Results:
|
77 |
|
|
# Returns a list, in "array set/get" format, where the keys are the package
|
78 |
|
|
# name and version (in the form "$name:$version"), and the values the rest
|
79 |
|
|
# of the command line.
|
80 |
|
|
|
81 |
|
|
proc pkgtest::parseIndex { filePath } {
|
82 |
|
|
# create a slave interpreter, where we override "package ifneeded"
|
83 |
|
|
|
84 |
|
|
set slave [interp create]
|
85 |
|
|
if {[catch {
|
86 |
|
|
$slave eval {
|
87 |
|
|
rename package package_original
|
88 |
|
|
proc package { args } {
|
89 |
|
|
if {[string compare [lindex $args 0] ifneeded] == 0} {
|
90 |
|
|
set pkg [lindex $args 1]
|
91 |
|
|
set ver [lindex $args 2]
|
92 |
|
|
set ::PKGS($pkg:$ver) [lindex $args 3]
|
93 |
|
|
} else {
|
94 |
|
|
return [eval package_original $args]
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
array set ::PKGS {}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
set dir [file dirname $filePath]
|
101 |
|
|
$slave eval {set curdir [pwd]}
|
102 |
|
|
$slave eval [list cd $dir]
|
103 |
|
|
$slave eval [list set dir $dir]
|
104 |
|
|
$slave eval [list source [file tail $filePath]]
|
105 |
|
|
$slave eval {cd $curdir}
|
106 |
|
|
|
107 |
|
|
# Create the list in sorted order, so that we don't get spurious
|
108 |
|
|
# errors because the order has changed.
|
109 |
|
|
|
110 |
|
|
array set P {}
|
111 |
|
|
foreach {k v} [$slave eval {array get ::PKGS}] {
|
112 |
|
|
set P($k) $v
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
set PKGS ""
|
116 |
|
|
foreach k [lsort [array names P]] {
|
117 |
|
|
lappend PKGS $k $P($k)
|
118 |
|
|
}
|
119 |
|
|
} err]} {
|
120 |
|
|
set ei $::errorInfo
|
121 |
|
|
set ec $::errorCode
|
122 |
|
|
|
123 |
|
|
catch {interp delete $slave}
|
124 |
|
|
|
125 |
|
|
error $ei $ec
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
interp delete $slave
|
129 |
|
|
|
130 |
|
|
return $PKGS
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
# pkgtest::createIndex --
|
134 |
|
|
#
|
135 |
|
|
# Runs pkg_mkIndex for the given directory and set of patterns.
|
136 |
|
|
# This procedure deletes any pkgIndex.tcl file in the target directory,
|
137 |
|
|
# then runs pkg_mkIndex.
|
138 |
|
|
#
|
139 |
|
|
# Arguments:
|
140 |
|
|
# (optional) arguments starting with a dash are collected
|
141 |
|
|
# as options to pkg_mkIndex and passed to pkg_mkIndex.
|
142 |
|
|
# dirPath the directory to index
|
143 |
|
|
# pattern0 pattern to index
|
144 |
|
|
# ... pattern to index
|
145 |
|
|
# patternN pattern to index
|
146 |
|
|
#
|
147 |
|
|
# Results:
|
148 |
|
|
# Returns a two element list:
|
149 |
|
|
# 0: 1 if the procedure encountered an error, 0 otherwise.
|
150 |
|
|
# 1: the error result if element 0 was 1
|
151 |
|
|
|
152 |
|
|
proc pkgtest::createIndex { args } {
|
153 |
|
|
set parsed [eval parseArgs $args]
|
154 |
|
|
set options [lindex $parsed 0]
|
155 |
|
|
set dirPath [lindex $parsed 1]
|
156 |
|
|
set patternList [lindex $parsed 2]
|
157 |
|
|
|
158 |
|
|
if {[catch {
|
159 |
|
|
file delete [file join $dirPath pkgIndex.tcl]
|
160 |
|
|
eval pkg_mkIndex $options $dirPath $patternList
|
161 |
|
|
} err]} {
|
162 |
|
|
return [list 1 $err]
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
return [list 0 {}]
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
# makePkgList --
|
169 |
|
|
#
|
170 |
|
|
# Takes the output of a pkgtest::parseIndex call, filters it and returns a
|
171 |
|
|
# cleaned up list of packages and their actions.
|
172 |
|
|
#
|
173 |
|
|
# Arguments:
|
174 |
|
|
# inList output from a pkgtest::parseIndex.
|
175 |
|
|
#
|
176 |
|
|
# Results:
|
177 |
|
|
# Returns a list of two element lists:
|
178 |
|
|
# 0: the name:version
|
179 |
|
|
# 1: a list describing the package.
|
180 |
|
|
# For tclPkgSetup packages it consists of:
|
181 |
|
|
# 0: the keyword tclPkgSetup
|
182 |
|
|
# 1: the first file to source, with its exported procedures
|
183 |
|
|
# 2: the second file ...
|
184 |
|
|
# N: the N-1st file ...
|
185 |
|
|
|
186 |
|
|
proc makePkgList { inList } {
|
187 |
|
|
set pkgList ""
|
188 |
|
|
|
189 |
|
|
foreach {k v} $inList {
|
190 |
|
|
switch [lindex $v 0] {
|
191 |
|
|
tclPkgSetup {
|
192 |
|
|
set l tclPkgSetup
|
193 |
|
|
foreach s [lindex $v 4] {
|
194 |
|
|
lappend l $s
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
source {
|
199 |
|
|
set l $v
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
default {
|
203 |
|
|
error "can't handle $k $v"
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
lappend pkgList [list $k $l]
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
return $pkgList
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
# pkgtest::runIndex --
|
214 |
|
|
#
|
215 |
|
|
# Runs pkg_mkIndex, parses the generated index file.
|
216 |
|
|
#
|
217 |
|
|
# Arguments:
|
218 |
|
|
# (optional) arguments starting with a dash are collected
|
219 |
|
|
# as options to pkg_mkIndex and passed to pkg_mkIndex.
|
220 |
|
|
# dirPath the directory to index
|
221 |
|
|
# pattern0 pattern to index
|
222 |
|
|
# ... pattern to index
|
223 |
|
|
# patternN pattern to index
|
224 |
|
|
#
|
225 |
|
|
# Results:
|
226 |
|
|
# Returns a two element list:
|
227 |
|
|
# 0: 1 if the procedure encountered an error, 0 otherwise.
|
228 |
|
|
# 1: if no error, this is the parsed generated index file, in the format
|
229 |
|
|
# returned by pkgtest::parseIndex.
|
230 |
|
|
# If error, this is the error result.
|
231 |
|
|
|
232 |
|
|
proc pkgtest::runIndex { args } {
|
233 |
|
|
set rv [eval createIndex $args]
|
234 |
|
|
if {[lindex $rv 0] == 0} {
|
235 |
|
|
set parsed [eval parseArgs $args]
|
236 |
|
|
set dirPath [lindex $parsed 1]
|
237 |
|
|
set idxFile [file join $dirPath pkgIndex.tcl]
|
238 |
|
|
|
239 |
|
|
if {[catch {
|
240 |
|
|
set result [list 0 [makePkgList [parseIndex $idxFile]]]
|
241 |
|
|
} err]} {
|
242 |
|
|
set result [list 1 $err]
|
243 |
|
|
}
|
244 |
|
|
file delete $idxFile
|
245 |
|
|
} else {
|
246 |
|
|
set result $rv
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
return $result
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
# If there is no match to the patterns, make sure the directory hasn't
|
253 |
|
|
# changed on us
|
254 |
|
|
|
255 |
|
|
test pkgMkIndex-1.1 {nothing matches pattern - current dir is the same} {
|
256 |
|
|
list [pkgtest::runIndex pkg nomatch.tcl] [pwd]
|
257 |
|
|
} [list {1 {no files matched glob pattern "nomatch.tcl"}} [pwd]]
|
258 |
|
|
cd $oldDir ;# 'cause 8.0.3 is left in the wrong place
|
259 |
|
|
test pkgMkIndex-2.1 {simple package} {
|
260 |
|
|
pkgtest::runIndex pkg simple.tcl
|
261 |
|
|
} {0 {{simple:1.0 {tclPkgSetup {simple.tcl source {::simple::lower ::simple::upper}}}}}}
|
262 |
|
|
|
263 |
|
|
test pkgMkIndex-2.2 {simple package - use -direct} {
|
264 |
|
|
pkgtest::runIndex -direct pkg simple.tcl
|
265 |
|
|
} "0 {{simple:1.0 {source [file join pkg simple.tcl]}}}"
|
266 |
|
|
|
267 |
|
|
test pkgMkIndex-3.1 {simple package with global symbols} {
|
268 |
|
|
pkgtest::runIndex pkg global.tcl
|
269 |
|
|
} {0 {{global:1.0 {tclPkgSetup {global.tcl source {global_lower global_upper}}}}}}
|
270 |
|
|
|
271 |
|
|
test pkgMkIndex-4.1 {split package} {
|
272 |
|
|
pkgtest::runIndex pkg pkg2_a.tcl pkg2_b.tcl
|
273 |
|
|
} {0 {{pkg2:1.0 {tclPkgSetup {pkg2_a.tcl source ::pkg2::p2-1} {pkg2_b.tcl source ::pkg2::p2-2}}}}}
|
274 |
|
|
|
275 |
|
|
test pkgMkIndex-4.2 {split package - direct loading} {
|
276 |
|
|
pkgtest::runIndex -direct pkg pkg2_a.tcl pkg2_b.tcl
|
277 |
|
|
} "0 {{pkg2:1.0 {source [file join pkg pkg2_a.tcl]
|
278 |
|
|
source [file join pkg pkg2_b.tcl]}}}"
|
279 |
|
|
|
280 |
|
|
# This will fail, with "direct1" procedures in the list of procedures
|
281 |
|
|
# provided by std.
|
282 |
|
|
# It may also fail, if tclblend is in the auto_path, with an additional
|
283 |
|
|
# command "loadJava" which comes from the tclblend pkgIndex.tcl file.
|
284 |
|
|
# Both failures are caused by Tcl code executed in pkgIndex.tcl.
|
285 |
|
|
|
286 |
|
|
test pkgMkIndex-5.1 {requires -direct package} {
|
287 |
|
|
pkgtest::runIndex pkg std.tcl
|
288 |
|
|
} {0 {{std:1.0 {tclPkgSetup {std.tcl source {::std::p1 ::std::p2}}}}}}
|
289 |
|
|
|
290 |
|
|
test pkgMkIndex-6.1 {pkg1 requires pkg3} {
|
291 |
|
|
pkgtest::runIndex pkg pkg1.tcl pkg3.tcl
|
292 |
|
|
} {0 {{pkg1:1.0 {tclPkgSetup {pkg1.tcl source {::pkg1::p1-1 ::pkg1::p1-2}}}} {pkg3:1.0 {tclPkgSetup {pkg3.tcl source {::pkg3::p3-1 ::pkg3::p3-2}}}}}}
|
293 |
|
|
|
294 |
|
|
test pkgMkIndex-6.2 {pkg1 requires pkg3 - use -direct} {
|
295 |
|
|
pkgtest::runIndex -direct pkg pkg1.tcl pkg3.tcl
|
296 |
|
|
} "0 {{pkg1:1.0 {source [file join pkg pkg1.tcl]}} {pkg3:1.0 {source [file join pkg pkg3.tcl]}}}"
|
297 |
|
|
|
298 |
|
|
test pkgMkIndex-7.1 {pkg4 uses pkg3} {
|
299 |
|
|
pkgtest::runIndex pkg pkg4.tcl pkg3.tcl
|
300 |
|
|
} {0 {{pkg3:1.0 {tclPkgSetup {pkg3.tcl source {::pkg3::p3-1 ::pkg3::p3-2}}}} {pkg4:1.0 {tclPkgSetup {pkg4.tcl source {::pkg4::p4-1 ::pkg4::p4-2}}}}}}
|
301 |
|
|
|
302 |
|
|
test pkgMkIndex-7.2 {pkg4 uses pkg3 - use -direct} {
|
303 |
|
|
pkgtest::runIndex -direct pkg pkg4.tcl pkg3.tcl
|
304 |
|
|
} "0 {{pkg3:1.0 {source [file join pkg pkg3.tcl]}} {pkg4:1.0 {source [file join pkg pkg4.tcl]}}}"
|
305 |
|
|
|
306 |
|
|
test pkgMkIndex-8.1 {pkg5 uses pkg2} {
|
307 |
|
|
pkgtest::runIndex pkg pkg5.tcl pkg2_a.tcl pkg2_b.tcl
|
308 |
|
|
} {0 {{pkg2:1.0 {tclPkgSetup {pkg2_a.tcl source ::pkg2::p2-1} {pkg2_b.tcl source ::pkg2::p2-2}}} {pkg5:1.0 {tclPkgSetup {pkg5.tcl source {::pkg5::p5-1 ::pkg5::p5-2}}}}}}
|
309 |
|
|
|
310 |
|
|
test pkgMkIndex-8.2 {pkg5 uses pkg2 - use -direct} {
|
311 |
|
|
pkgtest::runIndex -direct pkg pkg5.tcl pkg2_a.tcl pkg2_b.tcl
|
312 |
|
|
} "0 {{pkg2:1.0 {source [file join pkg pkg2_a.tcl]
|
313 |
|
|
source [file join pkg pkg2_b.tcl]}} {pkg5:1.0 {source [file join pkg pkg5.tcl]}}}"
|
314 |
|
|
|
315 |
|
|
test pkgMkIndex-9.1 {circular packages} {
|
316 |
|
|
pkgtest::runIndex pkg circ1.tcl circ2.tcl circ3.tcl
|
317 |
|
|
} {0 {{circ1:1.0 {tclPkgSetup {circ1.tcl source {::circ1::c1-1 ::circ1::c1-2 ::circ1::c1-3 ::circ1::c1-4}}}} {circ2:1.0 {tclPkgSetup {circ2.tcl source {::circ2::c2-1 ::circ2::c2-2}}}} {circ3:1.0 {tclPkgSetup {circ3.tcl source ::circ3::c3-1}}}}}
|
318 |
|
|
|
319 |
|
|
# Try to find one of the DLLs in the dltest directory
|
320 |
|
|
set x [file join [pwd] [file dirname [info script]]]
|
321 |
|
|
set x [file join $x ../unix/dltest/pkga[info sharedlibextension]]
|
322 |
|
|
if {[file exists $x]} {
|
323 |
|
|
file copy -force $x pkg
|
324 |
|
|
test pkgMkIndex-10.1 {package in DLL and script} {
|
325 |
|
|
pkgtest::runIndex pkg pkga[info sharedlibextension] pkga.tcl
|
326 |
|
|
} {0 {{Pkga:1.0 {tclPkgSetup {pkga.so load {pkga_eq pkga_quote}} {pkga.tcl source pkga_neq}}}}}
|
327 |
|
|
test pkgMkIndex-10.2 {package in DLL hidden by -load} {
|
328 |
|
|
pkgtest::runIndex -load Pkg* -- pkg pkga[info sharedlibextension]
|
329 |
|
|
} {0 {}}
|
330 |
|
|
} else {
|
331 |
|
|
puts "Skipping pkgMkIndex-10.1 (index of DLL and script)"
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
#
|
335 |
|
|
# cleanup
|
336 |
|
|
#
|
337 |
|
|
if {![info exist TESTS]} {
|
338 |
|
|
file delete [file join pkg pkgIndex.tcl]
|
339 |
|
|
namespace delete pkgtest
|
340 |
|
|
}
|