]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/30-threads.t
c3db6c15c8c21fb94eab99524ea35ac6e6c0a1f4
[perl/modules/Lexical-Types.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  if (!$Config{useithreads}) {
10   require Test::More;
11   Test::More->import;
12   plan(skip_all => 'This perl wasn\'t built to support threads');
13  }
14 }
15
16 use threads;
17
18 use Test::More tests => 10 * 2 * 2 * (1 + 2);
19
20 defined and diag "Using threads $_" for $threads::VERSION;
21
22 {
23  package Lexical::Types::Test::Tag;
24
25  sub TYPEDSCALAR {
26   my $tid = threads->tid();
27   my ($file, $line) = (caller(0))[1, 2];
28   my $where = "at $file line $line in thread $tid";
29   Test::More::is($_[0], __PACKAGE__, "base type is correct $where");
30   Test::More::is($_[2], 'Tag', "original type is correct $where");
31   $_[1] = $tid;
32   ();
33  }
34 }
35
36 { package Tag; }
37
38 use Lexical::Types as => 'Lexical::Types::Test::';
39
40 sub try {
41  my $tid = threads->tid();
42
43  for (1 .. 2) {
44   my Tag $t;
45   is $t, $tid, "typed lexical correctly initialized at run $_ in thread $tid";
46
47   eval <<'EVALD';
48    use Lexical::Types as => "Lexical::Types::Test::";
49    my Tag $t2;
50    is $t2, $tid, "typed lexical correctly initialized in eval at run $_ in thread $tid";
51 EVALD
52   diag $@ if $@;
53  }
54 }
55
56 my @t = map threads->create(\&try), 1 .. 10;
57 $_->join for @t;