diff options
Diffstat (limited to 'tcl/tests/pkgMkIndex.test')
-rw-r--r-- | tcl/tests/pkgMkIndex.test | 128 |
1 files changed, 80 insertions, 48 deletions
diff --git a/tcl/tests/pkgMkIndex.test b/tcl/tests/pkgMkIndex.test index 83fd704bb0d..0acb34a0b1f 100644 --- a/tcl/tests/pkgMkIndex.test +++ b/tcl/tests/pkgMkIndex.test @@ -5,20 +5,26 @@ # Sourcing this file into Tcl runs the tests and generates output for # errors. No output means no errors were found. # -# Copyright (c) 1998 by Scriptics Corporation. +# Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # # RCS: @(#) $Id$ -if {[string compare test [info procs test]] == 1} then {source defs} +if {[lsearch [namespace children] ::tcltest] == -1} { + package require tcltest + namespace import -force ::tcltest::* +} + +set origDir [pwd] +cd $::tcltest::testsDirectory + +set fullPkgPath [file join $::tcltest::testsDirectory pkg] # Add the pkg1 directory to auto_path, so that its packages can be found. # packages in pkg1 are used to test indexing of packages in pkg. # Make sure that the path to pkg1 is absolute. -set scriptDir [file dirname [info script]] -set oldDir [pwd] -lappend auto_path [file join [pwd] $scriptDir pkg1] +lappend auto_path [file join $::tcltest::testsDirectory pkg1] namespace eval pkgtest { # Namespace for procs we can discard @@ -155,6 +161,8 @@ proc pkgtest::createIndex { args } { set dirPath [lindex $parsed 1] set patternList [lindex $parsed 2] + file mkdir $dirPath + if {[catch { file delete [file join $dirPath pkgIndex.tcl] eval pkg_mkIndex $options $dirPath $patternList @@ -240,7 +248,7 @@ proc pkgtest::runIndex { args } { set result [list 0 [makePkgList [parseIndex $idxFile]]] } err]} { set result [list 1 $err] - } + } file delete $idxFile } else { set result $rv @@ -253,29 +261,33 @@ proc pkgtest::runIndex { args } { # changed on us test pkgMkIndex-1.1 {nothing matches pattern - current dir is the same} { - list [pkgtest::runIndex pkg nomatch.tcl] [pwd] + list [pkgtest::runIndex -lazy $fullPkgPath nomatch.tcl] [pwd] } [list {1 {no files matched glob pattern "nomatch.tcl"}} [pwd]] -cd $oldDir ;# 'cause 8.0.3 is left in the wrong place + test pkgMkIndex-2.1 {simple package} { - pkgtest::runIndex pkg simple.tcl + pkgtest::runIndex -lazy $fullPkgPath simple.tcl } {0 {{simple:1.0 {tclPkgSetup {simple.tcl source {::simple::lower ::simple::upper}}}}}} test pkgMkIndex-2.2 {simple package - use -direct} { - pkgtest::runIndex -direct pkg simple.tcl -} "0 {{simple:1.0 {source [file join pkg simple.tcl]}}}" + pkgtest::runIndex -direct $fullPkgPath simple.tcl +} "0 {{simple:1.0 {source [file join $fullPkgPath simple.tcl]}}}" + +test pkgMkIndex-2.3 {simple package - direct loading is default} { + pkgtest::runIndex $fullPkgPath simple.tcl +} "0 {{simple:1.0 {source [file join $fullPkgPath simple.tcl]}}}" test pkgMkIndex-3.1 {simple package with global symbols} { - pkgtest::runIndex pkg global.tcl + pkgtest::runIndex -lazy $fullPkgPath global.tcl } {0 {{global:1.0 {tclPkgSetup {global.tcl source {global_lower global_upper}}}}}} test pkgMkIndex-4.1 {split package} { - pkgtest::runIndex pkg pkg2_a.tcl pkg2_b.tcl + pkgtest::runIndex -lazy $fullPkgPath 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}}}}} test pkgMkIndex-4.2 {split package - direct loading} { - pkgtest::runIndex -direct pkg pkg2_a.tcl pkg2_b.tcl -} "0 {{pkg2:1.0 {source [file join pkg pkg2_a.tcl] -source [file join pkg pkg2_b.tcl]}}}" + pkgtest::runIndex -direct $fullPkgPath pkg2_a.tcl pkg2_b.tcl +} "0 {{pkg2:1.0 {source [file join $fullPkgPath pkg2_a.tcl] +source [file join $fullPkgPath pkg2_b.tcl]}}}" # This will fail, with "direct1" procedures in the list of procedures # provided by std. @@ -284,57 +296,77 @@ source [file join pkg pkg2_b.tcl]}}}" # Both failures are caused by Tcl code executed in pkgIndex.tcl. test pkgMkIndex-5.1 {requires -direct package} { - pkgtest::runIndex pkg std.tcl + pkgtest::runIndex -lazy $fullPkgPath std.tcl } {0 {{std:1.0 {tclPkgSetup {std.tcl source {::std::p1 ::std::p2}}}}}} test pkgMkIndex-6.1 {pkg1 requires pkg3} { - pkgtest::runIndex pkg pkg1.tcl pkg3.tcl + 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 pkg pkg1.tcl pkg3.tcl -} "0 {{pkg1:1.0 {source [file join pkg pkg1.tcl]}} {pkg3:1.0 {source [file join pkg pkg3.tcl]}}}" + pkgtest::runIndex -direct $fullPkgPath pkg1.tcl pkg3.tcl +} "0 {{pkg1:1.0 {source [file join $fullPkgPath pkg1.tcl]}} {pkg3:1.0 {source [file join $fullPkgPath pkg3.tcl]}}}" test pkgMkIndex-7.1 {pkg4 uses pkg3} { - pkgtest::runIndex pkg pkg4.tcl pkg3.tcl + 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 pkg pkg4.tcl pkg3.tcl -} "0 {{pkg3:1.0 {source [file join pkg pkg3.tcl]}} {pkg4:1.0 {source [file join pkg pkg4.tcl]}}}" + pkgtest::runIndex -direct $fullPkgPath pkg4.tcl pkg3.tcl +} "0 {{pkg3:1.0 {source [file join $fullPkgPath pkg3.tcl]}} {pkg4:1.0 {source [file join $fullPkgPath pkg4.tcl]}}}" test pkgMkIndex-8.1 {pkg5 uses pkg2} { - pkgtest::runIndex pkg pkg5.tcl pkg2_a.tcl pkg2_b.tcl + 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 pkg pkg5.tcl pkg2_a.tcl pkg2_b.tcl -} "0 {{pkg2:1.0 {source [file join pkg pkg2_a.tcl] -source [file join pkg pkg2_b.tcl]}} {pkg5:1.0 {source [file join pkg pkg5.tcl]}}}" + pkgtest::runIndex -direct $fullPkgPath pkg5.tcl pkg2_a.tcl pkg2_b.tcl +} "0 {{pkg2:1.0 {source [file join $fullPkgPath pkg2_a.tcl] +source [file join $fullPkgPath pkg2_b.tcl]}} {pkg5:1.0 {source [file join $fullPkgPath pkg5.tcl]}}}" test pkgMkIndex-9.1 {circular packages} { - pkgtest::runIndex pkg circ1.tcl circ2.tcl circ3.tcl + 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}}}}} -# Try to find one of the DLLs in the dltest directory -set x [file join [pwd] [file dirname [info script]]] -set x [file join $x ../unix/dltest/pkga[info sharedlibextension]] -if {[file exists $x]} { - file copy -force $x pkg - test pkgMkIndex-10.1 {package in DLL and script} { - pkgtest::runIndex pkg pkga[info sharedlibextension] pkga.tcl - } {0 {{Pkga:1.0 {tclPkgSetup {pkga.so load {pkga_eq pkga_quote}} {pkga.tcl source pkga_neq}}}}} - test pkgMkIndex-10.2 {package in DLL hidden by -load} { - pkgtest::runIndex -load Pkg* -- pkg pkga[info sharedlibextension] - } {0 {}} -} else { - puts "Skipping pkgMkIndex-10.1 (index of DLL and script)" -} +# Some tests require the existence of one of the DLLs in the dltest directory +set x [file join [file dirname [info nameofexecutable]] dltest \ + pkga[info sharedlibextension]] +set dll "[file tail $x]Required" +set ::tcltest::testConstraints($dll) [file exists $x] + +test pkgMkIndex-10.1 {package in DLL and script} $dll { + file copy -force $x $fullPkgPath + pkgtest::runIndex -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} $dll { + pkgtest::runIndex -lazy -load Pkg* -- $fullPkgPath pkga[info sharedlibextension] +} {0 {}} + +# Tolerate "namespace import" at the global scope + +test pkgMkIndex-11.1 {conflicting namespace imports} { + pkgtest::runIndex -lazy $fullPkgPath import.tcl +} {0 {{fubar:1.0 {tclPkgSetup {import.tcl source ::fubar::foo}}}}} + +# 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) + +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}}}}}} + +# Proc names with embedded spaces are properly listed (ie, correct number of +# braces) in result +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}}}}}}} -# # cleanup -# -if {![info exist TESTS]} { - file delete [file join pkg pkgIndex.tcl] - namespace delete pkgtest -} + +namespace delete pkgtest +cd $origDir +::tcltest::cleanupTests +return + + |