This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[ANNOUNCE] Math::BigInt v1.69
[perl5.git] / ext / threads / shared / t / sv_refs.t
CommitLineData
13c1b207
DM
1use warnings;
2
b050c948
AB
3BEGIN {
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
14sub ok {
15 my ($id, $ok, $name) = @_;
16
13c1b207 17 $name = '' unless defined $name;
b050c948
AB
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
26use Devel::Peek;
27use ExtUtils::testlib;
28use strict;
aaf3876d 29BEGIN { print "1..10\n" };
b050c948
AB
30use threads;
31use threads::shared;
32ok(1,1,"loaded");
33
34my $foo;
35my $bar = "foo";
36share($foo);
37eval {
38$foo = \$bar;
39};
a446a88f
NIS
40
41ok(2,my $temp1 = $@ =~/^Invalid\b.*shared scalar/, "Wrong error message");
b050c948
AB
42share($bar);
43$foo = \$bar;
44ok(3, $temp1 = $foo =~/SCALAR/, "Check that is a ref");
45ok(4, $$foo eq "foo", "Check that it points to the correct value");
46$bar = "yeah";
47ok(5, $$foo eq "yeah", "Check that assignment works");
48$$foo = "yeah2";
49ok(6, $$foo eq "yeah2", "Check that deref assignment works");
50threads->create(sub {$bar = "yeah3"})->join();
51ok(7, $$foo eq "yeah3", "Check that other thread assignemtn works");
52threads->create(sub {$foo = "artur"})->join();
53ok(8, $foo eq "artur", "Check that uncopupling the ref works");
54my $baz;
55share($baz);
56$baz = "original";
57$bar = \$baz;
58$foo = \$bar;
59ok(9,$$$foo eq 'original', "Check reference chain");
aaf3876d
AB
60my($t1,$t2);
61share($t1);
62share($t2);
63$t2 = "text";
64$t1 = \$t2;
65threads->create(sub { $t1 = "bar" })->join();
66ok(10,$t1 eq 'bar',"Check that assign to a ROK works");