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