This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move sub attributes before the signature
[perl5.git] / t / op / lex.t
CommitLineData
bc795616 1#!perl
da851177
FC
2
3# Tests too complex for t/base/lex.t
4
f3365a56 5use strict;
bc795616 6use warnings;
f3365a56 7
a817e89d 8BEGIN { chdir 't' if -d 't'; require './test.pl'; }
f3365a56 9
743e3e72 10plan(tests => 36);
f3365a56
NC
11
12{
c6e25b09 13 print <<''; # Yow!
f3365a56
NC
14ok 1
15
16 # previous line intentionally left blank.
17
18 my $yow = "ok 2";
c6e25b09 19 print <<""; # Yow!
f3365a56
NC
20$yow
21
22 # previous line intentionally left blank.
23}
24
25curr_test(3);
bc795616
JV
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
58b85e8b
FC
50{
51 delete local $ENV{PERL_UNICODE};
52 fresh_perl_is(
67a057d6
FC
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{...}'
58b85e8b
FC
58 );
59}
67a057d6
FC
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(
6d70c686
FC
70 'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"};
71 $^H{charnames} = \"foo" } "\N{a}"',
d2192f4f
FC
72 "Not a CODE reference at - line 2.\n"
73 ."Propagated at - line 2, within string\n"
67a057d6
FC
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);
4aaee9b8
FC
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;
e660c409
FC
93
94$_ = "rhubarb";
95is ${no strict; \$_}, "rhubarb", '${no strict; ...}';
96is join("", map{no strict; "rhu$_" } "barb"), 'rhubarb',
97 'map{no strict;...}';
3c47da3c
FC
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: {
bf8a9a15 131 skip "Different output on EBCDIC (presumably)", 3 if $::IS_EBCDIC;
3c47da3c
FC
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 );
eea89386
FC
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 );
bf8a9a15
FC
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 );
3c47da3c 159}
e47d32dc
FC
160
161fresh_perl_is(
162 '/$a[/<<a',
0f9d53bb
FC
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",
e47d32dc
FC
166 { stderr => 1 },
167 '/$a[/<<a with no newline [perl #123712]'
168);
d27f4b91
FC
169fresh_perl_is(
170 '/$a[m||/<<a',
0f9d53bb
FC
171 "Missing right curly or square bracket at - line 1, within pattern\n" .
172 "syntax error at - line 1, at EOF\n" .
d27f4b91
FC
173 "Execution of - aborted due to compilation errors.\n",
174 { stderr => 1 },
175 '/$a[m||/<<a with no newline [perl #123712]'
176);
0f9d53bb
FC
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);
479ae48e
FC
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 },
de72f778 192 '/$0{}/ with no newline [perl #123802]'
479ae48e 193);
66edcf79
FC
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);
9d58dbc4
FC
208
209is eval "qq'@\x{ff13}'", "\@\x{ff13}",
210 '"@<fullwidth digit>" [perl #123963]';
b24768f0
FC
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);
e7127e21
FC
218
219fresh_perl_is(
220 '$_ = q-strict.pm-; 1 ? require : die;'
221 .' print qq-ok\n- if $INC{q-strict.pm-}',
222 "ok\n",
2a91eb11 223 {},
e7127e21
FC
224 'foo ? require : bar [perl #128307]'
225);
89bfd824
FC
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';
37817481
DC
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);
f54cfdac
DC
243
244fresh_perl_like(
245 "#!perl -i u\nprint 'OK'",
246 qr/OK/,
247 {},
248 '[perl #129336] - #!perl -i argument handling'
249);
272d03f8
TC
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",
75219bac
KW
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.",
272d03f8
TC
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),
9a6c9c81 264 qr/Malformed UTF-8 character: \\xff \(too short; 1 byte available, need 13\) at - line 1\./,
272d03f8
TC
265 {},
266 '[perl #128997] - buffer read overflow'
267 );
268 fresh_perl_like(
269 qq(BEGIN{\$^H=0x800000}\n 0m 0\xB5\xB500\xB5\0),
75219bac 270 qr/Malformed UTF-8 character: \\xb5 \(unexpected continuation byte 0xb5, with no preceding start byte\)/,
272d03f8
TC
271 {},
272 '[perl #129000] read before buffer'
273 );
274}
71776ae4
TC
275# probably only failed under ASAN
276fresh_perl_is(
277 "stat\tt\$#0",
278 <<'EOM',
279$# is no longer supported. Its use will be fatal in Perl 5.30 at - line 1.
280Number found where operator expected at - line 1, near "$#0"
281 (Missing operator before 0?)
282Can't call method "t" on an undefined value at - line 1.
283EOM
284 {},
285 "[perl #129273] heap use after free or overflow"
286);
743e3e72
TC
287
288fresh_perl_like('flock _$', qr/Not enough arguments for flock/, {stderr => 1},
289 "[perl #129190] intuit_method() invalidates PL_bufptr");