]> git.vpit.fr Git - perl/modules/Thread-Cleanup.git/blobdiff - t/20-recurse.t
Skip threads tests unless perl version is 5.13.4 or greater
[perl/modules/Thread-Cleanup.git] / t / 20-recurse.t
index 85724c357e009819f339e9fb6b57ccf98a2c4ccb..4143821286af8a28bc2638d70553a74d0bcf883d 100644 (file)
@@ -3,31 +3,13 @@
 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;
-
-my ($num, $depth);
-BEGIN {
- $num   = 3;
- $depth = 2;
-}
-
-use Test::More tests => (($num ** ($depth + 1) - 1) / ($num - 1) - 1 ) * (2 + 2) + 1;
+use Test::More 'no_plan';
 
-BEGIN {
- defined and diag "Using threads $_"         for $threads::VERSION;
- defined and diag "Using threads::shared $_" for $threads::shared::VERSION;
-}
+my $num   = 3;
+my $depth = 2;
 
 use Thread::Cleanup;
 
@@ -41,16 +23,18 @@ my %called : shared;
 
 my @tids;
 
-sub spawn {
+sub test_threads {
  my ($num, $depth) = @_;
- @tids = ();
- return unless $depth > 0;
- map {
+ if ($depth <= 0) {
+  @tids = ();
+  return;
+ }
+ my @threads = map {
   local $x = $_;
-  my $thr = threads->create(\&cb, $_, $depth);
-  push @tids, $thr->tid;
-  $thr;
+  spawn(\&cb, $_, $depth);
  } 1 .. $num;
+ @tids = map $_->tid, @threads;
+ return @threads;
 }
 
 sub check {
@@ -78,7 +62,7 @@ sub cb {
  is $x, $y, "\$x in thread $tid";
  local $x = -$tid;
 
- $_->join for spawn $num, $depth - 1;
+ $_->join for test_threads $num, $depth - 1;
 
  check;
 }
@@ -99,7 +83,7 @@ Thread::Cleanup::register {
  local $x = $tid;
 };
 
-$_->join for spawn $num, $depth;
+$_->join for test_threads $num, $depth;
 
 check;