X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01_basic.t;h=c8d847f052ceaaad4be01fbe02dc97461ad6f685;hb=754056f2221e2d174895f3dc6967f6da695333a5;hp=c739a63f84d9920ee14220197eb90bd6e8608bc8;hpb=140a3884a09b85a2f4c988ffea726455e194066d;p=p5sagit%2FDevel-GlobalDestruction.git diff --git a/t/01_basic.t b/t/01_basic.t index c739a63..c8d847f 100644 --- a/t/01_basic.t +++ b/t/01_basic.t @@ -3,19 +3,9 @@ use warnings; BEGIN { if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) { - no strict 'refs'; - no warnings 'redefine'; - - for my $f (qw(DynaLoader::bootstrap XSLoader::load)) { - my ($mod) = $f =~ /^ (.+) \:\: [^:]+ $/x; - eval "require $mod" or die $@; - - my $orig = \&$f; - *$f = sub { - die 'no XS' if ($_[0]||'') eq 'Devel::GlobalDestruction'; - goto $orig; - }; - } + unshift @INC, sub { + die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm'; + }; } } @@ -31,25 +21,31 @@ our $had_error; # try to ensure this is the last-most END so we capture future tests # running in other ENDs -require B; -my $reinject_retries = my $max_retry = 5; -my $end_worker; -$end_worker = sub { - my $tail = (B::end_av()->ARRAY)[-1]; - if (!defined $tail or $tail == $end_worker) { - $? = $had_error || 0; - $reinject_retries = 0; - } - elsif ($reinject_retries--) { - push @{B::end_av()->object_2svref}, $end_worker; - } - else { - print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n"; - require POSIX; - POSIX::_exit( 255 ); - } -}; -END { push @{B::end_av()->object_2svref}, $end_worker } +if ($] >= 5.008) { + require B; + my $reinject_retries = my $max_retry = 5; + my $end_worker; + $end_worker = sub { + my $tail = (B::end_av()->ARRAY)[-1]; + if (!defined $tail or $tail == $end_worker) { + $? = $had_error || 0; + $reinject_retries = 0; + } + elsif ($reinject_retries--) { + push @{B::end_av()->object_2svref}, $end_worker; + } + else { + print STDERR "\n\nSomething is racing with @{[__FILE__]} for final END block definition - can't win after $max_retry iterations :(\n\n"; + require POSIX; + POSIX::_exit( 255 ); + } + }; + eval 'END { push @{B::end_av()->object_2svref}, $end_worker }'; +} +# B::end_av isn't available on 5.6, so just use a basic end block +else { + eval 'END { $? = $had_error || 0 }'; +} sub ok ($$) { $had_error++, print "not " if !$_[0]; @@ -72,7 +68,8 @@ ok( prototype \&in_global_destruction eq "", "empty prototype" ); ok( ! in_global_destruction(), "Runtime is not GD" ); -our $sg1 = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) }); +our $sg1; +$sg1 = Test::Scope::Guard->new(sub { ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) }); END { ok( ! in_global_destruction(), 'Not yet in GD while in END block 1' )