📄 pkgmkindex.test
字号:
namespace eval direct1 { namespace export pd1 pd2}proc direct1::pd1 { stg } { return [string tolower $stg]}proc direct1::pd2 { stg } { return [string toupper $stg]}} [file join direct1 direct1.tcl]pkg_mkIndex -direct $direct1 direct1.tclmakeFile {# Does a package require of direct1, whose pkgIndex.tcl entry# is created above with option -direct. This tests that pkg_mkIndex# can handle code that is sourced in pkgIndex.tcl files.package require direct1package provide std 1.0namespace eval std { namespace export p1 p2}proc std::p1 { stg } { return [string tolower $stg]}proc std::p2 { stg } { return [string toupper $stg]}} [file join pkg std.tcl]test pkgMkIndex-5.1 {requires -direct package} { pkgtest::runIndex -lazy $fullPkgPath std.tcl} {0 {{std:1.0 {tclPkgSetup {std.tcl source {::std::p1 ::std::p2}}}}}}removeFile [file join direct1 direct1.tcl]file delete [file join $direct1 pkgIndex.tcl]removeDirectory direct1removeFile [file join pkg std.tcl]makeFile {# This package requires pkg3, but it does# not use any of pkg3's procs in the code that is executed by the file# (i.e. references to pkg3's procs are in the proc bodies only).package require pkg3 1.0package provide pkg1 1.0namespace eval pkg1 { namespace export p1-1 p1-2}proc pkg1::p1-1 { num } { return [pkg3::p3-1 $num]}proc pkg1::p1-2 { num } { return [pkg3::p3-2 $num]}} [file join pkg pkg1.tcl]makeFile {package provide pkg3 1.0namespace eval pkg3 { namespace export p3-1 p3-2}proc pkg3::p3-1 { num } { return {[expr $num * 2]}}proc pkg3::p3-2 { num } { return {[expr $num * 3]}}} [file join pkg pkg3.tcl]test pkgMkIndex-6.1 {pkg1 requires pkg3} { pkgtest::runIndex -lazy $fullPkgPath pkg1.tcl pkg3.tcl} {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}}}}}}test pkgMkIndex-6.2 {pkg1 requires pkg3 - use -direct} { pkgtest::runIndex -direct $fullPkgPath pkg1.tcl pkg3.tcl} "0 {{pkg1:1.0 {[list source [file join $fullPkgPath pkg1.tcl]]}} {pkg3:1.0 {[list source [file join $fullPkgPath pkg3.tcl]]}}}"removeFile [file join pkg pkg1.tcl]makeFile {# This package requires pkg3, and it calls# a pkg3 proc in the code that is executed by the filepackage require pkg3 1.0package provide pkg4 1.0namespace eval pkg4 { namespace export p4-1 p4-2 variable m2 [pkg3::p3-1 10]}proc pkg4::p4-1 { num } { variable m2 return [expr {$m2 * $num}]}proc pkg4::p4-2 { num } { return [pkg3::p3-2 $num]}} [file join pkg pkg4.tcl]test pkgMkIndex-7.1 {pkg4 uses pkg3} { pkgtest::runIndex -lazy $fullPkgPath pkg4.tcl pkg3.tcl} {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}}}}}}test pkgMkIndex-7.2 {pkg4 uses pkg3 - use -direct} { pkgtest::runIndex -direct $fullPkgPath pkg4.tcl pkg3.tcl} "0 {{pkg3:1.0 {[list source [file join $fullPkgPath pkg3.tcl]]}} {pkg4:1.0 {[list source [file join $fullPkgPath pkg4.tcl]]}}}"removeFile [file join pkg pkg4.tcl]removeFile [file join pkg pkg3.tcl]makeFile {# This package requires pkg2, and it calls# a pkg2 proc in the code that is executed by the file.# Pkg2 is a split package.package require pkg2 1.0package provide pkg5 1.0namespace eval pkg5 { namespace export p5-1 p5-2 variable m2 [pkg2::p2-1 10] variable m3 [pkg2::p2-2 10]}proc pkg5::p5-1 { num } { variable m2 return [expr {$m2 * $num}]}proc pkg5::p5-2 { num } { variable m2 return [expr {$m2 * $num}]}} [file join pkg pkg5.tcl]test pkgMkIndex-8.1 {pkg5 uses pkg2} { pkgtest::runIndex -lazy $fullPkgPath pkg5.tcl pkg2_a.tcl pkg2_b.tcl} {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}}}}}}test pkgMkIndex-8.2 {pkg5 uses pkg2 - use -direct} { pkgtest::runIndex -direct $fullPkgPath pkg5.tcl pkg2_a.tcl pkg2_b.tcl} "0 {{pkg2:1.0 {[list source [file join $fullPkgPath pkg2_a.tcl]][list source [file join $fullPkgPath pkg2_b.tcl]]}} {pkg5:1.0 {[list source [file join $fullPkgPath pkg5.tcl]]}}}"removeFile [file join pkg pkg5.tcl]removeFile [file join pkg pkg2_a.tcl]removeFile [file join pkg pkg2_b.tcl]makeFile {# This package requires circ2, and circ2# requires circ3, which in turn requires circ1.# In case of cirularities, pkg_mkIndex should give up when it gets stuck.package require circ2 1.0package provide circ1 1.0namespace eval circ1 { namespace export c1-1 c1-2 c1-3 c1-4}proc circ1::c1-1 { num } { return [circ2::c2-1 $num]}proc circ1::c1-2 { num } { return [circ2::c2-2 $num]}proc circ1::c1-3 {} { return 10}proc circ1::c1-4 {} { return 20}} [file join pkg circ1.tcl]makeFile {# This package is required by circ1, and# requires circ3. Circ3, in turn, requires circ1 to give us a circularity.package require circ3 1.0package provide circ2 1.0namespace eval circ2 { namespace export c2-1 c2-2}proc circ2::c2-1 { num } { return [expr $num * [circ3::c3-1]]}proc circ2::c2-2 { num } { return [expr $num * [circ3::c3-2]]}} [file join pkg circ2.tcl]makeFile {# This package is required by circ2, and in# turn requires circ1. This closes the circularity.package require circ1 1.0package provide circ3 1.0namespace eval circ3 { namespace export c3-1 c3-4}proc circ3::c3-1 {} { return [circ1::c1-3]}proc circ3::c3-2 {} { return [circ1::c1-4]}} [file join pkg circ3.tcl]test pkgMkIndex-9.1 {circular packages} { pkgtest::runIndex -lazy $fullPkgPath circ1.tcl circ2.tcl circ3.tcl} {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}}}}}removeFile [file join pkg circ1.tcl]removeFile [file join pkg circ2.tcl]removeFile [file join pkg circ3.tcl]# Some tests require the existence of one of the DLLs in the dltest directoryset x [file join [file dirname [info nameofexecutable]] dltest \ pkga[info sharedlibextension]]set dll "[file tail $x]Required"::tcltest::testConstraint $dll [file exists $x]if {[testConstraint $dll]} {makeFile {# This package provides Pkga, which is also provided by a DLL.package provide Pkga 1.0proc pkga_neq { x } { return [expr {! [pkgq_eq $x]}]}} [file join pkg pkga.tcl]file copy -force $x $fullPkgPath}testConstraint exec [llength [info commands ::exec]]test pkgMkIndex-10.1 {package in DLL and script} [list exec $dll] { # Do all [load]ing of shared libraries in another process, so # we can delete the file and not get stuck because we're holding # a reference to it. set cmd [list pkg_mkIndex -lazy $fullPkgPath [file tail $x] pkga.tcl] exec [interpreter] << $cmd pkgtest::runCreatedIndex {0 {}} -lazy $fullPkgPath pkga[info sharedlibextension] pkga.tcl} "0 {{Pkga:1.0 {tclPkgSetup {pkga[info sharedlibextension] load {pkga_eq pkga_quote}} {pkga.tcl source pkga_neq}}}}"test pkgMkIndex-10.2 {package in DLL hidden by -load} [list exec $dll] { # Do all [load]ing of shared libraries in another process, so # we can delete the file and not get stuck because we're holding # a reference to it. # # This test depends on context from prior test, so repeat it. set script "[list pkg_mkIndex -lazy $fullPkgPath [file tail $x] pkga.tcl]\n" append script \ "[list pkg_mkIndex -lazy -load Pkg* $fullPkgPath [file tail $x]]" exec [interpreter] << $script pkgtest::runCreatedIndex {0 {}} -lazy -load Pkg* -- $fullPkgPath pkga[info sharedlibextension]} {0 {}}if {[testConstraint $dll]} {file delete -force [file join $fullPkgPath [file tail $x]]removeFile [file join pkg pkga.tcl]}# Tolerate "namespace import" at the global scopemakeFile {package provide fubar 1.0namespace eval ::fubar:: { # # export only public functions. # namespace export {[a-z]*}}proc ::fubar::foo {bar} { puts "$bar" return true}namespace import ::fubar::foo} [file join pkg import.tcl]test pkgMkIndex-11.1 {conflicting namespace imports} { pkgtest::runIndex -lazy $fullPkgPath import.tcl} {0 {{fubar:1.0 {tclPkgSetup {import.tcl source ::fubar::foo}}}}}removeFile [file join pkg import.tcl]# Verify that the auto load list generated is correct even when there# is a proc name conflict between two namespaces (ie, ::foo::baz and# ::bar::baz)makeFile {package provide football 1.0namespace eval ::pro:: { # # export only public functions. # namespace export {[a-z]*}}namespace eval ::college:: { # # export only public functions. # namespace export {[a-z]*}}proc ::pro::team {} { puts "go packers!" return true}proc ::college::team {} { puts "go badgers!" return true}} [file join pkg samename.tcl]test pkgMkIndex-12.1 {same name procs in different namespace} { pkgtest::runIndex -lazy $fullPkgPath samename.tcl} {0 {{football:1.0 {tclPkgSetup {samename.tcl source {::college::team ::pro::team}}}}}}removeFile [file join pkg samename.tcl]# Proc names with embedded spaces are properly listed (ie, correct number of# braces) in resultmakeFile {package provide spacename 1.0proc {a b} {} {}proc {c d} {} {}} [file join pkg spacename.tcl]test pkgMkIndex-13.1 {proc names with embedded spaces} { pkgtest::runIndex -lazy $fullPkgPath spacename.tcl} {0 {{spacename:1.0 {tclPkgSetup {spacename.tcl source {{a b} {c d}}}}}}}removeFile [file join pkg spacename.tcl]# Test the pkg_compareExtension helper functiontest pkgMkIndex-14.1 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo.so .so} 1test pkgMkIndex-14.2 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo.so.bar .so} 0test pkgMkIndex-14.3 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo.so.1 .so} 1test pkgMkIndex-14.4 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo.so.1.2 .so} 1test pkgMkIndex-14.5 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo .so} 0test pkgMkIndex-14.6 {pkg_compareExtension} {unixOnly} { pkg_compareExtension foo.so.1.2.bar .so} 0# cleanupremoveDirectory pkgnamespace delete pkgtest::tcltest::cleanupTestsreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -