Commit | Line | Data |
---|---|---|
87a42246 MS |
1 | #!./perl |
2 | ||
3 | BEGIN { | |
62a6bb71 | 4 | unshift @INC, 't'; |
9cd8f857 NC |
5 | require Config; |
6 | if (($Config::Config{'extensions'} !~ /\bB\b/) ){ | |
7 | print "1..0 # Skip -- Perl configured without B module\n"; | |
8 | exit 0; | |
9 | } | |
87a42246 MS |
10 | } |
11 | ||
87a42246 MS |
12 | use warnings; |
13 | use strict; | |
e9c69003 NC |
14 | BEGIN { |
15 | # BEGIN block is acutally a subroutine :-) | |
16 | return unless $] > 5.009; | |
17 | require feature; | |
18 | feature->import(':5.10'); | |
19 | } | |
507a68aa | 20 | use Test::More; |
1bb3cfc5 | 21 | use Config (); |
87a42246 MS |
22 | |
23 | use B::Deparse; | |
09d856fb | 24 | my $deparse = B::Deparse->new(); |
507a68aa | 25 | isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object'); |
87a42246 MS |
26 | |
27 | # Tell B::Deparse about our ambient pragmas | |
0ced6c29 RGS |
28 | { my ($hint_bits, $warning_bits, $hinthash); |
29 | BEGIN { ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H); } | |
87a42246 MS |
30 | $deparse->ambient_pragmas ( |
31 | hint_bits => $hint_bits, | |
32 | warning_bits => $warning_bits, | |
0ced6c29 RGS |
33 | '$[' => 0 + $[, |
34 | '%^H' => $hinthash, | |
87a42246 MS |
35 | ); |
36 | } | |
37 | ||
ad46c0be RH |
38 | $/ = "\n####\n"; |
39 | while (<DATA>) { | |
40 | chomp; | |
e9c69003 NC |
41 | # This code is pinched from the t/lib/common.pl for TODO. |
42 | # It's not clear how to avoid duplication | |
b871937f NC |
43 | # Now tweaked a bit to do skip or todo |
44 | my %reason; | |
45 | foreach my $what (qw(skip todo)) { | |
46 | s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1; | |
47 | # If the SKIP reason starts ? then it's taken as a code snippet to | |
48 | # evaluate. This provides the flexibility to have conditional SKIPs | |
49 | if ($reason{$what} && $reason{$what} =~ s/^\?//) { | |
50 | my $temp = eval $reason{$what}; | |
51 | if ($@) { | |
52 | die "# In \U$what\E code reason:\n# $reason{$what}\n$@"; | |
53 | } | |
54 | $reason{$what} = $temp; | |
e9c69003 | 55 | } |
e9c69003 NC |
56 | } |
57 | ||
4a4b8592 | 58 | s/^\s*#\s*(.*)$//mg; |
507a68aa NC |
59 | my $desc = $1; |
60 | die "Missing name in test $_" unless defined $desc; | |
e9c69003 | 61 | |
b871937f | 62 | if ($reason{skip}) { |
e9c69003 | 63 | # Like this to avoid needing a label SKIP: |
b871937f | 64 | Test::More->builder->skip($reason{skip}); |
e9c69003 NC |
65 | next; |
66 | } | |
67 | ||
ad46c0be RH |
68 | my ($input, $expected); |
69 | if (/(.*)\n>>>>\n(.*)/s) { | |
70 | ($input, $expected) = ($1, $2); | |
71 | } | |
72 | else { | |
73 | ($input, $expected) = ($_, $_); | |
74 | } | |
87a42246 | 75 | |
ad46c0be | 76 | my $coderef = eval "sub {$input}"; |
87a42246 | 77 | |
ad46c0be | 78 | if ($@) { |
507a68aa | 79 | is($@, "", "compilation of $desc"); |
ad46c0be RH |
80 | } |
81 | else { | |
82 | my $deparsed = $deparse->coderef2text( $coderef ); | |
31c6271a RD |
83 | my $regex = $expected; |
84 | $regex =~ s/(\S+)/\Q$1/g; | |
85 | $regex =~ s/\s+/\\s+/g; | |
86 | $regex = '^\{\s*' . $regex . '\s*\}$'; | |
b871937f | 87 | |
4a4b8592 | 88 | local $::TODO = $reason{todo}; |
507a68aa | 89 | like($deparsed, qr/$regex/, $desc); |
87a42246 | 90 | } |
87a42246 MS |
91 | } |
92 | ||
87a42246 | 93 | use constant 'c', 'stuff'; |
507a68aa NC |
94 | is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff', |
95 | 'the subroutine generated by use constant deparses'); | |
87a42246 | 96 | |
09d856fb | 97 | my $a = 0; |
507a68aa NC |
98 | is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}", |
99 | 'anon sub capturing an external lexical'); | |
87a42246 | 100 | |
d989cdac SM |
101 | use constant cr => ['hello']; |
102 | my $string = "sub " . $deparse->coderef2text(\&cr); | |
0707d6cc | 103 | my $val = (eval $string)->() or diag $string; |
507a68aa NC |
104 | is(ref($val), 'ARRAY', 'constant array references deparse'); |
105 | is($val->[0], 'hello', 'and return the correct value'); | |
87a42246 | 106 | |
87a42246 | 107 | my $path = join " ", map { qq["-I$_"] } @INC; |
87a42246 | 108 | |
7cde0a5f | 109 | $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`; |
e69a2255 | 110 | $a =~ s/-e syntax OK\n//g; |
d2bc402e | 111 | $a =~ s/.*possible typo.*\n//; # Remove warning line |
87a42246 MS |
112 | $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037 |
113 | $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc' | |
114 | $b = <<'EOF'; | |
d2bc402e RGS |
115 | BEGIN { $^I = ".bak"; } |
116 | BEGIN { $^W = 1; } | |
117 | BEGIN { $/ = "\n"; $\ = "\n"; } | |
87a42246 MS |
118 | LINE: while (defined($_ = <ARGV>)) { |
119 | chomp $_; | |
f86ea535 | 120 | our(@F) = split(' ', $_, 0); |
87a42246 MS |
121 | '???'; |
122 | } | |
87a42246 | 123 | EOF |
507a68aa NC |
124 | is($a, $b, |
125 | 'command line flags deparse as BEGIN blocks setting control variables'); | |
87a42246 | 126 | |
5b4ee549 NC |
127 | $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`; |
128 | $a =~ s/-e syntax OK\n//g; | |
129 | is($a, "use constant ('PI', 4);\n", | |
130 | "Proxy Constant Subroutines must not show up as (incorrect) prototypes"); | |
131 | ||
579a54dc | 132 | #Re: perlbug #35857, patch #24505 |
b3980c39 YO |
133 | #handle warnings::register-ed packages properly. |
134 | package B::Deparse::Wrapper; | |
135 | use strict; | |
136 | use warnings; | |
137 | use warnings::register; | |
138 | sub getcode { | |
579a54dc | 139 | my $deparser = B::Deparse->new(); |
b3980c39 YO |
140 | return $deparser->coderef2text(shift); |
141 | } | |
142 | ||
2990415a FR |
143 | package Moo; |
144 | use overload '0+' => sub { 42 }; | |
145 | ||
b3980c39 YO |
146 | package main; |
147 | use strict; | |
148 | use warnings; | |
71c4dbc3 | 149 | use constant GLIPP => 'glipp'; |
2990415a FR |
150 | use constant PI => 4; |
151 | use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo'); | |
3779476a | 152 | use Fcntl qw/O_TRUNC O_APPEND O_EXCL/; |
aaf9c2b2 | 153 | BEGIN { delete $::Fcntl::{O_APPEND}; } |
2990415a | 154 | use POSIX qw/O_CREAT/; |
b3980c39 | 155 | sub test { |
579a54dc RGS |
156 | my $val = shift; |
157 | my $res = B::Deparse::Wrapper::getcode($val); | |
507a68aa NC |
158 | like($res, qr/use warnings/, |
159 | '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly'); | |
b3980c39 YO |
160 | } |
161 | my ($q,$p); | |
162 | my $x=sub { ++$q,++$p }; | |
163 | test($x); | |
164 | eval <<EOFCODE and test($x); | |
165 | package bar; | |
166 | use strict; | |
167 | use warnings; | |
168 | use warnings::register; | |
169 | package main; | |
170 | 1 | |
171 | EOFCODE | |
172 | ||
640d5d41 FC |
173 | # [perl #33752] |
174 | { | |
175 | my $code = <<"EOCODE"; | |
176 | { | |
177 | our \$\x{1e1f}\x{14d}\x{14d}; | |
178 | } | |
179 | EOCODE | |
180 | my $deparsed | |
181 | = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" ); | |
182 | s/$ \n//x for $deparsed, $code; | |
183 | is $deparsed, $code, 'our $funny_Unicode_chars'; | |
184 | } | |
185 | ||
507a68aa NC |
186 | done_testing(); |
187 | ||
ad46c0be | 188 | __DATA__ |
507a68aa | 189 | # A constant |
ad46c0be RH |
190 | 1; |
191 | #### | |
507a68aa | 192 | # Constants in a block |
ad46c0be RH |
193 | { |
194 | no warnings; | |
195 | '???'; | |
196 | 2; | |
197 | } | |
198 | #### | |
507a68aa | 199 | # Lexical and simple arithmetic |
ad46c0be RH |
200 | my $test; |
201 | ++$test and $test /= 2; | |
202 | >>>> | |
203 | my $test; | |
204 | $test /= 2 if ++$test; | |
205 | #### | |
507a68aa | 206 | # list x |
ad46c0be RH |
207 | -((1, 2) x 2); |
208 | #### | |
507a68aa | 209 | # lvalue sub |
ad46c0be RH |
210 | { |
211 | my $test = sub : lvalue { | |
212 | my $x; | |
213 | } | |
214 | ; | |
215 | } | |
216 | #### | |
507a68aa | 217 | # method |
ad46c0be RH |
218 | { |
219 | my $test = sub : method { | |
220 | my $x; | |
221 | } | |
222 | ; | |
223 | } | |
224 | #### | |
507a68aa | 225 | # block with continue |
87a42246 | 226 | { |
ad46c0be | 227 | 234; |
f99a63a2 | 228 | } |
ad46c0be RH |
229 | continue { |
230 | 123; | |
87a42246 | 231 | } |
ce4e655d | 232 | #### |
507a68aa | 233 | # lexical and package scalars |
ce4e655d RH |
234 | my $x; |
235 | print $main::x; | |
236 | #### | |
507a68aa | 237 | # lexical and package arrays |
ce4e655d RH |
238 | my @x; |
239 | print $main::x[1]; | |
14a55f98 | 240 | #### |
507a68aa | 241 | # lexical and package hashes |
14a55f98 RH |
242 | my %x; |
243 | $x{warn()}; | |
ad8caead | 244 | #### |
507a68aa | 245 | # <> |
ad8caead RGS |
246 | my $foo; |
247 | $_ .= <ARGV> . <$foo>; | |
cef22867 | 248 | #### |
507a68aa | 249 | # \x{} |
cef22867 | 250 | my $foo = "Ab\x{100}\200\x{200}\377Cd\000Ef\x{1000}\cA\x{2000}\cZ"; |
4ae52e81 | 251 | #### |
507a68aa | 252 | # s///e |
4ae52e81 | 253 | s/x/'y';/e; |
241416b8 | 254 | #### |
507a68aa | 255 | # block |
241416b8 DM |
256 | { my $x; } |
257 | #### | |
507a68aa | 258 | # while 1 |
241416b8 DM |
259 | while (1) { my $k; } |
260 | #### | |
507a68aa | 261 | # trailing for |
241416b8 DM |
262 | my ($x,@a); |
263 | $x=1 for @a; | |
264 | >>>> | |
265 | my($x, @a); | |
0bb5f065 | 266 | $x = 1 foreach (@a); |
241416b8 | 267 | #### |
507a68aa | 268 | # 2 arguments in a 3 argument for |
241416b8 DM |
269 | for (my $i = 0; $i < 2;) { |
270 | my $z = 1; | |
271 | } | |
272 | #### | |
507a68aa | 273 | # 3 argument for |
241416b8 DM |
274 | for (my $i = 0; $i < 2; ++$i) { |
275 | my $z = 1; | |
276 | } | |
277 | #### | |
507a68aa | 278 | # 3 argument for again |
241416b8 DM |
279 | for (my $i = 0; $i < 2; ++$i) { |
280 | my $z = 1; | |
281 | } | |
282 | #### | |
507a68aa | 283 | # while/continue |
241416b8 DM |
284 | my $i; |
285 | while ($i) { my $z = 1; } continue { $i = 99; } | |
286 | #### | |
507a68aa | 287 | # foreach with my |
09d856fb | 288 | foreach my $i (1, 2) { |
241416b8 DM |
289 | my $z = 1; |
290 | } | |
291 | #### | |
507a68aa | 292 | # foreach |
241416b8 DM |
293 | my $i; |
294 | foreach $i (1, 2) { | |
295 | my $z = 1; | |
296 | } | |
297 | #### | |
507a68aa | 298 | # foreach, 2 mys |
241416b8 DM |
299 | my $i; |
300 | foreach my $i (1, 2) { | |
301 | my $z = 1; | |
302 | } | |
303 | #### | |
507a68aa | 304 | # foreach |
241416b8 DM |
305 | foreach my $i (1, 2) { |
306 | my $z = 1; | |
307 | } | |
308 | #### | |
507a68aa | 309 | # foreach with our |
241416b8 DM |
310 | foreach our $i (1, 2) { |
311 | my $z = 1; | |
312 | } | |
313 | #### | |
507a68aa | 314 | # foreach with my and our |
241416b8 DM |
315 | my $i; |
316 | foreach our $i (1, 2) { | |
317 | my $z = 1; | |
318 | } | |
3ac6e0f9 | 319 | #### |
507a68aa | 320 | # reverse sort |
3ac6e0f9 RGS |
321 | my @x; |
322 | print reverse sort(@x); | |
323 | #### | |
507a68aa | 324 | # sort with cmp |
3ac6e0f9 RGS |
325 | my @x; |
326 | print((sort {$b cmp $a} @x)); | |
327 | #### | |
507a68aa | 328 | # reverse sort with block |
3ac6e0f9 RGS |
329 | my @x; |
330 | print((reverse sort {$b <=> $a} @x)); | |
36d57d93 | 331 | #### |
507a68aa | 332 | # foreach reverse |
36d57d93 RGS |
333 | our @a; |
334 | print $_ foreach (reverse @a); | |
aae53c41 | 335 | #### |
507a68aa | 336 | # foreach reverse (not inplace) |
aae53c41 RGS |
337 | our @a; |
338 | print $_ foreach (reverse 1, 2..5); | |
f86ea535 | 339 | #### |
507a68aa | 340 | # bug #38684 |
f86ea535 SM |
341 | our @ary; |
342 | @ary = split(' ', 'foo', 0); | |
31c6271a | 343 | #### |
507a68aa | 344 | # bug #40055 |
31c6271a RD |
345 | do { () }; |
346 | #### | |
507a68aa | 347 | # bug #40055 |
31c6271a | 348 | do { my $x = 1; $x }; |
d9002312 | 349 | #### |
507a68aa | 350 | # <20061012113037.GJ25805@c4.convolution.nl> |
d9002312 SM |
351 | my $f = sub { |
352 | +{[]}; | |
353 | } ; | |
8b2d6640 | 354 | #### |
507a68aa | 355 | # bug #43010 |
8b2d6640 FC |
356 | '!@$%'->(); |
357 | #### | |
507a68aa | 358 | # bug #43010 |
8b2d6640 FC |
359 | ::(); |
360 | #### | |
507a68aa | 361 | # bug #43010 |
8b2d6640 FC |
362 | '::::'->(); |
363 | #### | |
507a68aa | 364 | # bug #43010 |
8b2d6640 | 365 | &::::; |
09d856fb | 366 | #### |
507a68aa | 367 | # variables as method names |
09d856fb CK |
368 | my $bar; |
369 | 'Foo'->$bar('orz'); | |
370 | #### | |
507a68aa | 371 | # constants as method names |
09d856fb CK |
372 | 'Foo'->bar('orz'); |
373 | #### | |
507a68aa | 374 | # constants as method names without () |
09d856fb | 375 | 'Foo'->bar; |
0ced6c29 | 376 | #### |
e9c69003 | 377 | # SKIP ?$] < 5.010 && "say not implemented on this Perl version" |
507a68aa | 378 | # say |
7ddd1a01 NC |
379 | say 'foo'; |
380 | #### | |
e9c69003 | 381 | # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version" |
507a68aa | 382 | # state vars |
0ced6c29 RGS |
383 | state $x = 42; |
384 | #### | |
e9c69003 | 385 | # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version" |
507a68aa | 386 | # state var assignment |
7ddd1a01 NC |
387 | { |
388 | my $y = (state $x = 42); | |
389 | } | |
390 | #### | |
e9c69003 | 391 | # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version" |
507a68aa | 392 | # state vars in anoymous subroutines |
7ddd1a01 NC |
393 | $a = sub { |
394 | state $x; | |
395 | return $x++; | |
396 | } | |
397 | ; | |
644741fd NC |
398 | #### |
399 | # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version' | |
507a68aa | 400 | # each @array; |
644741fd NC |
401 | each @ARGV; |
402 | each @$a; | |
403 | #### | |
404 | # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version' | |
507a68aa | 405 | # keys @array; values @array |
644741fd NC |
406 | keys @$a if keys @ARGV; |
407 | values @ARGV if values @$a; | |
35925e80 | 408 | #### |
507a68aa | 409 | # Anonymous arrays and hashes, and references to them |
35925e80 RGS |
410 | my $a = {}; |
411 | my $b = \{}; | |
412 | my $c = []; | |
413 | my $d = \[]; | |
9210de83 FR |
414 | #### |
415 | # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version" | |
507a68aa | 416 | # implicit smartmatch in given/when |
9210de83 FR |
417 | given ('foo') { |
418 | when ('bar') { continue; } | |
419 | when ($_ ~~ 'quux') { continue; } | |
420 | default { 0; } | |
421 | } | |
7ecdd211 | 422 | #### |
507a68aa | 423 | # conditions in elsifs (regression in change #33710 which fixed bug #37302) |
7ecdd211 PJ |
424 | if ($a) { x(); } |
425 | elsif ($b) { x(); } | |
426 | elsif ($a and $b) { x(); } | |
427 | elsif ($a or $b) { x(); } | |
428 | else { x(); } | |
03b22f1b | 429 | #### |
507a68aa | 430 | # interpolation in regexps |
03b22f1b RGS |
431 | my($y, $t); |
432 | /x${y}z$t/; | |
227375e1 | 433 | #### |
4a4b8592 | 434 | # TODO new undocumented cpan-bug #33708 |
507a68aa | 435 | # cpan-bug #33708 |
227375e1 RU |
436 | %{$_ || {}} |
437 | #### | |
4a4b8592 | 438 | # TODO hash constants not yet fixed |
507a68aa | 439 | # cpan-bug #33708 |
227375e1 RU |
440 | use constant H => { "#" => 1 }; H->{"#"} |
441 | #### | |
4a4b8592 | 442 | # TODO optimized away 0 not yet fixed |
507a68aa | 443 | # cpan-bug #33708 |
227375e1 | 444 | foreach my $i (@_) { 0 } |
edbe35ea | 445 | #### |
507a68aa | 446 | # tests with not, not optimized |
07f3cdf5 | 447 | my $c; |
edbe35ea VP |
448 | x() unless $a; |
449 | x() if not $a and $b; | |
450 | x() if $a and not $b; | |
451 | x() unless not $a and $b; | |
452 | x() unless $a and not $b; | |
453 | x() if not $a or $b; | |
454 | x() if $a or not $b; | |
455 | x() unless not $a or $b; | |
456 | x() unless $a or not $b; | |
07f3cdf5 VP |
457 | x() if $a and not $b and $c; |
458 | x() if not $a and $b and not $c; | |
459 | x() unless $a and not $b and $c; | |
460 | x() unless not $a and $b and not $c; | |
461 | x() if $a or not $b or $c; | |
462 | x() if not $a or $b or not $c; | |
463 | x() unless $a or not $b or $c; | |
464 | x() unless not $a or $b or not $c; | |
edbe35ea | 465 | #### |
507a68aa | 466 | # tests with not, optimized |
07f3cdf5 | 467 | my $c; |
edbe35ea VP |
468 | x() if not $a; |
469 | x() unless not $a; | |
470 | x() if not $a and not $b; | |
471 | x() unless not $a and not $b; | |
472 | x() if not $a or not $b; | |
473 | x() unless not $a or not $b; | |
07f3cdf5 VP |
474 | x() if not $a and not $b and $c; |
475 | x() unless not $a and not $b and $c; | |
476 | x() if not $a or not $b or $c; | |
477 | x() unless not $a or not $b or $c; | |
478 | x() if not $a and not $b and not $c; | |
479 | x() unless not $a and not $b and not $c; | |
480 | x() if not $a or not $b or not $c; | |
481 | x() unless not $a or not $b or not $c; | |
482 | x() unless not $a or not $b or not $c; | |
edbe35ea | 483 | >>>> |
07f3cdf5 | 484 | my $c; |
edbe35ea VP |
485 | x() unless $a; |
486 | x() if $a; | |
487 | x() unless $a or $b; | |
488 | x() if $a or $b; | |
489 | x() unless $a and $b; | |
07f3cdf5 VP |
490 | x() if $a and $b; |
491 | x() if not $a || $b and $c; | |
492 | x() unless not $a || $b and $c; | |
493 | x() if not $a && $b or $c; | |
494 | x() unless not $a && $b or $c; | |
495 | x() unless $a or $b or $c; | |
496 | x() if $a or $b or $c; | |
497 | x() unless $a and $b and $c; | |
498 | x() if $a and $b and $c; | |
499 | x() unless not $a && $b && $c; | |
71c4dbc3 | 500 | #### |
507a68aa | 501 | # tests that should be constant folded |
71c4dbc3 VP |
502 | x() if 1; |
503 | x() if GLIPP; | |
504 | x() if !GLIPP; | |
505 | x() if GLIPP && GLIPP; | |
506 | x() if !GLIPP || GLIPP; | |
507 | x() if do { GLIPP }; | |
508 | x() if do { no warnings 'void'; 5; GLIPP }; | |
509 | x() if do { !GLIPP }; | |
510 | if (GLIPP) { x() } else { z() } | |
511 | if (!GLIPP) { x() } else { z() } | |
512 | if (GLIPP) { x() } elsif (GLIPP) { z() } | |
513 | if (!GLIPP) { x() } elsif (GLIPP) { z() } | |
514 | if (GLIPP) { x() } elsif (!GLIPP) { z() } | |
515 | if (!GLIPP) { x() } elsif (!GLIPP) { z() } | |
516 | if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() } | |
517 | if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() } | |
518 | if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() } | |
519 | >>>> | |
520 | x(); | |
521 | x(); | |
522 | '???'; | |
523 | x(); | |
524 | x(); | |
525 | x(); | |
526 | x(); | |
527 | do { | |
528 | '???' | |
529 | }; | |
530 | do { | |
531 | x() | |
532 | }; | |
533 | do { | |
534 | z() | |
535 | }; | |
536 | do { | |
537 | x() | |
538 | }; | |
539 | do { | |
540 | z() | |
541 | }; | |
542 | do { | |
543 | x() | |
544 | }; | |
545 | '???'; | |
546 | do { | |
547 | t() | |
548 | }; | |
549 | '???'; | |
550 | !1; | |
551 | #### | |
719c50dc RGS |
552 | # TODO constant deparsing has been backed out for 5.12 |
553 | # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads" | |
507a68aa | 554 | # tests that shouldn't be constant folded |
ac0f1413 NC |
555 | # It might be fundamentally impossible to make this work on ithreads, in which |
556 | # case the TODO should become a SKIP | |
71c4dbc3 VP |
557 | x() if $a; |
558 | if ($a == 1) { x() } elsif ($b == 2) { z() } | |
559 | if (do { foo(); GLIPP }) { x() } | |
560 | if (do { $a++; GLIPP }) { x() } | |
561 | >>>> | |
562 | x() if $a; | |
563 | if ($a == 1) { x(); } elsif ($b == 2) { z(); } | |
2990415a FR |
564 | if (do { foo(); GLIPP }) { x(); } |
565 | if (do { ++$a; GLIPP }) { x(); } | |
566 | #### | |
0fa4a265 | 567 | # TODO constant deparsing has been backed out for 5.12 |
507a68aa | 568 | # tests for deparsing constants |
2990415a FR |
569 | warn PI; |
570 | #### | |
0fa4a265 | 571 | # TODO constant deparsing has been backed out for 5.12 |
507a68aa | 572 | # tests for deparsing imported constants |
3779476a | 573 | warn O_TRUNC; |
2990415a | 574 | #### |
0fa4a265 | 575 | # TODO constant deparsing has been backed out for 5.12 |
507a68aa | 576 | # tests for deparsing re-exported constants |
2990415a FR |
577 | warn O_CREAT; |
578 | #### | |
0fa4a265 | 579 | # TODO constant deparsing has been backed out for 5.12 |
507a68aa | 580 | # tests for deparsing imported constants that got deleted from the original namespace |
aaf9c2b2 | 581 | warn O_APPEND; |
2990415a | 582 | #### |
0fa4a265 DM |
583 | # TODO constant deparsing has been backed out for 5.12 |
584 | # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads" | |
507a68aa | 585 | # tests for deparsing constants which got turned into full typeglobs |
ac0f1413 NC |
586 | # It might be fundamentally impossible to make this work on ithreads, in which |
587 | # case the TODO should become a SKIP | |
2990415a FR |
588 | warn O_EXCL; |
589 | eval '@Fcntl::O_EXCL = qw/affe tiger/;'; | |
590 | warn O_EXCL; | |
591 | #### | |
0fa4a265 | 592 | # TODO constant deparsing has been backed out for 5.12 |
507a68aa | 593 | # tests for deparsing of blessed constant with overloaded numification |
2990415a | 594 | warn OVERLOADED_NUMIFICATION; |
79289e05 NC |
595 | #### |
596 | # TODO Only strict 'refs' currently supported | |
507a68aa | 597 | # strict |
79289e05 NC |
598 | no strict; |
599 | $x; | |
600 | #### | |
601 | # TODO Subsets of warnings could be encoded textually, rather than as bitflips. | |
507a68aa | 602 | # subsets of warnings |
79289e05 NC |
603 | no warnings 'deprecated'; |
604 | my $x; | |
605 | #### | |
606 | # TODO Better test for CPAN #33708 - the deparsed code has different behaviour | |
507a68aa | 607 | # CPAN #33708 |
79289e05 NC |
608 | use strict; |
609 | no warnings; | |
610 | ||
611 | foreach (0..3) { | |
612 | my $x = 2; | |
613 | { | |
614 | my $x if 0; | |
615 | print ++$x, "\n"; | |
616 | } | |
617 | } | |
d83f38d8 | 618 | #### |
507a68aa | 619 | # no attribute list |
d83f38d8 NC |
620 | my $pi = 4; |
621 | #### | |
507a68aa | 622 | # := empty attribute list |
d83f38d8 NC |
623 | no warnings; |
624 | my $pi := 4; | |
625 | >>>> | |
626 | no warnings; | |
627 | my $pi = 4; | |
628 | #### | |
507a68aa | 629 | # : = empty attribute list |
d83f38d8 NC |
630 | my $pi : = 4; |
631 | >>>> | |
632 | my $pi = 4; | |
689e417f | 633 | #### |
507a68aa | 634 | # in place sort |
689e417f VP |
635 | our @a; |
636 | my @b; | |
637 | @a = sort @a; | |
638 | @b = sort @b; | |
639 | (); | |
640 | #### | |
507a68aa | 641 | # in place reverse |
689e417f VP |
642 | our @a; |
643 | my @b; | |
644 | @a = reverse @a; | |
645 | @b = reverse @b; | |
646 | (); | |
06fc6867 | 647 | #### |
507a68aa | 648 | # #71870 Use of uninitialized value in bitwise and B::Deparse |
06fc6867 VP |
649 | my($r, $s, @a); |
650 | @a = split(/foo/, $s, 0); | |
651 | $r = qr/foo/; | |
652 | @a = split(/$r/, $s, 0); | |
653 | (); | |
98a1a137 | 654 | #### |
507a68aa | 655 | # package declaration before label |
98a1a137 Z |
656 | { |
657 | package Foo; | |
658 | label: print 123; | |
659 | } | |
538f5756 | 660 | #### |
507a68aa | 661 | # shift optimisation |
538f5756 RZ |
662 | shift; |
663 | >>>> | |
664 | shift(); | |
665 | #### | |
507a68aa | 666 | # shift optimisation |
538f5756 RZ |
667 | shift @_; |
668 | #### | |
507a68aa | 669 | # shift optimisation |
538f5756 RZ |
670 | pop; |
671 | >>>> | |
672 | pop(); | |
673 | #### | |
507a68aa | 674 | # shift optimisation |
538f5756 | 675 | pop @_; |
a539498a | 676 | #### |
507a68aa | 677 | #[perl #20444] |
a539498a FC |
678 | "foo" =~ (1 ? /foo/ : /bar/); |
679 | "foo" =~ (1 ? y/foo// : /bar/); | |
680 | "foo" =~ (1 ? s/foo// : /bar/); | |
681 | >>>> | |
682 | 'foo' =~ ($_ =~ /foo/); | |
683 | 'foo' =~ ($_ =~ tr/fo//); | |
684 | 'foo' =~ ($_ =~ s/foo//); | |
e0ab66ad NC |
685 | #### |
686 | # Test @threadsv_names under 5005threads | |
687 | foreach $' (1, 2) { | |
688 | sleep $'; | |
689 | } | |
e7afc405 FC |
690 | #### |
691 | # y///r | |
692 | tr/a/b/r; | |
cb8157e3 FC |
693 | #### |
694 | # y/uni/code/ | |
695 | tr/\x{345}/\x{370}/; |