]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/31-threads-teardown.t
Fix test failures with Strawberry Perl 5.12
[perl/modules/Lexical-Types.git] / t / 31-threads-teardown.t
1 #!perl
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;
19
20 BEGIN {
21  require Lexical::Types;
22  if (Lexical::Types::LT_THREADSAFE()) {
23   plan tests => 1;
24   defined and diag "Using threads $_" for $threads::VERSION;
25  } else {
26   plan skip_all => 'This Lexical::Types isn\'t thread safe';
27  }
28 }
29
30 sub run_perl {
31  my $code = shift;
32
33  my $SystemRoot   = $ENV{SystemRoot};
34  local %ENV;
35  $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
36
37  system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
38 }
39
40 SKIP:
41 {
42  skip 'Fails on 5.8.2 and lower' => 1 if $] <= 5.008002;
43
44  my $status = run_perl <<' RUN';
45   { package IntX; package IntY; package IntZ; }
46   my ($code, @expected);
47   sub cb {
48    my $e = shift(@expected) || q{DUMMY};
49    --$code if $_[0] eq $e;
50    ()
51   }
52   use threads;
53   $code = threads->create(sub {
54    $code = @expected = qw/IntX/;
55    eval q{use Lexical::Types as => \&cb; my IntX $x;}; die if $@;
56    return $code;
57   })->join;
58   $code += @expected = qw/IntZ/;
59   eval q{my IntY $y;}; die if $@;
60   eval q{use Lexical::Types as => \&cb; my IntZ $z;}; die if $@;
61   $code += 256 if $code < 0;
62   exit $code;
63  RUN
64  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
65 }