5 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
7 no warnings 'redefine';
9 for my $f (qw(DynaLoader::bootstrap XSLoader::load)) {
10 my ($mod) = $f =~ /^ (.+) \:\: [^:]+ $/x;
11 eval "require $mod" or die $@;
15 die 'no XS' if ($_[0]||'') eq 'Devel::GlobalDestruction';
23 package Test::Scope::Guard;
24 sub new { my ($class, $code) = @_; bless [$code], $class; }
25 sub DESTROY { my $self = shift; $self->[0]->() }
32 # try to ensure this is the last-most END so we capture future tests
33 # running in other ENDs
35 my $reinject_retries = my $max_retry = 5;
38 my $tail = (B::end_av()->ARRAY)[-1];
39 if (!defined $tail or $tail == $end_worker) {
41 $reinject_retries = 0;
43 elsif ($reinject_retries--) {
44 push @{B::end_av()->object_2svref}, $end_worker;
47 print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n";
52 END { push @{B::end_av()->object_2svref}, $end_worker }
55 $had_error++, print "not " if !$_[0];
57 print " - $_[1]" if defined $_[1];
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(), "not in GD" );
71 our $sg = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "in GD" ) });