]> git.vpit.fr Git - perl/modules/Thread-Cleanup.git/blobdiff - t/11-detach.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/Thread-Cleanup.git] / t / 11-detach.t
index 3c641666c96a5ca6845380ff3461b5627a87d95c..0631264a63fa331247b7eeb95ae5c494c83a9977 100644 (file)
@@ -3,20 +3,10 @@
 use strict;
 use warnings;
 
-use Config qw/%Config/;
+use lib 't/lib';
+use Thread::Cleanup::TestThreads;
 
-BEGIN {
- if (!$Config{useithreads}) {
-  require Test::More;
-  Test::More->import;
-  plan(skip_all => 'This perl wasn\'t built to support threads');
- }
-}
-
-use threads;
-use threads::shared;
-
-use Test::More tests => 5 * (2 + 2) + 1;
+use Test::More 'no_plan';
 
 use Thread::Cleanup;
 
@@ -62,26 +52,25 @@ sub cb {
  sleep 1;
 }
 
-my @tids;
-
-my @t = map {
+my @threads = map {
  local $x = $_;
- my $thr = threads->create(\&cb, $_);
- push @tids, $thr->tid;
- $thr;
+ spawn(\&cb, $_);
 } 0 .. 4;
 
-diag "Using threads $threads::VERSION";
-diag "Using threads::shared $threads::shared::VERSION";
+my @tids = map $_->tid, @threads;
 
-$_->detach for @t;
+$_->detach for @threads;
 
 sleep 2;
 
 is $x, -1, '$x in the main thread';
 
-is $ran{$_},    1, "thread $_ was run once" for @tids;
+for (@tids) {
+ is $ran{$_},    1,     "thread $_ was run once";
+ is $called{$_}, undef, "thread $_ destructor wasn't called yet";
+}
 
 END {
- is $called{$_}, 1, "thread $_ destructor was called once" for @tids;
+ is $called{$_}, 1, "thread $_ destructor was called once at END time"
+                                                                      for @tids;
 }