]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/41-threads-teardown.t
6c4814c0057da6a6987f3c16c2ff34c3f1ca4c8f
[perl/modules/indirect.git] / t / 41-threads-teardown.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use VPIT::TestHelpers;
8 use indirect::TestThreads;
9
10 use Test::Leaner tests => 3;
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, @expected);
18   BEGIN {
19    $code = 2;
20    @expected = qw<X Z>;
21   }
22   sub cb { --$code if $_[0] eq shift(@expected) || q{DUMMY} }
23   use threads;
24   $code = threads->create(sub {
25    eval q{return; no indirect hook => \&cb; new X;};
26    return $code;
27   })->join;
28   eval q{new Y;};
29   eval q{return; no indirect hook => \&cb; new Z;};
30   exit $code;
31  RUN
32  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
33 }
34
35 {
36  my $status = run_perl <<' RUN';
37   use threads;
38   BEGIN { require indirect; }
39   sub X::DESTROY { eval 'no indirect; 1'; exit 1 if $@ }
40   threads->create(sub {
41    my $x = bless { }, 'X';
42    $x->{self} = $x;
43    return;
44   })->join;
45   exit $code;
46  RUN
47  is $status, 0, 'indirect can be loaded in eval STRING during global destruction at the end of a thread';
48 }
49
50 {
51  my $status = run_perl <<' RUN';
52   use threads;
53   use threads::shared;
54   my $code : shared;
55   $code = 0;
56   no indirect cb => sub { lock $code; ++$code };
57   sub X::DESTROY { eval $_[0]->{code} }
58   threads->create(sub {
59    my $x = bless { code => 'new Z' }, 'X';
60    $x->{self} = $x;
61    return;
62   })->join;
63   exit $code;
64  RUN
65  is $status, 0, 'indirect does not check eval STRING during global destruction at the end of a thread';
66 }