diff --git a/tests/oo.test b/tests/oo.test index cc250074949..446b0f96f65 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -392,6 +392,52 @@ test oo-1.21 {basic test of OO functionality: default relations} -setup { } -cleanup { interp delete $fresh } -result {{} {::oo::Slot ::oo::class ::oo::object} {::oo::define::filter ::oo::define::mixin ::oo::define::superclass ::oo::define::variable ::oo::objdefine::filter ::oo::objdefine::mixin ::oo::objdefine::variable} {::oo::Slot ::oo::class} {} {} {} {} {} {} ::oo::object ::oo::object ::oo::class ::oo::class ::oo::class} +test oo-1.22 {basic test of OO functionality: nested ownership destruction order} -setup { + oo::class create parent +} -body { + oo::class create abc { + superclass parent + variable n + constructor {} {set n 0} + method make {i} {set n $i; [self class] create xyz} + destructor {lappend ::deathOrder $n} + } + apply {n { + set ::deathOrder {} + # Make some "nested" objects + set base [abc new] + for {set i 1; set obj $base} {$i < $n} {incr i} { + set obj [$obj make $i] + } + # Kill them all in one go; should come apart in right order! + $base destroy + return $::deathOrder + }} 5 +} -cleanup { + parent destroy +} -result {1 2 3 4 0} +test oo-1.23 {basic test of OO functionality: deep nested ownership} -setup { + oo::class create parent +} -constraints knownBug -body { + oo::class create abc { + superclass parent + method make {} {[self class] create xyz} + destructor {incr ::count} + } + apply {n { + set ::count 0 + # Make a lot of "nested" objects + set base [abc new] + for {set i 1; set obj $base} {$i < $n} {incr i} { + set obj [$obj make] + } + # Kill them all in one go; should not crash! + $base destroy + return [expr {$n - $::count}] + }} 10000 +} -cleanup { + parent destroy +} -result 0 test oo-2.1 {basic test of OO functionality: constructor} -setup { # This is a bit complex because it needs to run in a sub-interp as