]> git.vpit.fr Git - perl/modules/autovivification.git/blob - t/51-threads-teardown.t
Do nothing after that the thread local storage has been freed
[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 VPIT::TestHelpers;
8 use autovivification::TestThreads;
9
10 use Test::Leaner tests => 2;
11
12 SKIP:
13 {
14  skip 'Fails on 5.8.2 and lower' => 1 if "$]" <= 5.008_002;
15
16  my $status = run_perl <<' RUN';
17   my $code = 1 + 2 + 4;
18   use threads;
19   $code -= threads->create(sub {
20    eval q{no autovivification; my $x; my $y = $x->{foo}; $x};
21    return defined($x) ? 0 : 1;
22   })->join;
23   $code -= defined(eval q{my $x; my $y = $x->{foo}; $x}) ? 2 : 0;
24   $code -= defined(eval q{no autovivification; my $x; my $y = $x->{foo}; $x})
25            ? 0 : 4;
26   exit $code;
27  RUN
28  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
29 }
30
31 {
32  my $status = run_perl <<' RUN';
33   use threads;
34   BEGIN { require autovivification; }
35   sub X::DESTROY {
36    eval 'no autovivification; my $x; my $y = $x->{foo}{bar}; use autovivification; my $z = $x->{a}{b}{c};';
37    exit 1 if $@;
38   }
39   threads->create(sub {
40    my $x = bless { }, 'X';
41    $x->{self} = $x;
42    return;
43   })->join;
44   exit $code;
45  RUN
46  is $status, 0, 'autovivification can be loaded in eval STRING during global destruction at the end of a thread';
47 }