[perl #71204] diagnostics.pm suppresses 'Use of uninitialized value in range (or...
[p5sagit/p5-mst-13.2.git] / t / comp / hints.t
index 55aeb71..f8c6dca 100644 (file)
@@ -2,13 +2,9 @@
 
 # Tests the scoping of $^H and %^H
 
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = qw(. ../lib);
-}
+@INC = '../lib';
 
-
-BEGIN { print "1..17\n"; }
+BEGIN { print "1..23\n"; }
 BEGIN {
     print "not " if exists $^H{foo};
     print "ok 1 - \$^H{foo} doesn't exist initially\n";
@@ -38,7 +34,7 @@ BEGIN {
     }
     BEGIN {
        print "not " if $^H{foo} ne "a";
-       print "ok 6 - \$H^{foo} restored to 'a'\n";
+       print "ok 6 - \$^H{foo} restored to 'a'\n";
     }
     # The pragma settings disappear after compilation
     # (test at CHECK-time and at run-time)
@@ -82,27 +78,48 @@ BEGIN {
     }
 }
 
-require 'test.pl';
-
-# bug #27040: hints hash was being double-freed
-my $result = runperl(
-    prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
-    stderr => 1
-);
-print "not " if length $result;
-print "ok 15 - double-freeing hints hash\n";
-print "# got: $result\n" if length $result;
-
 {
     BEGIN{$^H{x}=1};
-    for(1..2) {
+    for my $tno (15..16) {
         eval q(
-            print $^H{x}==1 && !$^H{y} ? "ok\n" : "not ok\n";
+            print $^H{x}==1 && !$^H{y} ? "ok $tno\n" : "not ok $tno\n";
             $^H{y} = 1;
         );
         if ($@) {
             (my $str = $@)=~s/^/# /gm;
-            print "not ok\n$str\n";
+            print "not ok $tno\n$str\n";
         }
     }
 }
+
+{
+    BEGIN { $^H |= 0x04000000; $^H{foo} = "z"; }
+
+    our($ri0, $rf0); BEGIN { $ri0 = $^H; $rf0 = $^H{foo}; }
+    print +($ri0 & 0x04000000 ? "" : "not "), "ok 17 - \$^H correct before require\n";
+    print +($rf0 eq "z" ? "" : "not "), "ok 18 - \$^H{foo} correct before require\n";
+
+    our($ra1, $ri1, $rf1, $rfe1);
+    BEGIN { require "comp/hints.aux"; }
+    print +(!($ri1 & 0x04000000) ? "" : "not "), "ok 19 - \$^H cleared for require\n";
+    print +(!defined($rf1) && !$rfe1 ? "" : "not "), "ok 20 - \$^H{foo} cleared for require\n";
+
+    our($ri2, $rf2); BEGIN { $ri2 = $^H; $rf2 = $^H{foo}; }
+    print +($ri2 & 0x04000000 ? "" : "not "), "ok 21 - \$^H correct after require\n";
+    print +($rf2 eq "z" ? "" : "not "), "ok 22 - \$^H{foo} correct after require\n";
+}
+
+# Add new tests above this require, in case it fails.
+require './test.pl';
+
+# bug #27040: hints hash was being double-freed
+my $result = runperl(
+    prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
+    stderr => 1
+);
+print "not " if length $result;
+print "ok 23 - double-freeing hints hash\n";
+print "# got: $result\n" if length $result;
+
+__END__
+# Add new tests above require 'test.pl'