2 # Tests for classes within namespaces
3 # ----------------------------------------------------------------------
4 # AUTHOR: Michael J. McLennan
5 # Bell Labs Innovations for Lucent Technologies
7 # http://www.tcltk.com/itcl
8 # ----------------------------------------------------------------------
9 # Copyright (c) 1993-1998 Lucent Technologies, Inc.
10 # ======================================================================
11 # See the file "license.terms" for information on usage and
12 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 package require tcltest 2.2
15 namespace import ::tcltest::test
16 ::tcltest::loadTestedCommands
19 # ----------------------------------------------------------------------
20 # Classes within namespaces
21 # ----------------------------------------------------------------------
22 test namespace-1.1 {same class name can be used in different namespaces
24 namespace eval test_ns_1 {
35 proc exists {} { return "don't clobber me!" }
37 namespace eval test_ns_2 {
44 set num [expr {$num*$by}]
55 test namespace-1.2 {classes in different namespaces are different
57 list [namespace eval test_ns_1::Counter {info variable tag}] \
58 [namespace eval test_ns_2::Counter {info variable tag}] \
59 } -result {{protected common ::test_ns_1::Counter::tag 1 1} {protected common ::test_ns_2::Counter::tag 2 2}}
61 test namespace-1.3 {create an object in one namespace
63 namespace eval test_ns_1 {
64 list [Counter c] [c ++] [c ++] [c ++] [c ++]
68 test namespace-1.4 {create an object in another namespace
70 namespace eval test_ns_2 {
71 list [Counter c] [c ++] [c ++] [c ++] [c ++]
74 namespace delete ::itcl::internal::variables::test_ns_2
75 namespace delete test_ns_2
78 test namespace-1.5 {can find classes wrapped in a namespace
80 list [catch {test_ns_1::c do itcl::find objects -isa Counter} msg] $msg \
81 [catch {test_ns_1::c do itcl::find objects -class Counter} msg] $msg
82 } -result {0 ::test_ns_1::c 0 ::test_ns_1::c}
84 test namespace-1.6 {can't create an object that clobbers a command in this namespace
86 list [catch {namespace eval test_ns_1 {Counter exists}} msg] $msg
87 } -result {1 {command "exists" already exists in namespace "::test_ns_1"}}
89 test namespace-1.7 {can create an object that shadows a command in the global namespace
91 list [catch {namespace eval test_ns_1 {Counter lreplace}} msg] $msg \
92 [catch {itcl::find objects *lreplace} msg] $msg \
93 [namespace eval test_ns_1 {namespace which lreplace}]
95 namespace delete ::itcl::internal::variables::test_ns_1
96 namespace delete test_ns_1
97 } -result {0 lreplace 0 ::test_ns_1::lreplace ::test_ns_1::lreplace}
99 ::tcltest::cleanupTests