S_utf16_textfilter() needs to avoid splitting UTF-16 surrogate pairs.
[p5sagit/p5-mst-13.2.git] / t / comp / hints.t
1 #!./perl
2
3 # Tests the scoping of $^H and %^H
4
5 @INC = '../lib';
6
7 BEGIN { print "1..23\n"; }
8 BEGIN {
9     print "not " if exists $^H{foo};
10     print "ok 1 - \$^H{foo} doesn't exist initially\n";
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     }
18 }
19 {
20     # simulate a pragma -- don't forget HINT_LOCALIZE_HH
21     BEGIN { $^H |= 0x04020000; $^H{foo} = "a"; }
22     BEGIN {
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";
27     }
28     {
29         BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
30         BEGIN {
31             print "not " if $^H{foo} ne "b";
32             print "ok 5 - \$^H{foo} is now 'b'\n";
33         }
34     }
35     BEGIN {
36         print "not " if $^H{foo} ne "a";
37         print "ok 6 - \$^H{foo} restored to 'a'\n";
38     }
39     # The pragma settings disappear after compilation
40     # (test at CHECK-time and at run-time)
41     CHECK {
42         print "not " if exists $^H{foo};
43         print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
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         }
51     }
52     print "not " if exists $^H{foo};
53     print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
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     }
61     # op_entereval should keep the pragmas it was compiled with
62     eval q*
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";
67     *;
68 }
69 BEGIN {
70     print "not " if exists $^H{foo};
71     print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
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     }
79 }
80
81 {
82     BEGIN{$^H{x}=1};
83     for my $tno (15..16) {
84         eval q(
85             print $^H{x}==1 && !$^H{y} ? "ok $tno\n" : "not ok $tno\n";
86             $^H{y} = 1;
87         );
88         if ($@) {
89             (my $str = $@)=~s/^/# /gm;
90             print "not ok $tno\n$str\n";
91         }
92     }
93 }
94
95 {
96     BEGIN { $^H |= 0x04000000; $^H{foo} = "z"; }
97
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";
101
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";
106
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";
110 }
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;
121 print "ok 23 - double-freeing hints hash\n";
122 print "# got: $result\n" if length $result;
123
124 __END__
125 # Add new tests above require 'test.pl'