Commit | Line | Data |
---|---|---|
0f1612a7 | 1 | use strict; |
2 | use warnings; | |
4e00007d | 3 | |
4 | BEGIN { | |
0f1612a7 | 5 | use Config; |
fc04eb16 | 6 | if (! $Config{'useithreads'}) { |
561ee912 | 7 | print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); |
fc04eb16 | 8 | exit(0); |
4e00007d | 9 | } |
10 | } | |
11 | ||
12 | use ExtUtils::testlib; | |
0f1612a7 | 13 | |
4e00007d | 14 | use threads; |
4e00007d | 15 | |
fc04eb16 | 16 | BEGIN { |
e301958b | 17 | if (! eval 'use threads::shared; 1') { |
561ee912 | 18 | print("1..0 # SKIP threads::shared not available\n"); |
58a3a76c | 19 | exit(0); |
20 | } | |
21 | ||
fc04eb16 | 22 | $| = 1; |
23 | print("1..6\n"); ### Number of tests that will be run ### | |
24 | }; | |
25 | ||
4dcb9e53 | 26 | my $TEST; |
27 | BEGIN { | |
28 | share($TEST); | |
29 | $TEST = 1; | |
30 | } | |
fc04eb16 | 31 | |
32 | ok(1, 'Loaded'); | |
4e00007d | 33 | |
34 | sub ok { | |
35 | my ($ok, $name) = @_; | |
36 | ||
fc04eb16 | 37 | lock($TEST); |
38 | my $id = $TEST++; | |
f2cba68d | 39 | |
4e00007d | 40 | # You have to do it this way or VMS will get confused. |
fc04eb16 | 41 | if ($ok) { |
42 | print("ok $id - $name\n"); | |
43 | } else { | |
44 | print("not ok $id - $name\n"); | |
45 | printf("# Failed test at line %d\n", (caller)[2]); | |
46 | } | |
4e00007d | 47 | |
fc04eb16 | 48 | return ($ok); |
4e00007d | 49 | } |
fc04eb16 | 50 | |
51 | ||
52 | ### Start of Testing ### | |
53 | ||
54 | # Test that END blocks are run in the thread that created them, | |
55 | # and not in any child threads. | |
56 | ||
57 | END { | |
58 | ok(1, 'Main END block') | |
59 | } | |
60 | ||
61 | threads->create(sub { eval "END { ok(1, '1st thread END block') }"})->join(); | |
62 | threads->create(sub { eval "END { ok(1, '2nd thread END block') }"})->join(); | |
4e00007d | 63 | |
64 | sub thread { | |
fc04eb16 | 65 | eval "END { ok(1, '4th thread END block') }"; |
66 | threads->create(sub { eval "END { ok(1, '5th thread END block') }"})->join(); | |
4e00007d | 67 | } |
fc04eb16 | 68 | threads->create(\&thread)->join(); |
69 | ||
561ee912 | 70 | exit(0); |
71 | ||
fc04eb16 | 72 | # EOF |