]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/80-threads.t
Fall back to Test::More when PERL_TEST_LEANER_USES_TEST_MORE is set
[perl/modules/Test-Leaner.git] / t / 80-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 BEGIN { delete $ENV{PERL_TEST_LEANER_USES_TEST_MORE} }
7
8 sub skipall {
9  my ($msg) = @_;
10  require Test::Leaner;
11  Test::Leaner::plan(skip_all => $msg);
12 }
13
14 use Config qw/%Config/;
15
16 BEGIN {
17  my $force = $ENV{PERL_TEST_LEANER_TEST_THREADS} ? 1 : !1;
18  my $t_v   = $force ? '0' : '1.67';
19  skipall 'This perl wasn\'t built to support threads'
20                                                     unless $Config{useithreads};
21  skipall 'perl 5.13.4 required to test thread safety'
22                                                 unless $force or $] >= 5.013004;
23  skipall "threads $t_v required to test thread safety"
24                                               unless eval "use threads $t_v; 1";
25 }
26
27 use Test::Leaner; # after threads
28
29 BEGIN {
30  skipall 'This Test::Leaner isn\'t thread safe' unless Test::Leaner::THREADSAFE;
31  plan tests => 8 * 10;
32  defined and diag "Using threads $_" for $threads::VERSION;
33 }
34
35 sub tick {
36  sleep 1 if rand() < 0.5;
37 }
38
39 sub worker {
40  my $tid = threads->tid;
41  diag "spawned thread $tid";
42  tick;
43  for (1 .. 10) {
44   cmp_ok 1, '==', '1.0', "test $_ in thread $tid";
45   tick;
46  }
47 }
48
49 $_->join for map threads->create(\&worker), 1 .. 8;