The thread warnings aren't quite yet working as planned.
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / shared_attr.t
1 use warnings;
2
3 BEGIN {
4 #    chdir 't' if -d 't';
5 #    push @INC ,'../lib';
6     require Config; import Config;
7     unless ($Config{'useithreads'}) {
8         print "1..0 # Skip: no useithreads\n";
9         exit 0;
10     }
11 }
12
13
14 sub ok {
15     my ($id, $ok, $name) = @_;
16
17     $name = '' unless defined $name;
18     # You have to do it this way or VMS will get confused.
19     print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
20
21     printf "# Failed test at line %d\n", (caller)[2] unless $ok;
22
23     return $ok;
24 }
25
26
27 use ExtUtils::testlib;
28 use strict;
29 BEGIN { print "1..81\n" };
30 use threads;
31 use threads::shared;
32 ok(1,1,"loaded");
33
34 my $test_count;
35 share($test_count);
36 $test_count = 2;
37
38 for(1..10) {
39     my $foo : shared = "foo";
40     ok($test_count++, $foo eq "foo");
41     threads->create(sub { $foo = "bar" })->join();
42     ok($test_count++, $foo eq "bar");
43     my @foo : shared = ("foo","bar");
44     ok($test_count++, $foo[1] eq "bar");
45     threads->create(sub { ok($test_count++, shift(@foo) eq "foo")})->join();
46     ok($test_count++, $foo[0] eq "bar");
47     my %foo : shared = ( foo => "bar" );
48     ok($test_count++, $foo{foo} eq "bar");
49     threads->create(sub { $foo{bar} = "foo" })->join();
50     ok($test_count++, $foo{bar} eq "foo");
51     
52     threads->create(sub { $foo{array} = \@foo})->join();
53     threads->create(sub { push @{$foo{array}}, "baz"})->join();
54     ok($test_count++, $foo[-1] eq "baz");
55 }