]> git.vpit.fr Git - perl/modules/Linux-SysInfo.git/blob - t/30-threads.t
Fix the logic for skipping t/30-threads.t on perls with ithreads but without threads.pm
[perl/modules/Linux-SysInfo.git] / t / 30-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Config qw/%Config/;
7
8 BEGIN {
9  my $has_threads = do {
10   local $@;
11   $Config{useithreads} and eval "use threads; 1";
12  };
13  # Load Test::More after threads
14  require Test::More;
15  Test::More->import;
16  if ($has_threads) {
17   plan(tests => 4 * 10);
18  } else {
19   plan(skip_all => 'This perl wasn\'t built to support threads');
20  }
21 }
22
23 use Linux::SysInfo qw/sysinfo/;
24
25 sub try {
26  my $tid = threads->tid();
27  SKIP: {
28   my $si = sysinfo;
29   skip 'system error (sysinfo returned undef)' => 4 unless defined $si;
30   is ref($si), 'HASH', "sysinfo returns a hash reference in thread $tid";
31
32   for (1 .. 3) {
33    if (defined $si->{uptime}) {
34     like $si->{uptime}, qr/^\d+(?:\.\d+)?$/,
35                                     "key $_ looks like a number in thread $tid";
36    } else {
37     fail "key $_ isn't defined in thread $tid";
38    }
39   }
40  }
41 }
42
43 my @t = map { threads->create(\&try, $_) } 1 .. 10;
44 $_->join for @t;