1N/A#!./perl
1N/A
1N/A# Tests the scoping of $^H and %^H
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = qw(. ../lib);
1N/A}
1N/A
1N/A
1N/ABEGIN { print "1..15\n"; }
1N/ABEGIN {
1N/A print "not " if exists $^H{foo};
1N/A print "ok 1 - \$^H{foo} doesn't exist initially\n";
1N/A print "not " if $^H & 0x00020000;
1N/A print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
1N/A}
1N/A{
1N/A # simulate a pragma -- don't forget HINT_LOCALIZE_HH
1N/A BEGIN { $^H |= 0x00020000; $^H{foo} = "a"; }
1N/A BEGIN {
1N/A print "not " if $^H{foo} ne "a";
1N/A print "ok 3 - \$^H{foo} is now 'a'\n";
1N/A print "not " unless $^H & 0x00020000;
1N/A print "ok 4 - \$^H contains HINT_LOCALIZE_HH while compiling\n";
1N/A }
1N/A {
1N/A BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
1N/A BEGIN {
1N/A print "not " if $^H{foo} ne "b";
1N/A print "ok 5 - \$^H{foo} is now 'b'\n";
1N/A }
1N/A }
1N/A BEGIN {
1N/A print "not " if $^H{foo} ne "a";
1N/A print "ok 6 - \$H^{foo} restored to 'a'\n";
1N/A }
1N/A # The pragma settings disappear after compilation
1N/A # (test at CHECK-time and at run-time)
1N/A CHECK {
1N/A print "not " if exists $^H{foo};
1N/A print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
1N/A print "not " if $^H & 0x00020000;
1N/A print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
1N/A }
1N/A print "not " if exists $^H{foo};
1N/A print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
1N/A print "not " if $^H & 0x00020000;
1N/A print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
1N/A # op_entereval should keep the pragmas it was compiled with
1N/A eval q*
1N/A print "not " if $^H{foo} ne "a";
1N/A print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time # TODO\n";
1N/A print "not " unless $^H & 0x00020000;
1N/A print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
1N/A *;
1N/A}
1N/ABEGIN {
1N/A print "not " if exists $^H{foo};
1N/A print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
1N/A print "not " if $^H & 0x00020000;
1N/A print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
1N/A}
1N/A
1N/Arequire 'test.pl';
1N/A
1N/A# bug #27040: hints hash was being double-freed
1N/Amy $result = runperl(
1N/A prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
1N/A stderr => 1
1N/A);
1N/Aprint "not " if length $result;
1N/Aprint "ok 15 - double-freeing hints hash\n";
1N/Aprint "# got: $result\n" if length $result;
1N/A