Skip tests if Devel::Peek not built
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / sv_refs.t
CommitLineData
13c1b207 1use warnings;
2
b050c948 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 }
4946def6 11 if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) {
12 print "1..0 # Skip: Devel::Peek was not built\n";
13 exit 0;
14 }
b050c948 15}
16
17
18sub ok {
19 my ($id, $ok, $name) = @_;
20
13c1b207 21 $name = '' unless defined $name;
b050c948 22 # You have to do it this way or VMS will get confused.
23 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
24
25 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
26
27 return $ok;
28}
29
30use Devel::Peek;
31use ExtUtils::testlib;
32use strict;
aaf3876d 33BEGIN { print "1..10\n" };
b050c948 34use threads;
35use threads::shared;
36ok(1,1,"loaded");
37
38my $foo;
39my $bar = "foo";
40share($foo);
41eval {
42$foo = \$bar;
43};
a446a88f 44
45ok(2,my $temp1 = $@ =~/^Invalid\b.*shared scalar/, "Wrong error message");
b050c948 46share($bar);
47$foo = \$bar;
48ok(3, $temp1 = $foo =~/SCALAR/, "Check that is a ref");
49ok(4, $$foo eq "foo", "Check that it points to the correct value");
50$bar = "yeah";
51ok(5, $$foo eq "yeah", "Check that assignment works");
52$$foo = "yeah2";
53ok(6, $$foo eq "yeah2", "Check that deref assignment works");
54threads->create(sub {$bar = "yeah3"})->join();
55ok(7, $$foo eq "yeah3", "Check that other thread assignemtn works");
56threads->create(sub {$foo = "artur"})->join();
57ok(8, $foo eq "artur", "Check that uncopupling the ref works");
58my $baz;
59share($baz);
60$baz = "original";
61$bar = \$baz;
62$foo = \$bar;
63ok(9,$$$foo eq 'original', "Check reference chain");
aaf3876d 64my($t1,$t2);
65share($t1);
66share($t2);
67$t2 = "text";
68$t1 = \$t2;
69threads->create(sub { $t1 = "bar" })->join();
70ok(10,$t1 eq 'bar',"Check that assign to a ROK works");