fix detection if loaded during global destruction
[p5sagit/Devel-GlobalDestruction.git] / t / 05_thread_clone.t
index 4596221..f2c939f 100644 (file)
@@ -18,19 +18,9 @@ BEGIN {
 
 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';
+    };
   }
 }
 
@@ -49,7 +39,7 @@ BEGIN {
 use threads;
 use threads::shared;
 
-print "1..3\n";
+print "1..4\n";
 
 our $had_error :shared;
 END { $? = $had_error||0 }
@@ -66,6 +56,9 @@ use Devel::GlobalDestruction;
 
 our $cloner = Test::Thread::Clone->new(sub {
     ok( ! in_global_destruction(), "CLONE is not GD" );
+    my $guard = Test::Scope::Guard->new(sub {
+        ok( ! in_global_destruction(), "DESTROY during CLONE is not GD");
+    });
 });
 our $global = Test::Scope::Guard->new(sub {
     ok( in_global_destruction(), "Final cleanup object destruction properly in GD in " . (threads->tid ? 'thread' : 'main program') );