5 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
7 no warnings 'redefine';
8 my $orig = \&DynaLoader::bootstrap;
9 *DynaLoader::bootstrap = sub {
10 die 'no XS' if $_[0] eq 'Devel::GlobalDestruction';
17 package Test::Scope::Guard;
18 sub new { my ($class, $code) = @_; bless [$code], $class; }
19 sub DESTROY { my $self = shift; $self->[0]->() }
26 # try to ensure this is the last-most END so we capture future tests
27 # running in other ENDs
29 my $reinject_retries = my $max_retry = 5;
32 my $tail = (B::end_av()->ARRAY)[-1];
33 if (!defined $tail or $tail == $end_worker) {
35 $reinject_retries = 0;
37 elsif ($reinject_retries--) {
38 push @{B::end_av()->object_2svref}, $end_worker;
41 print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n";
46 END { push @{B::end_av()->object_2svref}, $end_worker }
49 $had_error++, print "not " if !$_[0];
51 print " - $_[1]" if defined $_[1];
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(), "not in GD" );
65 our $sg = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "in GD" ) });