Upgrade to threads-shared-1.03
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / hv_simple.t
index fe1ee21..9ea9b9e 100644 (file)
@@ -1,41 +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) = @_;
 
-    $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;
-
-    return $ok;
-}
+    if ($ok) {
+        print("ok $id - $name\n");
+    } else {
+        print("not ok $id - $name\n");
+        printf("# Failed test at line %d\n", (caller)[2]);
+    }
 
-sub skip {
-    my ($id, $ok, $name) = @_;
-    print "ok $id # skip _thrcnt - $name \n";
+    return ($ok);
 }
 
+BEGIN {
+    $| = 1;
+    print("1..16\n");   ### Number of tests that will be run ###
+};
 
-
-use ExtUtils::testlib;
-use strict;
-BEGIN { print "1..21\n" };
 use threads;
 use threads::shared;
-ok(1,1,"loaded");
+ok(1, 1, 'Loaded');
+
+### Start of Testing ###
+
 my %hash;
 share(%hash);
 $hash{"foo"} = "bar";
@@ -63,21 +67,14 @@ ok(10, $seen{1} == 1, "Keys..");
 ok(11, $seen{2} == 1, "Keys..");
 ok(12, $seen{3} == 1, "Keys..");
 ok(13, $seen{"foo"} == 1, "Keys..");
+
+# bugid #24407: the stringification of the numeric 1 got allocated to the
+# wrong thread memory pool, which crashes on Windows.
+ok(14, exists $hash{1}, "Check numeric key");
+
 threads->create(sub { %hash = () })->join();
-ok(14, keys %hash == 0, "Check clear");
-skip(15, threads::shared::_thrcnt(%hash) == 1, "thrcnt");
-threads->create(sub { skip(16, threads::shared::_thrcnt(%hash) == 2, "thrcnt is up")})->join();
-skip(17, threads::shared::_thrcnt(%hash) == 1, "thrcnt is down");
-{
-       my $test;
-       my $test2;
-       share($test);
-       $test = \%hash;
-       $test2 = \%hash;
-       skip(18, threads::shared::_thrcnt(%hash) == 2, "thrcnt is up on shared reference");
-       $test = "bar";
-       skip(19 , threads::shared::_thrcnt(%hash) == 1, "thrcnt is down when shared reference is dropped");
-       $test = $test2;
-       skip(20, threads::shared::_thrcnt(%hash) == 2, "thrcnt is up on shared reference");
-}
-skip(21 , threads::shared::_thrcnt(%hash) == 1, "thrcnt is down when shared reference is killed");
+ok(15, keys %hash == 0, "Check clear");
+
+ok(16, is_shared(%hash), "Check for sharing");
+
+# EOF