This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add support for basic support for AVs, references not supported yet.
[perl5.git] / ext / threads / shared / t / sv_refs.t
CommitLineData
b050c948
AB
1BEGIN {
2# chdir 't' if -d 't';
3# push @INC ,'../lib';
4 require Config; import Config;
5 unless ($Config{'useithreads'}) {
6 print "1..0 # Skip: no useithreads\n";
7 exit 0;
8 }
9}
10
11
12sub ok {
13 my ($id, $ok, $name) = @_;
14
15 # You have to do it this way or VMS will get confused.
16 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
17
18 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
19
20 return $ok;
21}
22
23use Devel::Peek;
24use ExtUtils::testlib;
25use strict;
aaf3876d 26BEGIN { print "1..10\n" };
b050c948
AB
27use threads;
28use threads::shared;
29ok(1,1,"loaded");
30
31my $foo;
32my $bar = "foo";
33share($foo);
34eval {
35$foo = \$bar;
36};
37ok(2,my $temp1 = $@ =~/You cannot assign a non shared reference to a shared scalar/, "Check that the warning message is correct");
38share($bar);
39$foo = \$bar;
40ok(3, $temp1 = $foo =~/SCALAR/, "Check that is a ref");
41ok(4, $$foo eq "foo", "Check that it points to the correct value");
42$bar = "yeah";
43ok(5, $$foo eq "yeah", "Check that assignment works");
44$$foo = "yeah2";
45ok(6, $$foo eq "yeah2", "Check that deref assignment works");
46threads->create(sub {$bar = "yeah3"})->join();
47ok(7, $$foo eq "yeah3", "Check that other thread assignemtn works");
48threads->create(sub {$foo = "artur"})->join();
49ok(8, $foo eq "artur", "Check that uncopupling the ref works");
50my $baz;
51share($baz);
52$baz = "original";
53$bar = \$baz;
54$foo = \$bar;
55ok(9,$$$foo eq 'original', "Check reference chain");
aaf3876d
AB
56my($t1,$t2);
57share($t1);
58share($t2);
59$t2 = "text";
60$t1 = \$t2;
61threads->create(sub { $t1 = "bar" })->join();
62ok(10,$t1 eq 'bar',"Check that assign to a ROK works");