Forbid labels with keyword names
[p5sagit/p5-mst-13.2.git] / t / comp / hints.t
index 1170968..55aeb71 100644 (file)
@@ -2,16 +2,27 @@
 
 # Tests the scoping of $^H and %^H
 
-BEGIN { print "1..14\n"; }
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(. ../lib);
+}
+
+
+BEGIN { print "1..17\n"; }
 BEGIN {
     print "not " if exists $^H{foo};
     print "ok 1 - \$^H{foo} doesn't exist initially\n";
-    print "not " if $^H & 0x00020000;
-    print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
+    if (${^OPEN}) {
+       print "not " unless $^H & 0x00020000;
+       print "ok 2 - \$^H contains HINT_LOCALIZE_HH initially with ${^OPEN}\n";
+    } else {
+       print "not " if $^H & 0x00020000;
+       print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
+    }
 }
 {
     # simulate a pragma -- don't forget HINT_LOCALIZE_HH
-    BEGIN { $^H |= 0x00020000; $^H{foo} = "a"; }
+    BEGIN { $^H |= 0x04020000; $^H{foo} = "a"; }
     BEGIN {
        print "not " if $^H{foo} ne "a";
        print "ok 3 - \$^H{foo} is now 'a'\n";
@@ -34,17 +45,27 @@ BEGIN {
     CHECK {
        print "not " if exists $^H{foo};
        print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
-       print "not " if $^H & 0x00020000;
-       print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
+       if (${^OPEN}) {
+           print "not " unless $^H & 0x00020000;
+           print "ok 10 - \$^H contains HINT_LOCALIZE_HH when compilation complete with ${^OPEN}\n";
+       } else {
+           print "not " if $^H & 0x00020000;
+           print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
+       }
     }
     print "not " if exists $^H{foo};
     print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
-    print "not " if $^H & 0x00020000;
-    print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
+    if (${^OPEN}) {
+       print "not " unless $^H & 0x00020000;
+       print "ok 12 - \$^H contains HINT_LOCALIZE_HH at run-time with ${^OPEN}\n";
+    } else {
+       print "not " if $^H & 0x00020000;
+       print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
+    }
     # op_entereval should keep the pragmas it was compiled with
     eval q*
        print "not " if $^H{foo} ne "a";
-       print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time # TODO\n";
+       print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time\n";
        print "not " unless $^H & 0x00020000;
        print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
     *;
@@ -52,6 +73,36 @@ BEGIN {
 BEGIN {
     print "not " if exists $^H{foo};
     print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
-    print "not " if $^H & 0x00020000;
-    print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
+    if (${^OPEN}) {
+       print "not " unless $^H & 0x00020000;
+       print "ok 8 - \$^H contains HINT_LOCALIZE_HH while finishing compilation with ${^OPEN}\n";
+    } else {
+       print "not " if $^H & 0x00020000;
+       print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
+    }
+}
+
+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) {
+        eval q(
+            print $^H{x}==1 && !$^H{y} ? "ok\n" : "not ok\n";
+            $^H{y} = 1;
+        );
+        if ($@) {
+            (my $str = $@)=~s/^/# /gm;
+            print "not ok\n$str\n";
+        }
+    }
 }