Index: library/lib/test.xotcl =================================================================== diff -u -r670151ba40e8da27625ed679f2d3ff58d1763239 -r70b3b6899c6b462b4c52d864617d8da2ce3a8f5a --- library/lib/test.xotcl (.../test.xotcl) (revision 670151ba40e8da27625ed679f2d3ff58d1763239) +++ library/lib/test.xotcl (.../test.xotcl) (revision 70b3b6899c6b462b4c52d864617d8da2ce3a8f5a) @@ -24,19 +24,44 @@ } } - Class create Test -parameter { - {name ""} - cmd - {namespace ::} - {verbose 0} - {expected 1} - {count 100} - msg setResult errorReport - pre post - } { + Class create Test { + + :attribute {name ""} + :attribute cmd + :attribute {namespace ::} + :attribute {verbose 0} + :attribute {expected 1} + :attribute {count 100} + :attribute msg + :attribute setResult + :attribute errorReport + :attribute pre + :attribute post + set :count 0 - :public object method case {name} {set :case $name} + :public object method case {name arg:optional} { + # + # Experimental version of Test case, which (1) accepts test case as argument + # and (2) destroys all created objects on exit (auto cleanup) + # + # General limitation: namespace resolving differs in nested evals + # from global evals. So, this approach is not suitable for all test + # (but for most). + # + # Current limitations: just for xotcl2, no method/mixin cleanup/var cleanup + # + set :case $name + if {[info exists arg]} { + foreach o [Object info instances -closure] {set pre_exist($o) 1} + namespace eval :: [list $o eval $arg] + foreach o [Object info instances -closure] { + if {[info exists pre_exist($o)]} continue + #puts "must destroy $o" + if {[::xotcl::is $o object]} {$o destroy} + } + } + } :public object method parameter {name value:optional} { if {[info exists value]} {