diff options
author | dgp <dgp@users.sourceforge.net> | 2002-07-04 00:32:53 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2002-07-04 00:32:53 (GMT) |
commit | 72dbcf251c1f6a8af1d20d7eaa97bd014445ef71 (patch) | |
tree | ed284d443845c560065f4e46fb85b8099de3eb70 /tests | |
parent | fda47bbaa13e43865058a11d857c9c08ebb02137 (diff) | |
download | tcl-72dbcf251c1f6a8af1d20d7eaa97bd014445ef71.zip tcl-72dbcf251c1f6a8af1d20d7eaa97bd014445ef71.tar.gz tcl-72dbcf251c1f6a8af1d20d7eaa97bd014445ef71.tar.bz2 |
* Fixed [Bug 575857] where this test file
expected to be able to write to [file join [testsDirectory] pkg].
Part of the fix was to import several auxilliary files into the
test file itself.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pkg/circ1.tcl | 34 | ||||
-rw-r--r-- | tests/pkg/circ2.tcl | 25 | ||||
-rw-r--r-- | tests/pkg/circ3.tcl | 25 | ||||
-rw-r--r-- | tests/pkg/global.tcl | 19 | ||||
-rw-r--r-- | tests/pkg/import.tcl | 16 | ||||
-rw-r--r-- | tests/pkg/pkg1.tcl | 26 | ||||
-rw-r--r-- | tests/pkg/pkg2_a.tcl | 22 | ||||
-rw-r--r-- | tests/pkg/pkg2_b.tcl | 22 | ||||
-rw-r--r-- | tests/pkg/pkg3.tcl | 22 | ||||
-rw-r--r-- | tests/pkg/pkg4.tcl | 27 | ||||
-rw-r--r-- | tests/pkg/pkg5.tcl | 30 | ||||
-rw-r--r-- | tests/pkg/pkga.tcl | 15 | ||||
-rw-r--r-- | tests/pkg/samename.tcl | 25 | ||||
-rw-r--r-- | tests/pkg/simple.tcl | 23 | ||||
-rw-r--r-- | tests/pkg/spacename.tcl | 3 | ||||
-rw-r--r-- | tests/pkg/std.tcl | 28 | ||||
-rw-r--r-- | tests/pkgMkIndex.test | 456 |
17 files changed, 442 insertions, 376 deletions
diff --git a/tests/pkg/circ1.tcl b/tests/pkg/circ1.tcl deleted file mode 100644 index 3616621..0000000 --- a/tests/pkg/circ1.tcl +++ /dev/null @@ -1,34 +0,0 @@ -# circ1.tcl -- -# -# Test package for pkg_mkIndex. 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. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: circ1.tcl,v 1.1 1998/10/17 00:21:39 escoffon Exp $ - -package require circ2 1.0 - -package provide circ1 1.0 - -namespace 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 -} diff --git a/tests/pkg/circ2.tcl b/tests/pkg/circ2.tcl deleted file mode 100644 index 66a20a3..0000000 --- a/tests/pkg/circ2.tcl +++ /dev/null @@ -1,25 +0,0 @@ -# circ2.tcl -- -# -# Test package for pkg_mkIndex. This package is required by circ1, and -# requires circ3. Circ3, in turn, requires circ1 to give us a circularity. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: circ2.tcl,v 1.1 1998/10/17 00:21:39 escoffon Exp $ - -package require circ3 1.0 - -package provide circ2 1.0 - -namespace 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]] -} diff --git a/tests/pkg/circ3.tcl b/tests/pkg/circ3.tcl deleted file mode 100644 index ddcb691..0000000 --- a/tests/pkg/circ3.tcl +++ /dev/null @@ -1,25 +0,0 @@ -# circ3.tcl -- -# -# Test package for pkg_mkIndex. This package is required by circ2, and in -# turn requires circ1. This closes the circularity. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: circ3.tcl,v 1.1 1998/10/17 00:21:40 escoffon Exp $ - -package require circ1 1.0 - -package provide circ3 1.0 - -namespace eval circ3 { - namespace export c3-1 c3-4 -} - -proc circ3::c3-1 {} { - return [circ1::c1-3] -} - -proc circ3::c3-2 {} { - return [circ1::c1-4] -} diff --git a/tests/pkg/global.tcl b/tests/pkg/global.tcl deleted file mode 100644 index 38925c5..0000000 --- a/tests/pkg/global.tcl +++ /dev/null @@ -1,19 +0,0 @@ -# global.tcl -- -# -# Test package for pkg_mkIndex. -# Contains global symbols, used to check that they don't have a leading :: -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: global.tcl,v 1.1 1998/10/17 00:21:40 escoffon Exp $ - -package provide global 1.0 - -proc global_lower { stg } { - return [string tolower $stg] -} - -proc global_upper { stg } { - return [string toupper $stg] -} diff --git a/tests/pkg/import.tcl b/tests/pkg/import.tcl deleted file mode 100644 index e7196f5..0000000 --- a/tests/pkg/import.tcl +++ /dev/null @@ -1,16 +0,0 @@ -package provide fubar 1.0 - -namespace eval ::fubar:: { - # - # export only public functions. - # - namespace export {[a-z]*} -} - -proc ::fubar::foo {bar} { - puts "$bar" - return true -} - -namespace import ::fubar::foo - diff --git a/tests/pkg/pkg1.tcl b/tests/pkg/pkg1.tcl deleted file mode 100644 index e2cf960..0000000 --- a/tests/pkg/pkg1.tcl +++ /dev/null @@ -1,26 +0,0 @@ -# pkg1.tcl -- -# -# Test package for pkg_mkIndex. 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). -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: pkg1.tcl,v 1.1 1998/10/17 00:21:40 escoffon Exp $ - -package require pkg3 1.0 - -package provide pkg1 1.0 - -namespace 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] -} diff --git a/tests/pkg/pkg2_a.tcl b/tests/pkg/pkg2_a.tcl deleted file mode 100644 index 85e16c4..0000000 --- a/tests/pkg/pkg2_a.tcl +++ /dev/null @@ -1,22 +0,0 @@ -# pkg2_a.tcl -- -# -# Test package for pkg_mkIndex. This package is required by pkg1. -# This package is split into two files, to test packages that are split -# over multiple files. -# -# Copyright (c) 2998 by Scriptics Corporation. -# -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# SCCS: %Z% %M% %I% %E% %U% - -package provide pkg2 1.0 - -namespace eval pkg2 { - namespace export p2-1 -} - -proc pkg2::p2-1 { num } { - return [expr $num * 2] -} diff --git a/tests/pkg/pkg2_b.tcl b/tests/pkg/pkg2_b.tcl deleted file mode 100644 index 15fb1a8..0000000 --- a/tests/pkg/pkg2_b.tcl +++ /dev/null @@ -1,22 +0,0 @@ -# pkg2_b.tcl -- -# -# Test package for pkg_mkIndex. This package is required by pkg1. -# This package is split into two files, to test packages that are split -# over multiple files. -# -# Copyright (c) 2998 by Scriptics Corporation. -# -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# SCCS: %Z% %M% %I% %E% %U% - -package provide pkg2 1.0 - -namespace eval pkg2 { - namespace export p2-2 -} - -proc pkg2::p2-2 { num } { - return [expr $num * 3] -} diff --git a/tests/pkg/pkg3.tcl b/tests/pkg/pkg3.tcl deleted file mode 100644 index fd769c4..0000000 --- a/tests/pkg/pkg3.tcl +++ /dev/null @@ -1,22 +0,0 @@ -# pkg3.tcl -- -# -# Test package for pkg_mkIndex. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: pkg3.tcl,v 1.1 1998/10/17 00:21:42 escoffon Exp $ - -package provide pkg3 1.0 - -namespace 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]} -} diff --git a/tests/pkg/pkg4.tcl b/tests/pkg/pkg4.tcl deleted file mode 100644 index ccb9291..0000000 --- a/tests/pkg/pkg4.tcl +++ /dev/null @@ -1,27 +0,0 @@ -# pkg4.tcl -- -# -# Test package for pkg_mkIndex. This package requires pkg3, and it calls -# a pkg3 proc in the code that is executed by the file -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: pkg4.tcl,v 1.1 1998/10/17 00:21:42 escoffon Exp $ - -package require pkg3 1.0 - -package provide pkg4 1.0 - -namespace 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] -} diff --git a/tests/pkg/pkg5.tcl b/tests/pkg/pkg5.tcl deleted file mode 100644 index 5e25e6d..0000000 --- a/tests/pkg/pkg5.tcl +++ /dev/null @@ -1,30 +0,0 @@ -# pkg5.tcl -- -# -# Test package for pkg_mkIndex. This package requires pkg2, and it calls -# a pkg2 proc in the code that is executed by the file. -# Pkg2 is a split package. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: pkg5.tcl,v 1.1 1998/10/17 00:21:42 escoffon Exp $ - -package require pkg2 1.0 - -package provide pkg5 1.0 - -namespace 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}] -} diff --git a/tests/pkg/pkga.tcl b/tests/pkg/pkga.tcl deleted file mode 100644 index e964f51..0000000 --- a/tests/pkg/pkga.tcl +++ /dev/null @@ -1,15 +0,0 @@ -# pkga.tcl -- -# -# Test package for pkg_mkIndex. This package provides Pkga, -# which is also provided by a DLL. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: pkga.tcl,v 1.1 1998/12/04 06:28:11 welch Exp $ - -package provide Pkga 1.0 - -proc pkga_neq { x } { - return [expr {! [pkgq_eq $x]}] -} diff --git a/tests/pkg/samename.tcl b/tests/pkg/samename.tcl deleted file mode 100644 index 8aa5080..0000000 --- a/tests/pkg/samename.tcl +++ /dev/null @@ -1,25 +0,0 @@ -package provide football 1.0 - -namespace 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 -} - diff --git a/tests/pkg/simple.tcl b/tests/pkg/simple.tcl deleted file mode 100644 index a2cf121..0000000 --- a/tests/pkg/simple.tcl +++ /dev/null @@ -1,23 +0,0 @@ -# simple.tcl -- -# -# Test package for pkg_mkIndex. This is a simple package, just to check -# basic functionality. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: simple.tcl,v 1.1 1998/10/17 00:21:43 escoffon Exp $ - -package provide simple 1.0 - -namespace eval simple { - namespace export lower upper -} - -proc simple::lower { stg } { - return [string tolower $stg] -} - -proc simple::upper { stg } { - return [string toupper $stg] -} diff --git a/tests/pkg/spacename.tcl b/tests/pkg/spacename.tcl deleted file mode 100644 index 7b48e76..0000000 --- a/tests/pkg/spacename.tcl +++ /dev/null @@ -1,3 +0,0 @@ -package provide spacename 1.0 -proc {a b} {} {} -proc {c d} {} {} diff --git a/tests/pkg/std.tcl b/tests/pkg/std.tcl deleted file mode 100644 index 48c4048..0000000 --- a/tests/pkg/std.tcl +++ /dev/null @@ -1,28 +0,0 @@ -# std.tcl -- -# -# Test package for pkg_mkIndex. -# Does a package require of direct1, whose pkgIndex.tcl entry (in pkg1) -# should be a -direct entry. -# This tests that pkg_mkIndex can handle code that is sourced in pkgIndex.tcl -# files. -# -# Copyright (c) 1998 by Scriptics Corporation. -# All rights reserved. -# -# RCS: @(#) $Id: std.tcl,v 1.1 1998/10/17 00:21:43 escoffon Exp $ - -package require direct1 - -package provide std 1.0 - -namespace eval std { - namespace export p1 p2 -} - -proc std::p1 { stg } { - return [string tolower $stg] -} - -proc std::p2 { stg } { - return [string toupper $stg] -} diff --git a/tests/pkgMkIndex.test b/tests/pkgMkIndex.test index 26e78f5..8ca9796 100644 --- a/tests/pkgMkIndex.test +++ b/tests/pkgMkIndex.test @@ -8,17 +8,14 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: pkgMkIndex.test,v 1.20 2002/06/22 04:19:47 dgp Exp $ +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 namespace import -force ::tcltest::* } -set origDir [pwd] -cd $::tcltest::testsDirectory - -set fullPkgPath [file join $::tcltest::testsDirectory pkg] +set fullPkgPath [makeDirectory 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. @@ -162,7 +159,7 @@ proc pkgtest::createIndex { args } { set patternList [lindex $parsed 2] file mkdir $dirPath - + if {[catch { file delete [file join $dirPath pkgIndex.tcl] eval pkg_mkIndex $options [list $dirPath] $patternList @@ -237,8 +234,7 @@ proc makePkgList { inList } { # returned by pkgtest::parseIndex. # If error, this is the error result. -proc pkgtest::runIndex { args } { - set rv [eval createIndex $args] +proc pkgtest::runCreatedIndex {rv args} { if {[lindex $rv 0] == 0} { set parsed [eval parseArgs $args] set dirPath [lindex $parsed 1] @@ -256,6 +252,10 @@ proc pkgtest::runIndex { args } { return $result } +proc pkgtest::runIndex { args } { + set rv [eval createIndex $args] + return [eval [list runCreatedIndex $rv] $args] +} # If there is no match to the patterns, make sure the directory hasn't # changed on us @@ -264,6 +264,31 @@ test pkgMkIndex-1.1 {nothing matches pattern - current dir is the same} { list [pkgtest::runIndex -lazy $fullPkgPath nomatch.tcl] [pwd] } [list {1 {no files matched glob pattern "nomatch.tcl"}} [pwd]] +makeFile { +# simple.tcl -- +# +# Test package for pkg_mkIndex. This is a simple package, just to check +# basic functionality. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package provide simple 1.0 + +namespace eval simple { + namespace export lower upper +} + +proc simple::lower { stg } { + return [string tolower $stg] +} + +proc simple::upper { stg } { + return [string toupper $stg] +} +} [file join pkg simple.tcl] test pkgMkIndex-2.1 {simple package} { pkgtest::runIndex -lazy $fullPkgPath simple.tcl } {0 {{simple:1.0 {tclPkgSetup {simple.tcl source {::simple::lower ::simple::upper}}}}}} @@ -275,11 +300,83 @@ test pkgMkIndex-2.2 {simple package - use -direct} { test pkgMkIndex-2.3 {simple package - direct loading is default} { pkgtest::runIndex $fullPkgPath simple.tcl } "0 {{simple:1.0 {[list source [file join $fullPkgPath simple.tcl]]}}}" +removeFile [file join pkg simple.tcl] + +makeFile { +# global.tcl -- +# +# Test package for pkg_mkIndex. +# Contains global symbols, used to check that they don't have a leading :: +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package provide global 1.0 + +proc global_lower { stg } { + return [string tolower $stg] +} + +proc global_upper { stg } { + return [string toupper $stg] +} +} [file join pkg global.tcl] test pkgMkIndex-3.1 {simple package with global symbols} { pkgtest::runIndex -lazy $fullPkgPath global.tcl } {0 {{global:1.0 {tclPkgSetup {global.tcl source {global_lower global_upper}}}}}} +removeFile [file join pkg global.tcl] + +makeFile { +# pkg2_a.tcl -- +# +# Test package for pkg_mkIndex. This package is required by pkg1. +# This package is split into two files, to test packages that are split +# over multiple files. +# +# Copyright (c) 2998 by Scriptics Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# SCCS: %Z% %M% %I% %E% %U% + +package provide pkg2 1.0 + +namespace eval pkg2 { + namespace export p2-1 +} + +proc pkg2::p2-1 { num } { + return [expr $num * 2] +} +} [file join pkg pkg2_a.tcl] +makeFile { +# pkg2_b.tcl -- +# +# Test package for pkg_mkIndex. This package is required by pkg1. +# This package is split into two files, to test packages that are split +# over multiple files. +# +# Copyright (c) 2998 by Scriptics Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# SCCS: %Z% %M% %I% %E% %U% +package provide pkg2 1.0 + +namespace eval pkg2 { + namespace export p2-2 +} + +proc pkg2::p2-2 { num } { + return [expr $num * 3] +} +} [file join pkg pkg2_b.tcl] test pkgMkIndex-4.1 {split package} { 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}}}}} @@ -295,10 +392,93 @@ test pkgMkIndex-4.2 {split package - direct loading} { # command "loadJava" which comes from the tclblend pkgIndex.tcl file. # Both failures are caused by Tcl code executed in pkgIndex.tcl. +makeFile { +# std.tcl -- +# +# Test package for pkg_mkIndex. +# Does a package require of direct1, whose pkgIndex.tcl entry (in pkg1) +# should be a -direct entry. +# This tests that pkg_mkIndex can handle code that is sourced in pkgIndex.tcl +# files. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require direct1 + +package provide std 1.0 + +namespace 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 pkg std.tcl] + +makeFile { +# pkg1.tcl -- +# +# Test package for pkg_mkIndex. 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). +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ +package require pkg3 1.0 + +package provide pkg1 1.0 + +namespace 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 { +# pkg3.tcl -- +# +# Test package for pkg_mkIndex. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package provide pkg3 1.0 + +namespace 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}}}}}} @@ -306,7 +486,37 @@ test pkgMkIndex-6.1 {pkg1 requires pkg3} { 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 { +# pkg4.tcl -- +# +# Test package for pkg_mkIndex. This package requires pkg3, and it calls +# a pkg3 proc in the code that is executed by the file +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require pkg3 1.0 + +package provide pkg4 1.0 + +namespace 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}}}}}} @@ -314,7 +524,41 @@ test pkgMkIndex-7.1 {pkg4 uses pkg3} { 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 { +# pkg5.tcl -- +# +# Test package for pkg_mkIndex. This package requires pkg2, and it calls +# a pkg2 proc in the code that is executed by the file. +# Pkg2 is a split package. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require pkg2 1.0 + +package provide pkg5 1.0 + +namespace 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}}}}}} @@ -323,10 +567,106 @@ 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 { +# circ1.tcl -- +# +# Test package for pkg_mkIndex. 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. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require circ2 1.0 + +package provide circ1 1.0 + +namespace 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 { +# circ2.tcl -- +# +# Test package for pkg_mkIndex. This package is required by circ1, and +# requires circ3. Circ3, in turn, requires circ1 to give us a circularity. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require circ3 1.0 + +package provide circ2 1.0 + +namespace 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 { +# circ3.tcl -- +# +# Test package for pkg_mkIndex. This package is required by circ2, and in +# turn requires circ1. This closes the circularity. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package require circ1 1.0 + +package provide circ3 1.0 + +namespace 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 directory set x [file join [file dirname [info nameofexecutable]] dltest \ @@ -334,33 +674,120 @@ set x [file join [file dirname [info nameofexecutable]] dltest \ set dll "[file tail $x]Required" ::tcltest::testConstraint $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 +makeFile { +# pkga.tcl -- +# +# Test package for pkg_mkIndex. This package provides Pkga, +# which is also provided by a DLL. +# +# Copyright (c) 1998 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id: pkgMkIndex.test,v 1.21 2002/07/04 00:32:54 dgp Exp $ + +package provide Pkga 1.0 + +proc 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} $dll { - pkgtest::runIndex -lazy -load Pkg* -- $fullPkgPath pkga[info sharedlibextension] +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 {}} +file delete -force [file join $fullPkgPath [file tail $x]] +removeFile [file join pkg pkga.tcl] # Tolerate "namespace import" at the global scope +makeFile { +package provide fubar 1.0 + +namespace 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.0 + +namespace 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 result +makeFile { +package provide spacename 1.0 +proc {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 function test pkgMkIndex-14.1 {pkg_compareExtension} {unixOnly} { @@ -384,8 +811,9 @@ test pkgMkIndex-14.6 {pkg_compareExtension} {unixOnly} { # cleanup +removeDirectory pkg + namespace delete pkgtest -cd $origDir ::tcltest::cleanupTests return |