]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/42-threads-global.t
Port threads tests to the new VPIT::TestHelpers interface
[perl/modules/indirect.git] / t / 42-threads-global.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 BEGIN { require indirect; }
7
8 use lib 't/lib';
9 use VPIT::TestHelpers (
10  threads => [ 'indirect' => indirect::I_THREADSAFE ],
11 );
12
13 use Test::Leaner;
14
15 sub expect {
16  my ($pkg) = @_;
17  qr/^Indirect call of method "new" on object "$pkg" at \(eval \d+\) line \d+/;
18 }
19
20 my $error;
21
22 no indirect 'global', 'hook' => sub { $error = indirect::msg(@_) };
23
24 sub try {
25  my $tid = threads->tid();
26
27  for my $run (1 .. 2) {
28   my $desc  = "global indirect hook (thread $tid, run $run)";
29   my $class = "Mango$tid";
30   my @warns;
31   {
32    local $SIG{__WARN__} = sub { push @warns, @_ };
33    eval "return; my \$x = new $class 1, 2;"
34   }
35   is        $@,      '',             "$desc: did not croak";
36   is_deeply \@warns, [ ],            "$desc: no warnings";
37   like      $error,  expect($class), "$desc: correct error";
38  }
39 }
40
41 my @threads = map spawn(\&try), 1 .. 10;
42
43 $_->join for @threads;
44
45 done_testing(scalar(@threads) * 3 * 2);