Commit | Line | Data |
dbc6b789 |
1 | #!./perl |
045ac317 |
2 | |
dbc6b789 |
3 | # Tests the scoping of $^H and %^H |
4 | |
bc8f2ddd |
5 | @INC = '../lib'; |
0f94e4a9 |
6 | |
a026e652 |
7 | BEGIN { print "1..23\n"; } |
045ac317 |
8 | BEGIN { |
9 | print "not " if exists $^H{foo}; |
10 | print "ok 1 - \$^H{foo} doesn't exist initially\n"; |
09337566 |
11 | if (${^OPEN}) { |
12 | print "not " unless $^H & 0x00020000; |
13 | print "ok 2 - \$^H contains HINT_LOCALIZE_HH initially with ${^OPEN}\n"; |
14 | } else { |
15 | print "not " if $^H & 0x00020000; |
16 | print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n"; |
17 | } |
045ac317 |
18 | } |
19 | { |
7168684c |
20 | # simulate a pragma -- don't forget HINT_LOCALIZE_HH |
af796537 |
21 | BEGIN { $^H |= 0x04020000; $^H{foo} = "a"; } |
045ac317 |
22 | BEGIN { |
23 | print "not " if $^H{foo} ne "a"; |
dbc6b789 |
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"; |
045ac317 |
27 | } |
28 | { |
29 | BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; } |
30 | BEGIN { |
31 | print "not " if $^H{foo} ne "b"; |
7168684c |
32 | print "ok 5 - \$^H{foo} is now 'b'\n"; |
045ac317 |
33 | } |
34 | } |
35 | BEGIN { |
36 | print "not " if $^H{foo} ne "a"; |
f747ebd6 |
37 | print "ok 6 - \$^H{foo} restored to 'a'\n"; |
045ac317 |
38 | } |
dbc6b789 |
39 | # The pragma settings disappear after compilation |
40 | # (test at CHECK-time and at run-time) |
045ac317 |
41 | CHECK { |
42 | print "not " if exists $^H{foo}; |
7168684c |
43 | print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n"; |
09337566 |
44 | if (${^OPEN}) { |
45 | print "not " unless $^H & 0x00020000; |
46 | print "ok 10 - \$^H contains HINT_LOCALIZE_HH when compilation complete with ${^OPEN}\n"; |
47 | } else { |
48 | print "not " if $^H & 0x00020000; |
49 | print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n"; |
50 | } |
045ac317 |
51 | } |
52 | print "not " if exists $^H{foo}; |
7168684c |
53 | print "ok 11 - \$^H{foo} doesn't exist at runtime\n"; |
09337566 |
54 | if (${^OPEN}) { |
55 | print "not " unless $^H & 0x00020000; |
56 | print "ok 12 - \$^H contains HINT_LOCALIZE_HH at run-time with ${^OPEN}\n"; |
57 | } else { |
58 | print "not " if $^H & 0x00020000; |
59 | print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n"; |
60 | } |
dbc6b789 |
61 | # op_entereval should keep the pragmas it was compiled with |
62 | eval q* |
63 | print "not " if $^H{foo} ne "a"; |
7168684c |
64 | print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time\n"; |
dbc6b789 |
65 | print "not " unless $^H & 0x00020000; |
7168684c |
66 | print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n"; |
dbc6b789 |
67 | *; |
045ac317 |
68 | } |
69 | BEGIN { |
70 | print "not " if exists $^H{foo}; |
7168684c |
71 | print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n"; |
09337566 |
72 | if (${^OPEN}) { |
73 | print "not " unless $^H & 0x00020000; |
74 | print "ok 8 - \$^H contains HINT_LOCALIZE_HH while finishing compilation with ${^OPEN}\n"; |
75 | } else { |
76 | print "not " if $^H & 0x00020000; |
77 | print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n"; |
78 | } |
045ac317 |
79 | } |
dfa41748 |
80 | |
0282be92 |
81 | { |
82 | BEGIN{$^H{x}=1}; |
bc8f2ddd |
83 | for my $tno (15..16) { |
0282be92 |
84 | eval q( |
f747ebd6 |
85 | print $^H{x}==1 && !$^H{y} ? "ok $tno\n" : "not ok $tno\n"; |
0282be92 |
86 | $^H{y} = 1; |
87 | ); |
88 | if ($@) { |
89 | (my $str = $@)=~s/^/# /gm; |
f747ebd6 |
90 | print "not ok $tno\n$str\n"; |
0282be92 |
91 | } |
92 | } |
93 | } |
f747ebd6 |
94 | |
95 | { |
f747ebd6 |
96 | BEGIN { $^H |= 0x04000000; $^H{foo} = "z"; } |
97 | |
98 | our($ri0, $rf0); BEGIN { $ri0 = $^H; $rf0 = $^H{foo}; } |
a026e652 |
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"; |
f747ebd6 |
101 | |
102 | our($ra1, $ri1, $rf1, $rfe1); |
103 | BEGIN { require "comp/hints.aux"; } |
a026e652 |
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"; |
f747ebd6 |
106 | |
107 | our($ri2, $rf2); BEGIN { $ri2 = $^H; $rf2 = $^H{foo}; } |
a026e652 |
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"; |
f747ebd6 |
110 | } |
bc8f2ddd |
111 | |
112 | # Add new tests above this require, in case it fails. |
113 | require './test.pl'; |
114 | |
115 | # bug #27040: hints hash was being double-freed |
116 | my $result = runperl( |
117 | prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}', |
118 | stderr => 1 |
119 | ); |
120 | print "not " if length $result; |
a026e652 |
121 | print "ok 23 - double-freeing hints hash\n"; |
bc8f2ddd |
122 | print "# got: $result\n" if length $result; |
123 | |
124 | __END__ |
125 | # Add new tests above require 'test.pl' |