1#!perl
2
3# Tests too complex for t/base/lex.t
4
5use strict;
6use warnings;
7
8BEGIN { chdir 't' if -d 't'; require './test.pl'; }
9
10plan(tests => 36);
11
12{
13    print <<'';   # Yow!
14ok 1
15
16    # previous line intentionally left blank.
17
18    my $yow = "ok 2";
19    print <<"";   # Yow!
20$yow
21
22    # previous line intentionally left blank.
23}
24
25curr_test(3);
26
27
28{
29    my %foo = (aap => "monkey");
30    my $foo = '';
31    is("@{[$foo{'aap'}]}", 'monkey', 'interpolation of hash lookup with space between lexical variable and subscript');
32    is("@{[$foo {'aap'}]}", 'monkey', 'interpolation of hash lookup with space between lexical variable and subscript - test for [perl #70091]');
33
34# Original bug report [perl #70091]
35#  #!perl
36#  use warnings;
37#  my %foo;
38#  my $foo = '';
39#  (my $tmp = $foo) =~ s/^/$foo {$0}/e;
40#  __END__
41#
42#  This program causes a segfault with 5.10.0 and 5.10.1.
43#
44#  The space between '$foo' and '{' is essential, which is why piping
45#  it through perl -MO=Deparse "fixes" it.
46#
47
48}
49
50{
51 delete local $ENV{PERL_UNICODE};
52 fresh_perl_is(
53  'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"} } "\N{a}"',
54  'Constant(\N{a}) unknown at - line 1, within string' . "\n"
55 ."Execution of - aborted due to compilation errors.\n",
56   { stderr => 1 },
57  'correct output (and no crash) when charnames cannot load for \N{...}'
58 );
59}
60fresh_perl_is(
61  'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"};
62          $^H{charnames} = "foo" } "\N{a}"',
63  "Undefined subroutine &main::foo called at - line 2.\n"
64 ."Propagated at - line 2, within string\n"
65 ."Execution of - aborted due to compilation errors.\n",
66   { stderr => 1 },
67  'no crash when charnames cannot load and %^H holds string'
68);
69fresh_perl_is(
70  'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"};
71          $^H{charnames} = \"foo" } "\N{a}"',
72  "Not a CODE reference at - line 2.\n"
73 ."Propagated at - line 2, within string\n"
74 ."Execution of - aborted due to compilation errors.\n",
75   { stderr => 1 },
76  'no crash when charnames cannot load and %^H holds string reference'
77);
78
79# not fresh_perl_is, as it seems to hide the error
80is runperl(
81    nolib => 1, # -Ilib may also hide the error
82    progs => [
83      '*{',
84      '         XS::APItest::gv_fetchmeth_type()',
85      '}'
86    ],
87    stderr => 1,
88   ),
89  "Undefined subroutine &XS::APItest::gv_fetchmeth_type called at -e line "
90 ."2.\n",
91  'no buffer corruption with multiline *{...expr...}'
92;
93
94$_ = "rhubarb";
95is ${no strict; \$_}, "rhubarb", '${no strict; ...}';
96is join("", map{no strict; "rhu$_" } "barb"), 'rhubarb',
97  'map{no strict;...}';
98
99# [perl #123753]
100fresh_perl_is(
101  '$eq = "ok\n"; print $' . "\0eq\n",
102  "ok\n",
103   { stderr => 1 },
104  '$ <null> ident'
105);
106fresh_perl_is(
107  '@eq = "ok\n"; print @' . "\0eq\n",
108  "ok\n",
109   { stderr => 1 },
110  '@ <null> ident'
111);
112fresh_perl_is(
113  '%eq = ("o"=>"k\n"); print %' . "\0eq\n",
114  "ok\n",
115   { stderr => 1 },
116  '% <null> ident'
117);
118fresh_perl_is(
119  'sub eq { "ok\n" } print &' . "\0eq\n",
120  "ok\n",
121   { stderr => 1 },
122  '& <null> ident'
123);
124fresh_perl_is(
125  '$eq = "ok\n"; print ${*' . "\0eq{SCALAR}}\n",
126  "ok\n",
127   { stderr => 1 },
128  '* <null> ident'
129);
130SKIP: {
131    skip "Different output on EBCDIC (presumably)", 3 if $::IS_EBCDIC;
132    fresh_perl_is(
133      qq'"ab}"ax;&\0z\x8Ao}\x82x;', <<gibberish,
134Bareword found where operator expected at - line 1, near ""ab}"ax"
135	(Missing operator before ax?)
136syntax error at - line 1, near ""ab}"ax"
137Unrecognized character \\x8A; marked by <-- HERE after ab}"ax;&\0z<-- HERE near column 12 at - line 1.
138gibberish
139       { stderr => 1 },
140      'gibberish containing &\0z - used to crash [perl #123753]'
141    );
142    fresh_perl_is(
143      qq'"ab}"ax;&{+z}\x8Ao}\x82x;', <<gibberish,
144Bareword found where operator expected at - line 1, near ""ab}"ax"
145	(Missing operator before ax?)
146syntax error at - line 1, near ""ab}"ax"
147Unrecognized character \\x8A; marked by <-- HERE after }"ax;&{+z}<-- HERE near column 14 at - line 1.
148gibberish
149       { stderr => 1 },
150      'gibberish containing &{+z} - used to crash [perl #123753]'
151    );
152    fresh_perl_is(
153      "\@{\327\n", <<\gibberisi,
154Unrecognized character \xD7; marked by <-- HERE after @{<-- HERE near column 3 at - line 1.
155gibberisi
156       { stderr => 1 },
157      '@ { \327 \n - used to garble output (or fail asan) [perl #128951]'
158    );
159}
160
161fresh_perl_is(
162  '/$a[/<<a',
163  "Missing right curly or square bracket at - line 1, within pattern\n" .
164  "syntax error at - line 1, at EOF\n" .
165  "Execution of - aborted due to compilation errors.\n",
166   { stderr => 1 },
167  '/$a[/<<a with no newline [perl #123712]'
168);
169fresh_perl_is(
170  '/$a[m||/<<a',
171  "Missing right curly or square bracket at - line 1, within pattern\n" .
172  "syntax error at - line 1, at EOF\n" .
173  "Execution of - aborted due to compilation errors.\n",
174   { stderr => 1 },
175  '/$a[m||/<<a with no newline [perl #123712]'
176);
177
178fresh_perl_is(
179  '"@{"',
180  "Missing right curly or square bracket at - line 1, within string\n" .
181  "syntax error at - line 1, at EOF\n" .
182  "Execution of - aborted due to compilation errors.\n",
183   { stderr => 1 },
184  '"@{" [perl #123712]'
185);
186
187fresh_perl_is(
188  '/$0{}/',
189  'syntax error at - line 1, near "{}"' . "\n" .
190  "Execution of - aborted due to compilation errors.\n",
191   { stderr => 1 },
192  '/$0{}/ with no newline [perl #123802]'
193);
194fresh_perl_is(
195  '"\L\L"',
196  'syntax error at - line 1, near "\L\L"' . "\n" .
197  "Execution of - aborted due to compilation errors.\n",
198   { stderr => 1 },
199  '"\L\L" with no newline [perl #123802]'
200);
201fresh_perl_is(
202  '<\L\L>',
203  'syntax error at - line 1, near "\L\L"' . "\n" .
204  "Execution of - aborted due to compilation errors.\n",
205   { stderr => 1 },
206  '<\L\L> with no newline [perl #123802]'
207);
208
209is eval "qq'@\x{ff13}'", "\@\x{ff13}",
210  '"@<fullwidth digit>" [perl #123963]';
211
212fresh_perl_is(
213  "s;\@{<<a;\n",
214  "Can't find string terminator \"a\" anywhere before EOF at - line 1.\n",
215   { stderr => 1 },
216  's;@{<<a; [perl #123995]'
217);
218
219fresh_perl_is(
220  '$_ = q-strict.pm-; 1 ? require : die;'
221 .' print qq-ok\n- if $INC{q-strict.pm-}',
222  "ok\n",
223  {},
224  'foo ? require : bar [perl #128307]'
225);
226
227like runperl(prog => 'sub ub(){0} ub ub', stderr=>1), qr/Bareword found/,
228 '[perl #126482] Assert failure when mentioning a constant twice in a row';
229
230fresh_perl_is(
231    "do\0"."000000",
232    "",
233    {},
234    '[perl #129069] - no output and valgrind clean'
235);
236
237fresh_perl_is(
238    "00my sub\0",
239    "Missing name in \"my sub\" at - line 1.\n",
240    {},
241    '[perl #129069] - "Missing name" warning and valgrind clean'
242);
243
244fresh_perl_like(
245    "#!perl -i u\nprint 'OK'",
246    qr/OK/,
247    {},
248    '[perl #129336] - #!perl -i argument handling'
249);
250SKIP:
251{
252    ord("A") == 65
253      or skip "These tests won't work on EBCIDIC", 3;
254    fresh_perl_is(
255        "BEGIN{\$^H=hex ~0}\xF3",
256        "Integer overflow in hexadecimal number at - line 1.\n"
257      . "Malformed UTF-8 character: \\xf3 (too short; 1 byte available, need 4) at - line 1.\n"
258      . "Malformed UTF-8 character (fatal) at - line 1.",
259        {},
260        '[perl #128996] - use of PL_op after op is freed'
261    );
262    fresh_perl_like(
263        qq(BEGIN{\$0="";\$^H=-hex join""=>1}""\xFF),
264        qr/Malformed UTF-8 character: \\xff \(too short; 1 byte available, need 13\) at - line 1\./,
265        {},
266        '[perl #128997] - buffer read overflow'
267    );
268    fresh_perl_like(
269        qq(BEGIN{\$^H=0x800000}\n   0m 0\xB5\xB500\xB5\0),
270        qr/Malformed UTF-8 character: \\xb5 \(unexpected continuation byte 0xb5, with no preceding start byte\)/,
271        {},
272        '[perl #129000] read before buffer'
273    );
274}
275# probably only failed under ASAN
276fresh_perl_is(
277    "stat\tt\$#0",
278    <<'EOM',
279$# is no longer supported as of Perl 5.30 at - line 1.
280EOM
281    {},
282    "[perl #129273] heap use after free or overflow"
283);
284
285fresh_perl_like('flock  _$', qr/Not enough arguments for flock/, {stderr => 1},
286                "[perl #129190] intuit_method() invalidates PL_bufptr");
287