Re: 'use threads::shared' noisy with -w
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / no_share.t
1 use warnings;
2
3 BEGIN {
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     $SIG{__WARN__} = sub { $warnmsg = shift; };
12 }
13
14
15 sub ok {
16     my ($id, $ok, $name) = @_;
17
18     $name = '' unless defined $name;
19     # You have to do it this way or VMS will get confused.
20     print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
21
22     printf "# Failed test at line %d\n", (caller)[2] unless $ok;
23
24     return $ok;
25 }
26
27 our $warnmsg;
28 use ExtUtils::testlib;
29 use strict;
30 BEGIN { print "1..5\n" };
31 use threads::shared;
32 use threads;
33 ok(1,1,"loaded");
34 ok(2,$warnmsg =~ /Warning, threads::shared has already been loaded/,
35     "threads has warned us");
36 my $test = "bar";
37 share($test);
38 ok(3,$test eq "bar","Test disabled share not interfering");
39 threads->create(
40                sub {
41                    ok(4,$test eq "bar","Test disabled share after thread");
42                    $test = "baz";
43                    })->join();
44 # Value should either remain unchanged or be value set by other thread
45 ok(5,$test eq "bar" || $test eq 'baz',"Test that value is an expected one");
46
47