Sub::Exporter::Progressive may break when loaded in GD so preload it in test
[p5sagit/Devel-GlobalDestruction.git] / t / 06_load-in-gd.t
CommitLineData
350bef65 1use strict;
2use warnings;
3
4BEGIN {
5 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
6 unshift @INC, sub {
7 die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm';
8 };
9 }
10}
11
12{
13 package Test::Scope::Guard;
14 sub new { my ($class, $code) = @_; bless [$code], $class; }
15 sub DESTROY { my $self = shift; $self->[0]->() }
16}
17
9d52b29f 18use POSIX qw(_exit);
19
20# doesn't always work when loaded in gd, so pre-load it
21use Sub::Exporter::Progressive ();
22
23$|++;
24print "1..3\n";
350bef65 25
26our $alive = Test::Scope::Guard->new(sub {
27 require Devel::GlobalDestruction;
28 my $gd = Devel::GlobalDestruction::in_global_destruction();
9d52b29f 29 print(($gd ? '' : 'not ') . "ok 3 - global destruct detected when loaded during GD\n");
30 _exit($gd ? 0 : 1);
350bef65 31});
32
9d52b29f 33print(($alive ? '' : 'not ') . "ok 1 - alive during runtime\n");
34END {
35 print(($alive ? '' : 'not ') . "ok 2 - alive during END\n");
36}