6 if (! $Config{'useithreads'}) {
7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
12 use ExtUtils::testlib;
15 my ($id, $ok, $name) = @_;
17 # You have to do it this way or VMS will get confused.
19 print("ok $id - $name\n");
21 print("not ok $id - $name\n");
22 printf("# Failed test at line %d\n", (caller)[2]);
30 print("1..44\n"); ### Number of tests that will be run ###
37 ### Start of Testing ###
41 ok(2,1,"shared \@foo");
43 ok(3, $foo[0] eq 'hi', "Check assignment works");
45 ok(4, $foo[0] eq 'bar', "Check overwriting works");
46 ok(5, !defined $foo[1], "Check undef value");
48 ok(6, $foo[2] eq "test", "Check extending the array works");
49 ok(7, !defined $foo[1], "Check undef value again");
50 ok(8, scalar(@foo) == 3, "Check the length of the array");
51 ok(9,$#foo == 2, "Check last element of array");
52 threads->create(sub { $foo[0] = "thread1" })->join;
53 ok(10, $foo[0] eq "thread1", "Check that a value can be changed in another thread");
54 push(@foo, "another value");
55 ok(11, $foo[3] eq "another value", "Check that push works");
57 ok(12, $foo[-1] == 3, "More push");
58 ok(13, $foo[-2] == 2, "More push");
59 ok(14, $foo[4] == 1, "More push");
60 threads->create(sub { push @foo, "thread2" })->join();
61 ok(15, $foo[7] eq "thread2", "Check push in another thread");
62 unshift(@foo, "start");
63 ok(16, $foo[0] eq "start", "Check unshift");
65 ok(17, $foo[0] == 1, "Check multiple unshift");
66 ok(18, $foo[1] == 2, "Check multiple unshift");
67 ok(19, $foo[2] == 3, "Check multiple unshift");
68 threads->create(sub { unshift @foo, "thread3" })->join();
69 ok(20, $foo[0] eq "thread3", "Check unshift from another thread");
71 ok(21, $var eq "thread2", "Check pop");
72 threads->create(sub { my $foo = pop @foo; ok(22, $foo == 3, "Check pop works in a thread")})->join();
74 ok(23, $var == 2, "Check pop after thread");
76 ok(24, $var eq "thread3", "Check shift");
77 threads->create(sub { my $foo = shift @foo; ok(25, $foo == 1, "Check shift works in a thread");
80 ok(26, $var == 2, "Check shift after thread");
84 my $empty = shift @foo2;
85 ok(27, !defined $empty, "Check shift on empty array");
87 ok(28, !defined $empty, "Check pop on empty array");
90 foreach my $var (@foo) {
93 ok(29, scalar @foo == $i, "Check foreach");
95 ok(30, $ref->[0] == 3, "Check reference access");
96 threads->create(sub { $ref->[0] = "thread4"})->join();
97 ok(31, $ref->[0] eq "thread4", "Check that it works after another thread");
99 threads->create(sub { @foo = () })->join();
100 ok(32, @foo == 0, "Check that array is empty");
101 ok(33, exists($foo[0]) == 0, "Check that zero index doesn't index");
103 ok(34, exists($foo[0]) == 1, "Check that zero index exists now");
104 ok(35, $foo[0] eq "sky", "And check that it also contains the right value");
107 ok(36, delete($foo[20]) eq "sky", "Check delete works");
109 threads->create(sub { delete($foo[0])})->join();
110 ok(37, !defined delete($foo[0]), "Check that delete works from a thread");
115 my ($t1,$t2) = @foo[2,3];
116 ok(38, $t1 == 3, "Check slice");
117 ok(39, $t2 == 4, "Check slice again");
118 my @t1 = @foo[1...4];
119 ok(40, $t1[0] == 2, "Check slice list");
120 ok(41, $t1[2] == 4, "Check slice list 2");
121 threads->create(sub { @foo[0,1] = ("hej","hop") })->join();
122 ok(42,$foo[0] eq "hej", "Check slice assign");
126 my @t1 = splice(@foo,0,2,"hop", "hej");
128 ok(43, my $temp1 = $@ =~/Splice not implemented for shared arrays/, "Check that the warning message is correct for non splice");
131 ok(44, is_shared(@foo), "Check for sharing");