KATO Kanryu wrote:
> When I single-tested tcllib/yaml.test,
> I found "package require yaml" put teapot/yaml-0.3.3.tm before "./yaml.tcl".
>
> So I had to rename yaml-0.3.3.tm to yaml-0.3.3.tm.nouse.
>
> How to escape this problem?
Hi.
This is a problem which has been solved for the tcllib testsuite. By not using
the 'package' command. The problem with 'package' is that you cannot specify
explicitly which code to use, except by listing a version number.
And if multiple implementations of the package with the same version exist the
package system is free to choose randomly which to take. And in the case of Tcl
Modules being being present things become even more quirkier.
To avoid all this and make sure that we are testing the code in the Tcllib we
are working with, instead of something installed, Tcllib provides a number of
helper commands in the devtools/testutilities.tcl file
Here is an example of their use taken from report/report.test
# ------------------------------------------------------------------
[1] source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 1.0
[2] support {
[3] use struct/matrix.tcl struct::matrix
}
[2] testing {
[3] useLocal report.tcl report
}
# -------------------------------------------------------------------
(Ad 1) First we are loading the test utilities, using a path relative to the
location of the .test file.
(Ad 2) The support and testing commands simply define a bit of context for the
useXXX commands inside. Here we basically declare which package is
under test (testing), and which other packages we load to just support
the testing and the package test (support).
(Ad 3) The 'use' command takes a path relative to the modules/ directory, and
the name of the package provided by the referenced file, and loads it.
The 'useLocal' command is similar, except that the path is relative to
the directory the .test is in.
> I implement for single test for yaml.test beginning.
>
> --------------------------------------------------------
> # lappend auto_path [pwd]
> set auto_path [linsert $auto_path 0 [pwd]]
> package require tcltest
> namespace import ::tcltest::*
> puts [package require yaml]
> --------------------------------------------------------
For yaml the equivalent code would look similar to
# ------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.x ; ## Which version of Tcl is needed by yaml ?
testsNeedTcltest 1.0 ; ## Which version of tclltest ?
testing {
useLocal yaml.tcl yaml
}
# -------------------------------------------------------------------
Hope that helps.
Andreas
|