Perl 5.6 compat
[p5sagit/Devel-GlobalDestruction-XS.git] / t / 01_basic.t
CommitLineData
101e5667 1use strict;
2use warnings;
cac979c6 3no warnings 'once';
101e5667 4
5BEGIN {
6 package Test::Scope::Guard;
7 sub new { my ($class, $code) = @_; bless [$code], $class; }
8 sub DESTROY { my $self = shift; $self->[0]->() }
9}
10
11print "1..8\n";
12
13our $had_error;
14
101e5667 15sub ok ($$) {
16 $had_error++, print "not " if !$_[0];
17 print "ok";
18 print " - $_[1]" if defined $_[1];
19 print "\n";
20}
21
22END {
23 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), 'Not yet in GD while in END block 2' )
24}
25
26ok( eval "use Devel::GlobalDestruction::XS; 1", "use Devel::GlobalDestruction::XS" );
27
28ok( defined prototype \&Devel::GlobalDestruction::XS::in_global_destruction, "defined prototype" );
29
30ok( prototype \&Devel::GlobalDestruction::XS::in_global_destruction eq "", "empty prototype" );
31
32ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "Runtime is not GD" );
33
34our $sg1 = Test::Scope::Guard->new(sub { ok( Devel::GlobalDestruction::XS::in_global_destruction(), "Final cleanup object destruction properly in GD" ) });
35
36END {
37 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), 'Not yet in GD while in END block 1' )
38}
39
40our $sg2 = Test::Scope::Guard->new(sub { ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "Object destruction in END not considered GD" ) });
41END { undef $sg2 }