5 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
7 die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm';
13 package Test::Scope::Guard;
14 sub new { my ($class, $code) = @_; bless [$code], $class; }
15 sub DESTROY { my $self = shift; $self->[0]->() }
22 # try to ensure this is the last-most END so we capture future tests
23 # running in other ENDs
25 my $reinject_retries = my $max_retry = 5;
28 my $tail = (B::end_av()->ARRAY)[-1];
29 if (!defined $tail or $tail == $end_worker) {
31 $reinject_retries = 0;
33 elsif ($reinject_retries--) {
34 push @{B::end_av()->object_2svref}, $end_worker;
37 print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n";
42 END { push @{B::end_av()->object_2svref}, $end_worker }
45 $had_error++, print "not " if !$_[0];
47 print " - $_[1]" if defined $_[1];
52 ok( ! in_global_destruction(), 'Not yet in GD while in END block 2' )
55 ok( eval "use Devel::GlobalDestruction; 1", "use Devel::GlobalDestruction" );
57 ok( defined &in_global_destruction, "exported" );
59 ok( defined prototype \&in_global_destruction, "defined prototype" );
61 ok( prototype \&in_global_destruction eq "", "empty prototype" );
63 ok( ! in_global_destruction(), "Runtime is not GD" );
65 our $sg1 = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) });
68 ok( ! in_global_destruction(), 'Not yet in GD while in END block 1' )
71 our $sg2 = Test::Scope::Guard->new(sub { ok( ! in_global_destruction(), "Object destruction in END not considered GD" ) });