Index: tests/interp.test =================================================================== diff -u -rcae9407ff24389d6f950a07279adb31750793e02 -r9318621f9cf5544818fbb03209814fdfc8d2156c --- tests/interp.test (.../interp.test) (revision cae9407ff24389d6f950a07279adb31750793e02) +++ tests/interp.test (.../interp.test) (revision 9318621f9cf5544818fbb03209814fdfc8d2156c) @@ -6,11 +6,11 @@ } nx::Test case hidden-cmds { + global i # # Create a slave interp for testing # - global i set i [interp create] # @@ -37,7 +37,7 @@ # sets a global variable for tracing the processing of the # app-level destructor! # - set ::[namespace tail [::nsf::current object]] [::nsf::current class] + set ::[namespace tail [current object]] [current class] next } }} @@ -47,7 +47,7 @@ # sets a global variable for tracing the processing of the # app-level destructor! # - set ::[namespace tail [::nsf::current object]] [::nsf::current class] + set ::[namespace tail [current object]] [current class] next } @@ -57,7 +57,7 @@ }} $i eval {nx::Class create ::M { :public method foo {} { - return [::nsf::current object]-[:info class]-[::nsf::current class] + return [current object]-[:info class]-[current class] } }} ? {$i eval {info commands ::o}} ::o @@ -129,49 +129,40 @@ # shutdown *after* the exit handler returned! # # For testing, we shutdown the NSF object systems in our slave - # interp by using ::nsf::finalize; to do some smoke testing of the + # 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} + $i eval {nsf::finalize -keepvars} # 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. # - # 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. - # - if {0} { - ? {$i eval { info exists ::o }} 1 + + ? {$i eval { info exists ::o }} 1 + ? {$i eval {interp hidden}} foo + ? {$i eval {info commands ::o}} "" + ? {$i eval {info commands ::C}} "" - ? {$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 - } + # + # 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 } +# +# Explicit destruction +# nx::Test case hidden-cmds+explicit-delete { + global i - # - # 2) Explicit destruction - # set i [interp create] $i eval { package req nx @@ -181,38 +172,34 @@ return ok } }} + + + ? {$i eval {interp hidden}} "" + ? {$i eval {info commands ::o2}} ::o2 + ? {$i eval {nx::Object info instances ::o2}} ::o2 + ? {$i eval {nsf::object::exists ::o2}} 1 - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o2] \ - [nx::Object info instances ::o2] \ - [::nsf::object::exists ::o2] - }] {{} ::o2 ::o2 1} - $i hide o2 - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o2] \ - [nx::Object info instances ::o2] \ - [::nsf::object::exists ::o2] - }] {o2 {} ::o2 0} + ? {$i eval {interp hidden}} o2 + ? {$i eval {info commands ::o2}} "" + ? {$i eval {nx::Object info instances ::o2}} ::o2 + ? {$i eval {nsf::object::exists ::o2}} 0 - ? [list interp invokehidden $i o2 destroy] "ok" - - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o2] \ - [nx::Object info instances ::o2] \ - [::nsf::object::exists ::o2] - }] {{} {} {} 0} + ? {interp invokehidden $i o2 destroy} "ok" + ? {$i eval {interp hidden}} "" + ? {$i eval {info commands ::o2}} "" + ? {$i eval {nx::Object info instances ::o2}} "" + ? {$i eval {nsf::object::exists ::o2}} 0 } + +# +# hide and re-expose +# nx::Test case hide-and-re-expose { - # - # 3) hide and re-expose - # + global i set i [interp create] $i eval { @@ -229,46 +216,44 @@ interp hide {} o } - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {o {} ::o 0} "Check hidden state" + # Check hidden state + ? {interp eval $i {interp hidden}} "o" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {nx::Object info instances ::o}} ::o + ? {interp eval $i {nsf::object::exists ::o}} 0 interp expose $i o - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {{} ::o ::o 1} "Check re-exposed state" - + + # Check re-exposed state + ? {interp eval $i {interp hidden}} "" + ? {interp eval $i {info commands ::o}} "::o" + ? {interp eval $i {nx::Object info instances ::o}} ::o + ? {interp eval $i {nsf::object::exists ::o}} 1 + # # Is the object "alive"? # - ? [list $i eval {::o foo}] {::o {} ::nx::Object ::nx::Object} + ? {$i eval {::o foo}} {::o {} ::nx::Object ::nx::Object} - $i eval {::nsf::finalize} + $i eval {nsf::finalize -keepvars} - # 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" - } + # Was the destructor called? + ? {interp eval $i {info exists ::o}} 1 + ? {interp eval $i {set ::o}} 1 + + # Check cleaned-up state + ? {interp eval $i {interp hidden}} "" + ? {interp eval $i {info commands ::o}} "" + interp delete $i } +# +# hide/re-expose with "command renaming" +# nx::Test case command-renaming { + global i - # 4) hide/re-expose with "command renaming" - set i [interp create] $i eval { package req nx @@ -285,50 +270,48 @@ interp hide {} o O } - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {O {} ::o 0} "Check hidden state -> object command renamed" + # Check hidden state -> object command renamed - ? [list interp invokehidden $i O foo] {::o {} ::nx::Object {invalid command name "::o"}} + ? {interp eval $i {interp hidden}} "O" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {nx::Object info instances ::o}} ::o + ? {interp eval $i {nsf::object::exists ::o}} 0 + ? {interp invokehidden $i O foo} \ + {::o {} ::nx::Object {invalid command name "::o"}} + interp expose $i O OO - ? [list interp eval $i {OO foo}] {::o {} ::nx::Object {invalid command name "::o"}} + ? {interp eval $i {OO foo}} \ + {::o {} ::nx::Object {invalid command name "::o"}} - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [info commands ::OO] \ - [nx::Object info instances ::o] \ - [nx::Object info instances ::OO] \ - [::nsf::object::exists ::o] \ - [::nsf::object::exists ::OO] - }] {{} {} ::OO ::o ::o 0 1} "Check re-exposed state -> object command renamed again"; # should be {} {} ::OO ::o {} 0 1 + ? {interp eval $i {interp hidden}} "" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {info commands ::OO}} ::OO + ? {interp eval $i {nx::Object info instances ::o}} ::o + ? {interp eval $i {nx::Object info instances ::OO}} ::o ;# should be ""? + ? {interp eval $i {nsf::object::exists ::o}} 0 + ? {interp eval $i {nsf::object::exists ::OO}} 1 + + $i eval {nsf::finalize -keepvars} - $i eval {::nsf::finalize} - - # deactivated, SEE above - if {0} { - # Was the destructor called? - ? [list interp eval $i {info exists ::o}] 1 - ? [list interp eval $i {set ::o}] 1 + # Was the destructor called? + ? {interp eval $i {info exists ::o}} 1 + ? {interp eval $i {set ::o}} 1 - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] - }] {{} {}} "Check cleaned-up state" - } - interp delete $i + ? {interp eval $i {interp hidden}} {} + ? {interp eval $i {info commands ::o}} {} + interp delete $i } + +# +# Rename namespaced object to global one and hide ... +# nx::Test case namespaced-object { + global i - # 5) Rename namespaced object to global one and hide ... - set i [interp create] $i eval { package req nx @@ -342,36 +325,38 @@ } } - ? [list $i hide ::ns1::o] {cannot use namespace qualifiers in hidden command token (rename)} + ? {$i hide ::ns1::o} \ + {cannot use namespace qualifiers in hidden command token (rename)} + $i eval {::rename ::ns1::o ::X} - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::X] \ - [nx::Object info instances ::X] \ - [::nsf::object::exists ::X] - }] {{} ::X ::X 1} + + ? {interp eval $i {interp hidden}} {} + ? {interp eval $i {info commands ::X}} {::X} + ? {interp eval $i {nx::Object info instances ::X}} {::X} + ? {interp eval $i {nsf::object::exists ::X}} 1 + $i eval {interp hide {} X} - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::X] \ - [nx::Object info instances ::X] \ - [::nsf::object::exists ::X] - }] {X {} ::X 0} - $i eval {::nsf::finalize} - # deactivated, SEE above - if {0} { - ? [list interp eval $i {info exists ::X}] 1 - ? [list interp eval $i {set ::X}] 1 - } + + ? {interp eval $i {interp hidden}} "X" + ? {interp eval $i {info commands ::X}} {} + ? {interp eval $i {nx::Object info instances ::X}} {::X} + ? {interp eval $i {nsf::object::exists ::X}} 0 + + $i eval {nsf::finalize -keepvars} + + ? {interp eval $i {info exists ::X}} 1 + ? {interp eval $i {set ::X}} 1 + interp delete $i } +# +# Deletion order +# + nx::Test case deletion-order { + global i - # - # 6) Deletion order - # - set i [interp create] $i eval { package req nx @@ -393,19 +378,22 @@ } $i hide o $i hide C - $i eval {::nsf::finalize} - # 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 - } + $i eval {nsf::finalize -keepvars} + + ? {interp eval $i {info exists ::C}} 1 + ? {interp eval $i {set ::C}} 1 + ? {interp eval $i {info exists ::o}} 1 + ? {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 +# +# Some stumbling blocks in destructors: [error] in app-level destroy +# +nx::Test case error-in-destroy-1 { + global i + set i [interp create] $i eval { package req nx @@ -417,23 +405,31 @@ interp hide {} o } - ? [list interp eval $i {::rename ::o ""}] {can't delete "::o": command doesn't exist} + ? {interp eval $i {::rename ::o ""}} \ + {can't delete "::o": command doesn't exist} - ? [list interp invokehidden $i o destroy] "BAFF!" - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {o {} ::o 0} - $i eval {::nsf::finalize} - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] - }] {{} {}} + ? {interp invokehidden $i o destroy} "BAFF!" + + ? {interp eval $i {interp hidden}} "o" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {nx::Object info instances ::o}} "::o" + ? {interp eval $i {nsf::object::exists ::o}} 0 + + $i eval {nsf::finalize} + + ? {interp eval $i {interp hidden}} "" + ? {interp eval $i {info commands ::o}} "" + interp delete $i +} - # 3b) Some stumbling blocks in destructors: [interp hide] in app-level destroy +# +# Some stumbling blocks in destructors: [interp hide] in app-level +# destroy +# +nx::Test case error-in-destroy-2 { + global i + set i [interp create] $i eval { package req nx @@ -461,17 +457,23 @@ } } - ? [list interp eval $i {::bar}] 1 - ? [list interp eval $i {::o destroy}] OK - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {bar {} {} 0} + ? {interp eval $i {::bar}} 1 + ? {interp eval $i {::o destroy}} OK + + ? {interp eval $i {interp hidden}} "bar" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {nx::Object info instances ::o}} "" + ? {interp eval $i {nsf::object::exists ::o}} 0 + interp delete $i +} - # 3b) Some stumbling blocks in destructors: [interp hide] in app-level destroy +# +# Some stumbling blocks in destructors: [interp hide] in app-level destroy +# +nx::Test case error-in-destroy-3 { + global i + set i [interp create] $i eval { package req nx @@ -484,27 +486,29 @@ } interp hide {} o } - - # ? [list interp eval $i {::o destroy}] OK; weird error message when channeling back the error info! - ? [list interp invokehidden $i o destroy] {can't delete "::o": command doesn't exist}; - ? [list interp eval $i { - list [interp hidden] \ - [info commands ::o] \ - [nx::Object info instances ::o] \ - [::nsf::object::exists ::o] - }] {{} {} {} 0} + + ? {interp eval $i {::o destroy}} {invalid command name "::o"} + + ? {interp invokehidden $i o destroy} \ + {can't delete "::o": command doesn't exist} + + ? {interp eval $i {interp hidden}} "" + ? {interp eval $i {info commands ::o}} "" + ? {interp eval $i {nx::Object info instances ::o}} "" + ? {interp eval $i {nsf::object::exists ::o}} 0 + interp delete $i } # # TODO: -# - [::nsf::current calledclass] seems broken -> returns NULL as string value?! +# - [current calledclass] seems broken -> returns NULL as string value?! # - renames to "" in destroy run into an endless loop: # nx::Object create ::o { -# :public method destroy {} { -# ::rename [current] "" -# next -# } -# :destroy -# } +# :public method destroy {} { +# ::rename [current] "" +# next +# } +# :destroy +# } # # \ No newline at end of file