3 # Tests the scoping of $^H and %^H
7 BEGIN { print "1..23\n"; }
9 print "not " if exists $^H{foo};
10 print "ok 1 - \$^H{foo} doesn't exist initially\n";
12 print "not " unless $^H & 0x00020000;
13 print "ok 2 - \$^H contains HINT_LOCALIZE_HH initially with ${^OPEN}\n";
15 print "not " if $^H & 0x00020000;
16 print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
20 # simulate a pragma -- don't forget HINT_LOCALIZE_HH
21 BEGIN { $^H |= 0x04020000; $^H{foo} = "a"; }
23 print "not " if $^H{foo} ne "a";
24 print "ok 3 - \$^H{foo} is now 'a'\n";
25 print "not " unless $^H & 0x00020000;
26 print "ok 4 - \$^H contains HINT_LOCALIZE_HH while compiling\n";
29 BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
31 print "not " if $^H{foo} ne "b";
32 print "ok 5 - \$^H{foo} is now 'b'\n";
36 print "not " if $^H{foo} ne "a";
37 print "ok 6 - \$^H{foo} restored to 'a'\n";
39 # The pragma settings disappear after compilation
40 # (test at CHECK-time and at run-time)
42 print "not " if exists $^H{foo};
43 print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
45 print "not " unless $^H & 0x00020000;
46 print "ok 10 - \$^H contains HINT_LOCALIZE_HH when compilation complete with ${^OPEN}\n";
48 print "not " if $^H & 0x00020000;
49 print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
52 print "not " if exists $^H{foo};
53 print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
55 print "not " unless $^H & 0x00020000;
56 print "ok 12 - \$^H contains HINT_LOCALIZE_HH at run-time with ${^OPEN}\n";
58 print "not " if $^H & 0x00020000;
59 print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
61 # op_entereval should keep the pragmas it was compiled with
63 print "not " if $^H{foo} ne "a";
64 print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time\n";
65 print "not " unless $^H & 0x00020000;
66 print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
70 print "not " if exists $^H{foo};
71 print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
73 print "not " unless $^H & 0x00020000;
74 print "ok 8 - \$^H contains HINT_LOCALIZE_HH while finishing compilation with ${^OPEN}\n";
76 print "not " if $^H & 0x00020000;
77 print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
83 for my $tno (15..16) {
85 print $^H{x}==1 && !$^H{y} ? "ok $tno\n" : "not ok $tno\n";
89 (my $str = $@)=~s/^/# /gm;
90 print "not ok $tno\n$str\n";
96 BEGIN { $^H |= 0x04000000; $^H{foo} = "z"; }
98 our($ri0, $rf0); BEGIN { $ri0 = $^H; $rf0 = $^H{foo}; }
99 print +($ri0 & 0x04000000 ? "" : "not "), "ok 17 - \$^H correct before require\n";
100 print +($rf0 eq "z" ? "" : "not "), "ok 18 - \$^H{foo} correct before require\n";
102 our($ra1, $ri1, $rf1, $rfe1);
103 BEGIN { require "comp/hints.aux"; }
104 print +(!($ri1 & 0x04000000) ? "" : "not "), "ok 19 - \$^H cleared for require\n";
105 print +(!defined($rf1) && !$rfe1 ? "" : "not "), "ok 20 - \$^H{foo} cleared for require\n";
107 our($ri2, $rf2); BEGIN { $ri2 = $^H; $rf2 = $^H{foo}; }
108 print +($ri2 & 0x04000000 ? "" : "not "), "ok 21 - \$^H correct after require\n";
109 print +($rf2 eq "z" ? "" : "not "), "ok 22 - \$^H{foo} correct after require\n";
112 # Add new tests above this require, in case it fails.
115 # bug #27040: hints hash was being double-freed
116 my $result = runperl(
117 prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
120 print "not " if length $result;
121 print "ok 23 - double-freeing hints hash\n";
122 print "# got: $result\n" if length $result;
125 # Add new tests above require 'test.pl'