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
26 my $reinject_retries = my $max_retry = 5;
29 my $tail = (B::end_av()->ARRAY)[-1];
30 if (!defined $tail or $tail == $end_worker) {
32 $reinject_retries = 0;
34 elsif ($reinject_retries--) {
35 push @{B::end_av()->object_2svref}, $end_worker;
38 print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n";
43 eval 'END { push @{B::end_av()->object_2svref}, $end_worker }';
45 # B::end_av isn't available on 5.6, so just use a basic end block
47 eval 'END { $? = $had_error || 0 }';
51 $had_error++, print "not " if !$_[0];
53 print " - $_[1]" if defined $_[1];
58 ok( ! in_global_destruction(), 'Not yet in GD while in END block 2' )
61 ok( eval "use Devel::GlobalDestruction; 1", "use Devel::GlobalDestruction" );
63 ok( defined &in_global_destruction, "exported" );
65 ok( defined prototype \&in_global_destruction, "defined prototype" );
67 ok( prototype \&in_global_destruction eq "", "empty prototype" );
69 ok( ! in_global_destruction(), "Runtime is not GD" );
72 $sg1 = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) });
75 ok( ! in_global_destruction(), 'Not yet in GD while in END block 1' )
78 our $sg2 = Test::Scope::Guard->new(sub { ok( ! in_global_destruction(), "Object destruction in END not considered GD" ) });