5 package Test::Scope::Guard;
6 sub new { my ($class, $code) = @_; bless [$code], $class; }
7 sub DESTROY { my $self = shift; $self->[0]->() }
14 # try to ensure this is the last-most END so we capture future tests
15 # running in other ENDs
17 my $reinject_retries = my $max_retry = 5;
20 my $tail = (B::end_av()->ARRAY)[-1];
21 if (!defined $tail or $tail == $end_worker) {
23 $reinject_retries = 0;
25 elsif ($reinject_retries--) {
26 push @{B::end_av()->object_2svref}, $end_worker;
29 print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n";
34 END { push @{B::end_av()->object_2svref}, $end_worker }
37 $had_error++, print "not " if !$_[0];
39 print " - $_[1]" if defined $_[1];
44 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), 'Not yet in GD while in END block 2' )
47 ok( eval "use Devel::GlobalDestruction::XS; 1", "use Devel::GlobalDestruction::XS" );
49 ok( defined prototype \&Devel::GlobalDestruction::XS::in_global_destruction, "defined prototype" );
51 ok( prototype \&Devel::GlobalDestruction::XS::in_global_destruction eq "", "empty prototype" );
53 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "Runtime is not GD" );
55 our $sg1 = Test::Scope::Guard->new(sub { ok( Devel::GlobalDestruction::XS::in_global_destruction(), "Final cleanup object destruction properly in GD" ) });
58 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), 'Not yet in GD while in END block 1' )
61 our $sg2 = Test::Scope::Guard->new(sub { ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "Object destruction in END not considered GD" ) });