}
}
-my ($plan, $test, $failed, $no_diag);
+my $TAP_STREAM = *STDOUT;
+my $DIAG_STREAM = *STDERR;
+
+my ($plan, $test, $failed, $no_diag, $done_testing);
sub NO_PLAN () { -1 }
sub SKIP_ALL () { -2 }
BEGIN {
- threads::shared::share($plan), lock $plan if THREADSAFE;
+ if (THREADSAFE) {
+ threads::shared::share($_) for $plan, $test, $failed, $no_diag;
+ }
+
+ lock $plan if THREADSAFE;
$plan = undef;
$test = 0;
$failed = 0;
}
-my $TAP_STREAM = *STDOUT;
-my $DIAG_STREAM = *STDERR;
-
sub carp {
my $level = 1 + ($Test::Builder::Level || 0);
my ($file, $line) = (caller $level)[1, 2];
last SKIP;
}
-my $done_testing;
-
sub done_testing {
my ($count) = @_;
--- /dev/null
+#!perl -T
+
+use strict;
+use warnings;
+
+sub skipall {
+ my ($msg) = @_;
+ require Test::Leaner;
+ Test::Leaner::plan(skip_all => $msg);
+}
+
+use Config qw/%Config/;
+
+BEGIN {
+ my $force = $ENV{PERL_TEST_LEANER_TEST_THREADS} ? 1 : !1;
+ my $t_v = $force ? '0' : '1.67';
+ skipall 'This perl wasn\'t built to support threads'
+ unless $Config{useithreads};
+ skipall 'perl 5.13.4 required to test thread safety'
+ unless $force or $] >= 5.013004;
+ skipall "threads $t_v required to test thread safety"
+ unless eval "use threads $t_v; 1";
+}
+
+use Test::Leaner; # after threads
+
+BEGIN {
+ skipall 'This Test::Leaner isn\'t thread safe' unless Test::Leaner::THREADSAFE;
+ plan tests => 8 * 10;
+ defined and diag "Using threads $_" for $threads::VERSION;
+}
+
+sub tick {
+ sleep 1 if rand() < 0.5;
+}
+
+sub worker {
+ my $tid = threads->tid;
+ diag "spawned thread $tid";
+ tick;
+ for (1 .. 10) {
+ pass "test $_ in thread $tid";
+ tick;
+ }
+}
+
+$_->join for map threads->create(\&worker), 1 .. 8;