Skip to content

Commit

Permalink
Test of nested ownership destruction order
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Oct 22, 2024
1 parent c1d266d commit 21d0451
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/oo.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21d0451

Please sign in to comment.