[TEST PATCH] %^H can now propagate into eval
[p5sagit/p5-mst-13.2.git] / t / comp / hints.t
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..17\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 | HINT_HH_FOR_EVAL
20     BEGIN { $^H |= 0x04020000; $^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         print "not " unless $^H & 0x04000000;
27         print "ok 5 - \$^H contains HINT_HH_FOR_EVAL while compiling\n";
28     }
29     {
30         BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
31         BEGIN {
32             print "not " if $^H{foo} ne "b";
33             print "ok 6 - \$^H{foo} is now 'b'\n";
34         }
35     }
36     BEGIN {
37         print "not " if $^H{foo} ne "a";
38         print "ok 7 - \$H^{foo} restored to 'a'\n";
39     }
40     # The pragma settings disappear after compilation
41     # (test at CHECK-time and at run-time)
42     CHECK {
43         print "not " if exists $^H{foo};
44         print "ok 10 - \$^H{foo} doesn't exist when compilation complete\n";
45         print "not " if $^H & 0x00020000;
46         print "ok 11 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
47     }
48     print "not " if exists $^H{foo};
49     print "ok 12 - \$^H{foo} doesn't exist at runtime\n";
50     print "not " if $^H & 0x00020000;
51     print "ok 13 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
52     print "not " if $^H & 0x04000000;
53     print "ok 14 - \$^H doesn't contain HINT_HH_FOR_EVAL at run-time\n";
54     # op_entereval should keep the pragmas it was compiled with
55     eval q*
56         print "not " if $^H{foo} ne "a";
57         print "ok 15 - \$^H{foo} is 'a' at eval-\"\" time\n";
58         print "not " unless $^H & 0x00020000;
59         print "ok 16 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
60     *;
61 }
62 BEGIN {
63     print "not " if exists $^H{foo};
64     print "ok 8 - \$^H{foo} doesn't exist while finishing compilation\n";
65     print "not " if $^H & 0x00020000;
66     print "ok 9 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
67 }
68
69 require 'test.pl';
70
71 # bug #27040: hints hash was being double-freed
72 my $result = runperl(
73     prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
74     stderr => 1
75 );
76 print "not " if length $result;
77 print "ok 17 - double-freeing hints hash\n";
78 print "# got: $result\n" if length $result;
79