Index: tests/interp.test =================================================================== diff -u -rd72a757e0aa13c9e34e5e8d284a6a3a833b9f6e6 -rcae9407ff24389d6f950a07279adb31750793e02 --- tests/interp.test (.../interp.test) (revision d72a757e0aa13c9e34e5e8d284a6a3a833b9f6e6) +++ tests/interp.test (.../interp.test) (revision cae9407ff24389d6f950a07279adb31750793e02) @@ -10,6 +10,7 @@ # # Create a slave interp for testing # + global i set i [interp create] # @@ -21,9 +22,9 @@ } $i hide foo - ? [list $i eval [list info commands ::nx::Object]] "" + ? {$i eval [list info commands ::nx::Object]} "" $i eval [list package req nx] - ? [list $i eval [list info commands ::nx::Object]] ::nx::Object + ? {$i eval [list info commands ::nx::Object]} ::nx::Object # # Tcl's hiding mechansim only applies to objects/classes in the # top-level namespace. So any non-globally namespaced ones and @@ -59,9 +60,9 @@ return [::nsf::current object]-[:info class]-[::nsf::current class] } }} - ? [list $i eval [list info commands ::o]] ::o - ? [list $i eval [list info commands ::C]] ::C - ? [list $i eval [list info commands ::M]] ::M + ? {$i eval {info commands ::o}} ::o + ? {$i eval {info commands ::C}} ::C + ? {$i eval {info commands ::M}} ::M # # [interp hide] performs a partial and widely silent deletion @@ -74,51 +75,50 @@ # target anymore ... # - ? [list interp hidden $i] "foo" + ? {interp hidden $i} "foo" $i hide o - ? [list interp hidden $i] "foo o" - ? [list $i eval [list ::o]] "invalid command name \"::o\"" - ? [list $i eval [list info commands ::o]] "" + ? {interp hidden $i} "foo o" + ? {$i eval ::o} "invalid command name \"::o\"" + ? {$i eval {info commands ::o}} "" - ? [list interp eval $i [list ::C create ::c]] ::c + ? {interp eval $i {::C create ::c}} ::c # set some relationships to test later ... - ? [list interp eval $i [list ::C mixin add ::M]] ::M - ? [list interp eval $i [list ::C class mixin add ::M]] ::M + ? {interp eval $i {::C mixin add ::M}} ::M + ? {interp eval $i {::C class mixin add ::M}} ::M $i hide C - ? [list interp eval $i [list ::C create ::c2]] {invalid command name "::C"} + ? {interp eval $i {::C create ::c2}} {invalid command name "::C"} # # However, the object structure is effectively preserved within the # object system and object relations are intact, e.g., the object is # still reported as an instance of a class. # - ? [list $i eval [list nx::Object info instances ::o]] "::o" - ? [list interp invokehidden $i o ::nsf::methods::object::info::class] "::nx::Object" - ? [list interp invokehidden $i o info class] "::nx::Object" + ? {$i eval {nx::Object info instances ::o}} "::o" + ? {interp invokehidden $i o ::nsf::methods::object::info::class} "::nx::Object" + ? {interp invokehidden $i o info class} "::nx::Object" - ? [list interp eval $i {c info class}] ::C - ? [list interp eval $i {c info class}] ::C - ? [list interp invokehidden $i C info instances ::c] ::c - ? [list interp invokehidden $i C info mixin classes] ::M + ? {interp eval $i {c info class}} ::C + ? {interp invokehidden $i C info instances ::c} ::c + ? {interp invokehidden $i C info mixin classes} ::M + # Note, for all introspections that do *not* try to convert the # Tcl_Obj into an object or a class, but treat it as a pattern (or # the like) we are fine ... - ? [list $i eval {M info mixinof ::C}] "::C ::C" - ? [list $i eval {M info mixinof -scope class ::C}] "::C" - ? [list $i eval {M info mixinof -scope object ::C}] "::C" + ? {$i eval {M info mixinof ::C}} "::C ::C" + ? {$i eval {M info mixinof -scope class ::C}} "::C" + ? {$i eval {M info mixinof -scope object ::C}} "::C" # dispatch to object-provided method (with the object being hidden) - ? [list interp eval $i {c bar}] OK - + ? {interp eval $i {c bar}} OK # dispatch to class-provided methods (with the class being hidden) - ? [list interp eval $i {c bar}] OK + ? {interp eval $i {c bar}} OK # dispatch to mixed-in methods (which do basic introspection on the hidden object) ... - ? [list interp invokehidden $i C foo] ::C-::nx::Class-::M - ? [list interp eval $i {c foo}] ::c-::C-::M + ? {interp invokehidden $i C foo} ::C-::nx::Class-::M + ? {interp eval $i {c foo}} ::c-::C-::M # # 1) Implicit destruction (through NSF's exit handler) @@ -132,23 +132,43 @@ # interp by using ::nsf::finalize; to do some smoke testing of the # cleanup results. As for the cleanup procedre, this is equivalent # to: interp delete $i + + $i eval {::nsf::finalize} - - ? [list $i eval {interp hidden}] foo - ? [list $i eval [list info commands ::o]] "" - ? [list $i eval [list info commands ::C]] "" - + + # The destructor of e.g. object o sets a global variable with the + # object name. The following test checks therfore, whether the + # destructor was executed. # - # Were the app-level destructors called effectively? + # However, as documented ::nsf::finalize has to be the final nsf cmd + # in an interp. The behavior after finalize is undefined and depends + # in the detail on several compiler flags. For example, when + # MEM_COUNT is activated, a full cleanup us performed by nsf, + # causing the deletion of all variables and cmds. This is necessary + # to ensure a defined situation of the refcounts when for debugging. + # Therefore the following cmds will fail - for the time being + # deactivated. # - ? [list $i eval { info exists ::o }] 1 - ? [list $i eval { set ::o }] "" - ? [list $i eval { info exists ::c }] 1 - ? [list $i eval { set ::c }] ::C - - + if {0} { + ? {$i eval { info exists ::o }} 1 + + ? {$i eval {interp hidden}} foo + ? {$i eval {info commands ::o}} "" + ? {$i eval {info commands ::C}} "" + + # + # Were the app-level destructors called effectively? + # + ? {$i eval { info exists ::o }} 1 + ? {$i eval { set ::o }} "" + ? {$i eval { info exists ::c }} 1 + ? {$i eval { set ::c }} ::C + } interp delete $i +} +nx::Test case hidden-cmds+explicit-delete { + # # 2) Explicit destruction # @@ -187,6 +207,9 @@ [::nsf::object::exists ::o2] }] {{} {} {} 0} +} + +nx::Test case hide-and-re-expose { # # 3) hide and re-expose # @@ -227,18 +250,23 @@ ? [list $i eval {::o foo}] {::o {} ::nx::Object ::nx::Object} $i eval {::nsf::finalize} - - # Was the destructor called? - ? [list interp eval $i {info exists ::o}] 1 - ? [list interp eval $i {set ::o}] 1 - - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] - }] {{} {}} "Check cleaned-up state" + # deactivated, SEE above + if {0} { + # Was the destructor called? + ? [list interp eval $i {info exists ::o}] 1 + ? [list interp eval $i {set ::o}] 1 + + ? [list interp eval $i { + list [interp hidden] \ + [info commands ::o] + }] {{} {}} "Check cleaned-up state" + } interp delete $i +} +nx::Test case command-renaming { + # 4) hide/re-expose with "command renaming" set i [interp create] @@ -282,17 +310,23 @@ $i eval {::nsf::finalize} - # Was the destructor called? - ? [list interp eval $i {info exists ::o}] 1 - ? [list interp eval $i {set ::o}] 1 - - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] - }] {{} {}} "Check cleaned-up state" - + # deactivated, SEE above + if {0} { + # Was the destructor called? + ? [list interp eval $i {info exists ::o}] 1 + ? [list interp eval $i {set ::o}] 1 + + ? [list interp eval $i { + list [interp hidden] \ + [info commands ::o] + }] {{} {}} "Check cleaned-up state" + } interp delete $i +} + +nx::Test case namespaced-object { + # 5) Rename namespaced object to global one and hide ... set i [interp create] @@ -324,10 +358,16 @@ [::nsf::object::exists ::X] }] {X {} ::X 0} $i eval {::nsf::finalize} - ? [list interp eval $i {info exists ::X}] 1 - ? [list interp eval $i {set ::X}] 1 + # deactivated, SEE above + if {0} { + ? [list interp eval $i {info exists ::X}] 1 + ? [list interp eval $i {set ::X}] 1 + } interp delete $i +} +nx::Test case deletion-order { + # # 6) Deletion order # @@ -354,12 +394,17 @@ $i hide o $i hide C $i eval {::nsf::finalize} - ? [list interp eval $i {info exists ::C}] 1 - ? [list interp eval $i {set ::C}] 1 - ? [list interp eval $i {info exists ::o}] 1 - ? [list interp eval $i {set ::o}] 1 + # deactivated, SEE above + if {0} { + ? [list interp eval $i {info exists ::C}] 1 + ? [list interp eval $i {set ::C}] 1 + ? [list interp eval $i {info exists ::o}] 1 + ? [list interp eval $i {set ::o}] 1 + } interp delete $i +} +nx::Test case error-in-destroy { # 8a) Some stumbling blocks in destructors: [error] in app-level destroy set i [interp create] $i eval {