Index: Makefile.in =================================================================== diff -u -N -r37c87756387c17e0f2f43634c0d452a91f91c844 -rdf76a8d9ffa43e250f5cf6b82e229fa51dac3026 --- Makefile.in (.../Makefile.in) (revision 37c87756387c17e0f2f43634c0d452a91f91c844) +++ Makefile.in (.../Makefile.in) (revision df76a8d9ffa43e250f5cf6b82e229fa51dac3026) @@ -583,6 +583,7 @@ $(TCLSH) $(src_test_dir_native)/method-require.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/interceptor-slot.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/alias.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) + $(TCLSH) $(src_test_dir_native)/double-alias.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/protected.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/forward.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/mixinof.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) Index: tests/alias.test =================================================================== diff -u -N -r3ccbf1417d84765af57693523035ecf857e37428 -rdf76a8d9ffa43e250f5cf6b82e229fa51dac3026 --- tests/alias.test (.../alias.test) (revision 3ccbf1417d84765af57693523035ecf857e37428) +++ tests/alias.test (.../alias.test) (revision df76a8d9ffa43e250f5cf6b82e229fa51dac3026) @@ -803,6 +803,46 @@ } # +# Test namespace of aliased methods coming from different namespaces +# +nx::test case proc-alias-target-namespace { + + proc foo {} { + set :foo 1 + namespace current + } + + namespace eval ns1 { + proc bar {} { + set :bar 1 + namespace current + } + } + namespace eval ns2 { + nx::Object create o { + :public object alias foo ::foo + :public object alias bar ::ns1::bar + :public object method baz {} {namespace current} + } + } + + namespace eval ns3 { + nx::Object create o + set handle [o public object method FOO {} {namespace current}] + ::ns2::o public object alias FOO $handle + } + + # + # The following tests show, that the defining namespace of the + # target method prevails always + # + ? {ns2::o foo} :: "alias to a global Tcl proc" + ? {ns2::o bar} ::ns1 "alias to a namespaced Tcl proc" + ? {ns2::o baz} ::ns2 "a method defined locally in ns2::o" + ? {ns2::o FOO} ::ns3 "alias to to method defined in ::ns3" +} + +# # Local variables: # mode: tcl # tcl-indent-level: 2 Index: tests/double-alias.tcl =================================================================== diff -u -N --- tests/double-alias.tcl (revision 0) +++ tests/double-alias.tcl (revision df76a8d9ffa43e250f5cf6b82e229fa51dac3026) @@ -0,0 +1,173 @@ +package prefer latest +package require nx::test + + +nx::test case alias-redefine-method1 { + # + # redefine an object method by an alias pointing to an alias + # + proc ::foo args {;} + + nx::Object create o + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR exists" + ? {::nsf::method::alias o BAR ::o::bar} ::o::BAR "redefine an object method with an alias (pointing to an alias) 87a2" +} + +nx::test case alias-redefine-method2 { + # + # redefine an object method by an alias pointing to an object method + # + proc ::foo args {;} + + nx::Object create o + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::o public object method FOO {} {;}} ::o::FOO + + ? {info commands ::o::FOO} ::o::FOO "a command ::o::FOO exists" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR exists" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "redefine an object method with an alias (pointing to a method) 87a2" +} + + +nx::test case alias-double-alias-proc { + + proc ::foo args {;} + nx::Object create o + + ? {info commands ::o::FOO} "" "a command ::o::FOO' does not exist" + ? {info commands ::o::BAR} "" "a command ::o::BAR does not exist" + ? {::nsf::method::alias o FOO ::foo} ::o::FOO "define an object alias based on existing ::foo" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "define an object alias based on alias based on existing ::o::FOO" +} + +nx::test case alias-double-alias-define { + # + # same as alias-double-reference-proc, but method instead of proc as target of o::FOO + # + proc ::foo args {;} + + nx::Object create o + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::FOO} "" "a command ::o::FOO' does not exists" + ? {info commands ::o::BAR} "" "a command ::o::BAR does not exist" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "define an object alias based on existing ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "define an object alias based on alias based on existing (?) ::o::bar" +} + + +nx::test case alias-double-alias-redefine { + # + # same as alias-double-reference-define, but redefined instead of new definition + # + proc ::foo args {;} + + nx::Object create o + ? {::nsf::method::alias ::o FOO ::foo} ::o::FOO + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::FOO} ::o::FOO "a command ::o::FOO' exists" + ? {info commands ::o::BAR} "" "a command ::o::BAR does not exist" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "redefine an object alias based on existing ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "define an object alias based on alias based on existing ::o::FOO" +} + +nx::test case alias-double-alias-redefine0 { + # + # same as alias-double-reference-define, but redefined second cmd instead of new definition + # + proc ::foo args {;} + + nx::Object create o + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::FOO} "" "a command ::o::FOO' does not exist" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR exists" + ? {::nsf::method::alias o FOO ::foo} ::o::FOO "define an object alias based on existing ::foo" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "redefine an object alias based on alias based on existing ::o::FOO 87a2" +} + +nx::test case alias-double-alias-redefine1 { + # + # same as alias-double-reference-define, but redefined second cmd instead of new definition + # + proc ::foo args {;} + + nx::Object create o + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::FOO} "" "a command ::o::FOO' does not exist" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR exists" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "define an object alias based on existing ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "redefine an object alias based on alias based on existing ::o::FOO 87a2" +} + +nx::test case alias-double-alias-redefine2 { + # + # same as alias-double-reference-define, but redefined twice instead of new definition + # + proc ::foo args {;} + + nx::Object create o + ? {::nsf::method::alias ::o FOO ::foo} ::o::FOO + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::nsf::method::alias ::o bar ::foo} ::o::bar + + ? {info commands ::o::bar} ::o::bar "::o::bar exists" + ? {info commands ::o::FOO} ::o::FOO "a command ::o::FOO' exists" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR exists" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "redefine an object alias based on existing ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "redefine an object alias based on alias based on existing ::o::FOO 87a2" +} + + + +nx::test case alias-double-alias-object-method-redefine { + + proc ::foo args {;} + + nx::Object create o + ? {::nsf::method::alias ::o FOO ::foo} ::o::FOO + ? {::o public object method bar {} {;}} ::o::bar + + ? {info commands ::o::bar} ::o::bar "handle ::o::bar exists" + ? {info commands ::o::FOO} ::o::FOO "a command ::o::FOO' exists" + ? {info commands ::o::BAR} "" "a command ::o::BAR does not exist" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "redefine an object alias based on existing (?) ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "define an object alias based on alias based on existing ::o::FOO" + ? {info exists ::nsf::alias(::o,FOO,1)} 1 + ? {info exists ::nsf::alias(::o,BAR,1)} 1 + + o public object method bar {} {} + ? {info exists ::nsf::alias(::o,FOO,1)} 1 + ? {info exists ::nsf::alias(::o,BAR,1)} 1 +} + + +nx::test case alias-double-alias-object-method-redefine2 { + + proc ::foo args {;} + + nx::Object create o + ? {::nsf::method::alias ::o FOO ::foo} ::o::FOO + ? {::o public object method BAR {} {;}} ::o::BAR + ? {::o public object method bar {} {;}} ::o::bar + + ? {info commands ::o::bar} ::o::bar "handle ::o::bar exists" + ? {info commands ::o::FOO} ::o::FOO "a command ::o::FOO' exists" + ? {info commands ::o::BAR} ::o::BAR "a command ::o::BAR does not exist" + ? {::nsf::method::alias o FOO ::o::bar} ::o::FOO "redefine an object alias based on existing (?) ::o::bar" + ? {::nsf::method::alias o BAR ::o::FOO} ::o::BAR "redefine an object alias based on alias based on existing ::o::FOO 87a2" +} + +