6 if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
8 die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm';
14 package Test::Scope::Guard;
15 sub new { my ($class, $code) = @_; bless [$code], $class; }
16 sub DESTROY { my $self = shift; $self->[0]->() }
19 package Test::Thread::Clone;
21 sub new { my ($class, $code) = @_; push @code, $code; bless [$code], $class; }
22 sub CLONE { $_->() for @code }
30 our $had_error :shared;
31 END { $? = $had_error||0 }
34 $had_error++, print "not " if !$_[0];
36 print " - $_[1]" if defined $_[1];
40 # load it before spawning a thread, that's the whole point
41 use Devel::GlobalDestruction;
43 our $cloner = Test::Thread::Clone->new(sub {
44 ok( ! in_global_destruction(), "CLONE is not GD" );
45 my $guard = Test::Scope::Guard->new(sub {
46 ok( ! in_global_destruction(), "DESTROY during CLONE is not GD");
49 our $global = Test::Scope::Guard->new(sub {
50 ok( in_global_destruction(), "Final cleanup object destruction properly in GD in " . (threads->tid ? 'thread' : 'main program') );
54 # just die so we don't need to deal with testcount skew
55 unless ( ($_[0]||'') eq 'arg' ) {
57 die "Argument passing failed!";
59 # nothing really to do in here
63 threads->create('do_test', 'arg')->join