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