threads::shared 1.22
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / av_simple.t
index 7cb67e3..67d9a32 100644 (file)
@@ -1,33 +1,45 @@
+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) = @_;
 
     # 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..44\n");   ### Number of tests that will be run ###
+};
 
-
-use ExtUtils::testlib;
-use strict;
-BEGIN { print "1..43\n" };
 use threads;
 use threads::shared;
-ok(1,1,"loaded");
+ok(1, 1, 'Loaded');
+
+### Start of Testing ###
+
 my @foo;
 share(@foo);
 ok(2,1,"shared \@foo");
@@ -35,10 +47,10 @@ $foo[0] = "hi";
 ok(3, $foo[0] eq 'hi', "Check assignment works");
 $foo[0] = "bar";
 ok(4, $foo[0] eq 'bar', "Check overwriting works");
-ok(5, $foo[1] == undef, "Check undef value");
+ok(5, !defined $foo[1], "Check undef value");
 $foo[2] = "test";
 ok(6, $foo[2] eq "test", "Check extending the array works");
-ok(7, $foo[1] == undef, "Check undef value again");
+ok(7, !defined $foo[1], "Check undef value again");
 ok(8, scalar(@foo) == 3, "Check the length of the array");
 ok(9,$#foo == 2, "Check last element of array");
 threads->create(sub { $foo[0] = "thread1" })->join;
@@ -74,9 +86,9 @@ ok(26, $var == 2, "Check shift after thread");
     my @foo2;
     share @foo2;
     my $empty = shift @foo2;
-    ok(27, $empty == undef , "Check shift on empty array");
+    ok(27, !defined $empty, "Check shift on empty array");
     $empty = pop @foo2;
-    ok(28, $empty == undef , "Check pop on empty array");
+    ok(28, !defined $empty, "Check pop on empty array");
 }
 my $i = 0;
 foreach my $var (@foo) {
@@ -99,12 +111,12 @@ $foo[20] = "sky";
 ok(36, delete($foo[20]) eq "sky", "Check delete works");
 
 threads->create(sub { delete($foo[0])})->join();
-ok(37, delete($foo[0]) == undef, "Check that delete works from a thread");
+ok(37, !defined delete($foo[0]), "Check that delete works from a thread");
 
 @foo = (1,2,3,4,5);
 
 {
-    my ($t1,$t2) = @foo[2,3]; 
+    my ($t1,$t2) = @foo[2,3];
     ok(38, $t1 == 3, "Check slice");
     ok(39, $t2 == 4, "Check slice again");
     my @t1 = @foo[1...4];
@@ -115,7 +127,13 @@ ok(37, delete($foo[0]) == undef, "Check that delete works from a thread");
 }
 {
     eval {
-       my @t1 = splice(@foo,0,2,"hop", "hej");
+        my @t1 = splice(@foo,0,2,"hop", "hej");
     };
-    ok(43, my $temp1 = $@ =~/Splice is not implmented for shared arrays/, "Check that the warning message is correct for non splice");
+    ok(43, my $temp1 = $@ =~/Splice not implemented for shared arrays/, "Check that the warning message is correct for non splice");
 }
+
+ok(44, is_shared(@foo), "Check for sharing");
+
+exit(0);
+
+# EOF