| 1 | #!./perl
|
|---|
| 2 |
|
|---|
| 3 | # Tests the scoping of $^H and %^H
|
|---|
| 4 |
|
|---|
| 5 | BEGIN {
|
|---|
| 6 | chdir 't' if -d 't';
|
|---|
| 7 | @INC = qw(. ../lib);
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | BEGIN { print "1..15\n"; }
|
|---|
| 12 | BEGIN {
|
|---|
| 13 | print "not " if exists $^H{foo};
|
|---|
| 14 | print "ok 1 - \$^H{foo} doesn't exist initially\n";
|
|---|
| 15 | print "not " if $^H & 0x00020000;
|
|---|
| 16 | print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
|
|---|
| 17 | }
|
|---|
| 18 | {
|
|---|
| 19 | # simulate a pragma -- don't forget HINT_LOCALIZE_HH
|
|---|
| 20 | BEGIN { $^H |= 0x00020000; $^H{foo} = "a"; }
|
|---|
| 21 | BEGIN {
|
|---|
| 22 | print "not " if $^H{foo} ne "a";
|
|---|
| 23 | print "ok 3 - \$^H{foo} is now 'a'\n";
|
|---|
| 24 | print "not " unless $^H & 0x00020000;
|
|---|
| 25 | print "ok 4 - \$^H contains HINT_LOCALIZE_HH while compiling\n";
|
|---|
| 26 | }
|
|---|
| 27 | {
|
|---|
| 28 | BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
|
|---|
| 29 | BEGIN {
|
|---|
| 30 | print "not " if $^H{foo} ne "b";
|
|---|
| 31 | print "ok 5 - \$^H{foo} is now 'b'\n";
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 | BEGIN {
|
|---|
| 35 | print "not " if $^H{foo} ne "a";
|
|---|
| 36 | print "ok 6 - \$H^{foo} restored to 'a'\n";
|
|---|
| 37 | }
|
|---|
| 38 | # The pragma settings disappear after compilation
|
|---|
| 39 | # (test at CHECK-time and at run-time)
|
|---|
| 40 | CHECK {
|
|---|
| 41 | print "not " if exists $^H{foo};
|
|---|
| 42 | print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
|
|---|
| 43 | print "not " if $^H & 0x00020000;
|
|---|
| 44 | print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
|
|---|
| 45 | }
|
|---|
| 46 | print "not " if exists $^H{foo};
|
|---|
| 47 | print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
|
|---|
| 48 | print "not " if $^H & 0x00020000;
|
|---|
| 49 | print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
|
|---|
| 50 | # op_entereval should keep the pragmas it was compiled with
|
|---|
| 51 | eval q*
|
|---|
| 52 | print "not " if $^H{foo} ne "a";
|
|---|
| 53 | print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time # TODO\n";
|
|---|
| 54 | print "not " unless $^H & 0x00020000;
|
|---|
| 55 | print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
|
|---|
| 56 | *;
|
|---|
| 57 | }
|
|---|
| 58 | BEGIN {
|
|---|
| 59 | print "not " if exists $^H{foo};
|
|---|
| 60 | print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
|
|---|
| 61 | print "not " if $^H & 0x00020000;
|
|---|
| 62 | print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | require 'test.pl';
|
|---|
| 66 |
|
|---|
| 67 | # bug #27040: hints hash was being double-freed
|
|---|
| 68 | my $result = runperl(
|
|---|
| 69 | prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
|
|---|
| 70 | stderr => 1
|
|---|
| 71 | );
|
|---|
| 72 | print "not " if length $result;
|
|---|
| 73 | print "ok 15 - double-freeing hints hash\n";
|
|---|
| 74 | print "# got: $result\n" if length $result;
|
|---|
| 75 |
|
|---|