5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 if (! $Config{'useithreads'}) {
11 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
16 use ExtUtils::testlib;
21 if (! eval 'use threads::shared; 1') {
22 print("1..0 # SKIP threads::shared not available\n");
27 print("1..31\n"); ### Number of tests that will be run ###
44 # You have to do it this way or VMS will get confused.
46 print("ok $id - $name\n");
48 print("not ok $id - $name\n");
49 printf("# Failed test at line %d\n", (caller)[2]);
56 ### Start of Testing ###
61 my $wantarray = wantarray();
64 ok($context eq 'array', 'Array/list context');
66 } elsif (defined($wantarray)) {
67 ok($context eq 'scalar', 'Scalar context');
70 ok($context eq 'void', 'Void context');
75 my ($thr) = threads->create('foo', 'array');
76 my ($res) = $thr->join();
77 ok($res eq 'array', 'Implicit array context');
79 $thr = threads->create('foo', 'scalar');
81 ok($res eq 'scalar', 'Implicit scalar context');
83 threads->create('foo', 'void');
84 ($thr) = threads->list();
86 ok(! defined($res), 'Implicit void context');
88 $thr = threads->create({'context' => 'array'}, 'foo', 'array');
89 ($res) = $thr->join();
90 ok($res eq 'array', 'Explicit array context');
92 ($thr) = threads->create({'scalar' => 'scalar'}, 'foo', 'scalar');
94 ok($res eq 'scalar', 'Explicit scalar context');
96 $thr = threads->create({'void' => 1}, 'foo', 'void');
98 ok(! defined($res), 'Explicit void context');
104 my $wantarray = threads->wantarray();
107 ok($context eq 'list', 'Array/list context');
109 } elsif (defined($wantarray)) {
110 ok($context eq 'scalar', 'Scalar context');
113 ok($context eq 'void', 'Void context');
118 ($thr) = threads->create('bar', 'list');
119 my $ctx = $thr->wantarray();
120 ok($ctx, 'Implicit array context');
121 ($res) = $thr->join();
122 ok($res eq 'list', 'Implicit array context');
124 $thr = threads->create('bar', 'scalar');
125 $ctx = $thr->wantarray();
126 ok(defined($ctx) && !$ctx, 'Implicit scalar context');
128 ok($res eq 'scalar', 'Implicit scalar context');
130 threads->create('bar', 'void');
131 ($thr) = threads->list();
132 $ctx = $thr->wantarray();
133 ok(! defined($ctx), 'Implicit void context');
135 ok(! defined($res), 'Implicit void context');
137 $thr = threads->create({'context' => 'list'}, 'bar', 'list');
138 $ctx = $thr->wantarray();
139 ok($ctx, 'Explicit array context');
140 ($res) = $thr->join();
141 ok($res eq 'list', 'Explicit array context');
143 ($thr) = threads->create({'scalar' => 'scalar'}, 'bar', 'scalar');
144 $ctx = $thr->wantarray();
145 ok(defined($ctx) && !$ctx, 'Explicit scalar context');
147 ok($res eq 'scalar', 'Explicit scalar context');
149 $thr = threads->create({'void' => 1}, 'bar', 'void');
150 $ctx = $thr->wantarray();
151 ok(! defined($ctx), 'Explicit void context');
153 ok(! defined($res), 'Explicit void context');