Eviscerate README.macos to match the state of the world
[p5sagit/p5-mst-13.2.git] / dist / threads-shared / t / no_share.t
CommitLineData
7473853a 1use strict;
13c1b207 2use warnings;
3
dab065ea 4BEGIN {
7473853a 5 use Config;
6 if (! $Config{'useithreads'}) {
6c791b15 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
7473853a 8 exit(0);
dab065ea 9 }
dab065ea 10}
11
7473853a 12use ExtUtils::testlib;
dab065ea 13
14sub ok {
15 my ($id, $ok, $name) = @_;
16
17 # You have to do it this way or VMS will get confused.
7473853a 18 if ($ok) {
19 print("ok $id - $name\n");
20 } else {
21 print("not ok $id - $name\n");
22 printf("# Failed test at line %d\n", (caller)[2]);
23 }
dab065ea 24
7473853a 25 return ($ok);
dab065ea 26}
27
7473853a 28BEGIN {
29 $| = 1;
30 print("1..6\n"); ### Number of tests that will be run ###
31};
32
dab065ea 33our $warnmsg;
7473853a 34BEGIN {
35 $SIG{__WARN__} = sub { $warnmsg = shift; };
36}
37
dab065ea 38use threads::shared;
39use threads;
7473853a 40ok(1, 1, 'Loaded');
41
42### Start of Testing ###
43
44ok(2, ($warnmsg =~ /Warning, threads::shared has already been loaded/)?1:0,
9c4972d9 45 "threads has warned us");
7473853a 46
dab065ea 47my $test = "bar";
48share($test);
7473853a 49ok(3, $test eq "bar", "Test disabled share not interfering");
50
51threads->create(sub {
52 ok(4, $test eq "bar", "Test disabled share after thread");
dab065ea 53 $test = "baz";
7473853a 54 })->join();
9c4972d9 55# Value should either remain unchanged or be value set by other thread
7473853a 56ok(5, $test eq "bar" || $test eq 'baz', "Test that value is an expected one");
9c4972d9 57
7473853a 58ok(6, ! is_shared($test), "Check for sharing");
dab065ea 59
6c791b15 60exit(0);
61
7473853a 62# EOF