Make the pure-perl fallback work under -c (RT#78619)
[p5sagit/Devel-GlobalDestruction.git] / t / 03_minusc.t
CommitLineData
09b12813 1use strict;
2use warnings;
3
4BEGIN {
5 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
6 no strict 'refs';
7 no warnings 'redefine';
8
9 for my $f (qw(DynaLoader::bootstrap XSLoader::load)) {
10 my ($mod) = $f =~ /^ (.+) \:\: [^:]+ $/x;
11 eval "require $mod" or die $@;
12
13 my $orig = \&$f;
14 *$f = sub {
15 die 'no XS' if ($_[0]||'') eq 'Devel::GlobalDestruction';
16 goto $orig;
17 };
18 }
19 }
20}
21
22{
23 package Test::Scope::Guard;
24 sub new { my ($class, $code) = @_; bless [$code], $class; }
25 sub DESTROY { my $self = shift; $self->[0]->() }
26}
27
28sub ok ($$) {
29 print "not " if !$_[0];
30 print "ok";
31 print " - $_[1]" if defined $_[1];
32 print "\n";
33 !!$_[0]
34}
35
36BEGIN {
37 require B;
38 B::minus_c();
39
40 print "1..2\n";
41 ok( $^C, "Test properly running under minus-c" );
42}
43
44use Devel::GlobalDestruction;
45
46our $foo;
47BEGIN {
48 $foo = Test::Scope::Guard->new( sub {
49 ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) or do {
50 require POSIX;
51 POSIX::_exit(1);
52 };
53 });
54}