]> git.vpit.fr Git - perl/modules/autovivification.git/blob - t/51-threads-teardown.t
Threads tests may not be able to spawn all the threads
[perl/modules/autovivification.git] / t / 51-threads-teardown.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use autovivification::TestThreads;
8
9 use Test::Leaner tests => 1;
10
11 sub run_perl {
12  my $code = shift;
13
14  my $SystemRoot   = $ENV{SystemRoot};
15  local %ENV;
16  $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
17
18  system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
19 }
20
21 SKIP:
22 {
23  skip 'Fails on 5.8.2 and lower' => 1 if "$]" <= 5.008002;
24
25  my $status = run_perl <<' RUN';
26   my $code = 1 + 2 + 4;
27   use threads;
28   $code -= threads->create(sub {
29    eval q{no autovivification; my $x; my $y = $x->{foo}; $x};
30    return defined($x) ? 0 : 1;
31   })->join;
32   $code -= defined(eval q{my $x; my $y = $x->{foo}; $x}) ? 2 : 0;
33   $code -= defined(eval q{no autovivification; my $x; my $y = $x->{foo}; $x})
34            ? 0 : 4;
35   exit $code;
36  RUN
37  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
38 }