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