X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2Fthreads%2Fshared%2Ft%2Fshared_attr.t;h=a901b702b7f13cf55dcb4205d6b35d1b337cb633;hb=7473853ae9011ddcc2c47de96bb5b2cce2df42a2;hp=367424c1f26cbec9e3ae5777b88b50e5ec8421ff;hpb=45cd5be73bf5c2ad46a82c3a4df3760035464110;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/threads/shared/t/shared_attr.t b/ext/threads/shared/t/shared_attr.t index 367424c..a901b70 100644 --- a/ext/threads/shared/t/shared_attr.t +++ b/ext/threads/shared/t/shared_attr.t @@ -1,35 +1,47 @@ +use strict; use warnings; BEGIN { -# chdir 't' if -d 't'; -# push @INC ,'../lib'; - require Config; import Config; - unless ($Config{'useithreads'}) { - print "1..0 # Skip: no useithreads\n"; - exit 0; + if ($ENV{'PERL_CORE'}){ + chdir 't'; + unshift @INC, '../lib'; + } + use Config; + if (! $Config{'useithreads'}) { + print("1..0 # Skip: Perl not compiled with 'useithreads'\n"); + exit(0); } } +use ExtUtils::testlib; sub ok { my ($id, $ok, $name) = @_; + if (! defined($name)) { + $name = ''; + } - $name = '' unless defined $name; # You have to do it this way or VMS will get confused. - print $ok ? "ok $id - $name\n" : "not ok $id - $name\n"; - - printf "# Failed test at line %d\n", (caller)[2] unless $ok; + if ($ok) { + print("ok $id - $name\n"); + } else { + print("not ok $id - $name\n"); + printf("# Failed test at line %d\n", (caller)[2]); + } - return $ok; + return ($ok); } +BEGIN { + $| = 1; + print("1..101\n"); ### Number of tests that will be run ### +}; -use ExtUtils::testlib; -use strict; -BEGIN { print "1..81\n" }; use threads; use threads::shared; -ok(1,1,"loaded"); +ok(1, 1, 'Loaded'); + +### Start of Testing ### my $test_count; share($test_count); @@ -48,8 +60,22 @@ for(1..10) { ok($test_count++, $foo{foo} eq "bar"); threads->create(sub { $foo{bar} = "foo" })->join(); ok($test_count++, $foo{bar} eq "foo"); - + threads->create(sub { $foo{array} = \@foo})->join(); threads->create(sub { push @{$foo{array}}, "baz"})->join(); ok($test_count++, $foo[-1] eq "baz"); } + +my $shared :shared = &share({}); +$$shared{'foo'} = 'bar'; + +for(1..10) { + my $str1 = "$shared"; + my $str2 = "$shared"; + ok($test_count++, $str1 eq $str2, 'stringify'); + $str1 = $$shared{'foo'}; + $str2 = $$shared{'foo'}; + ok($test_count++, $str1 eq $str2, 'contents'); +} + +# EOF