Fix bad assumptions in test case.
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / sv_refs.t
1 BEGIN {
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
12 sub 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
23 use Devel::Peek;
24 use ExtUtils::testlib;
25 use strict;
26 BEGIN { print "1..10\n" };
27 use threads;
28 use threads::shared;
29 ok(1,1,"loaded");
30
31 my $foo;
32 my $bar = "foo";
33 share($foo);
34 eval {
35 $foo = \$bar;
36 };
37
38 ok(2,my $temp1 = $@ =~/^Invalid\b.*shared scalar/, "Wrong error message");
39 share($bar);
40 $foo = \$bar;
41 ok(3, $temp1 = $foo =~/SCALAR/, "Check that is a ref");
42 ok(4, $$foo eq "foo", "Check that it points to the correct value");
43 $bar = "yeah";
44 ok(5, $$foo eq "yeah", "Check that assignment works");
45 $$foo = "yeah2";
46 ok(6, $$foo eq "yeah2", "Check that deref assignment works");
47 threads->create(sub {$bar = "yeah3"})->join();
48 ok(7, $$foo eq "yeah3", "Check that other thread assignemtn works");
49 threads->create(sub {$foo = "artur"})->join();
50 ok(8, $foo eq "artur", "Check that uncopupling the ref works");
51 my $baz;
52 share($baz);
53 $baz = "original";
54 $bar = \$baz;
55 $foo = \$bar;
56 ok(9,$$$foo eq 'original', "Check reference chain");
57 my($t1,$t2);
58 share($t1);
59 share($t2);
60 $t2 = "text";
61 $t1 = \$t2;
62 threads->create(sub { $t1 = "bar" })->join();
63 ok(10,$t1 eq 'bar',"Check that assign to a ROK works");