This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
use VERSION needs to enable uni8bit hint
[perl5.git] / dist / B-Deparse / t / deparse.t
CommitLineData
87a42246
MS
1#!./perl
2
3BEGIN {
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
12use warnings;
13use strict;
e9c69003 14BEGIN {
c4a6f826 15 # BEGIN block is actually a subroutine :-)
e9c69003
NC
16 return unless $] > 5.009;
17 require feature;
18 feature->import(':5.10');
19}
507a68aa 20use Test::More;
1bb3cfc5 21use Config ();
87a42246
MS
22
23use B::Deparse;
09d856fb 24my $deparse = B::Deparse->new();
507a68aa 25isa_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 33 '%^H' => $hinthash,
87a42246
MS
34 );
35}
36
ad46c0be
RH
37$/ = "\n####\n";
38while (<DATA>) {
39 chomp;
e9c69003
NC
40 # This code is pinched from the t/lib/common.pl for TODO.
41 # It's not clear how to avoid duplication
b871937f
NC
42 # Now tweaked a bit to do skip or todo
43 my %reason;
44 foreach my $what (qw(skip todo)) {
45 s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1;
46 # If the SKIP reason starts ? then it's taken as a code snippet to
47 # evaluate. This provides the flexibility to have conditional SKIPs
48 if ($reason{$what} && $reason{$what} =~ s/^\?//) {
49 my $temp = eval $reason{$what};
50 if ($@) {
51 die "# In \U$what\E code reason:\n# $reason{$what}\n$@";
52 }
53 $reason{$what} = $temp;
e9c69003 54 }
e9c69003
NC
55 }
56
4a4b8592 57 s/^\s*#\s*(.*)$//mg;
507a68aa
NC
58 my $desc = $1;
59 die "Missing name in test $_" unless defined $desc;
e9c69003 60
b871937f 61 if ($reason{skip}) {
e9c69003 62 # Like this to avoid needing a label SKIP:
b871937f 63 Test::More->builder->skip($reason{skip});
e9c69003
NC
64 next;
65 }
66
ad46c0be
RH
67 my ($input, $expected);
68 if (/(.*)\n>>>>\n(.*)/s) {
69 ($input, $expected) = ($1, $2);
70 }
71 else {
72 ($input, $expected) = ($_, $_);
73 }
87a42246 74
ad46c0be 75 my $coderef = eval "sub {$input}";
87a42246 76
ad46c0be 77 if ($@) {
507a68aa 78 is($@, "", "compilation of $desc");
ad46c0be
RH
79 }
80 else {
81 my $deparsed = $deparse->coderef2text( $coderef );
31c6271a
RD
82 my $regex = $expected;
83 $regex =~ s/(\S+)/\Q$1/g;
84 $regex =~ s/\s+/\\s+/g;
85 $regex = '^\{\s*' . $regex . '\s*\}$';
b871937f 86
4a4b8592 87 local $::TODO = $reason{todo};
507a68aa 88 like($deparsed, qr/$regex/, $desc);
87a42246 89 }
87a42246
MS
90}
91
87a42246 92use constant 'c', 'stuff';
507a68aa
NC
93is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
94 'the subroutine generated by use constant deparses');
87a42246 95
09d856fb 96my $a = 0;
507a68aa
NC
97is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
98 'anon sub capturing an external lexical');
87a42246 99
d989cdac
SM
100use constant cr => ['hello'];
101my $string = "sub " . $deparse->coderef2text(\&cr);
0707d6cc 102my $val = (eval $string)->() or diag $string;
507a68aa
NC
103is(ref($val), 'ARRAY', 'constant array references deparse');
104is($val->[0], 'hello', 'and return the correct value');
87a42246 105
87a42246 106my $path = join " ", map { qq["-I$_"] } @INC;
87a42246 107
7cde0a5f 108$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
e69a2255 109$a =~ s/-e syntax OK\n//g;
d2bc402e 110$a =~ s/.*possible typo.*\n//; # Remove warning line
87a42246
MS
111$a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
112$a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
113$b = <<'EOF';
d2bc402e
RGS
114BEGIN { $^I = ".bak"; }
115BEGIN { $^W = 1; }
116BEGIN { $/ = "\n"; $\ = "\n"; }
87a42246
MS
117LINE: while (defined($_ = <ARGV>)) {
118 chomp $_;
f86ea535 119 our(@F) = split(' ', $_, 0);
87a42246
MS
120 '???';
121}
87a42246 122EOF
507a68aa
NC
123is($a, $b,
124 'command line flags deparse as BEGIN blocks setting control variables');
87a42246 125
5b4ee549
NC
126$a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
127$a =~ s/-e syntax OK\n//g;
128is($a, "use constant ('PI', 4);\n",
129 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
130
579a54dc 131#Re: perlbug #35857, patch #24505
b3980c39
YO
132#handle warnings::register-ed packages properly.
133package B::Deparse::Wrapper;
134use strict;
135use warnings;
136use warnings::register;
137sub getcode {
579a54dc 138 my $deparser = B::Deparse->new();
b3980c39
YO
139 return $deparser->coderef2text(shift);
140}
141
2990415a
FR
142package Moo;
143use overload '0+' => sub { 42 };
144
b3980c39
YO
145package main;
146use strict;
147use warnings;
71c4dbc3 148use constant GLIPP => 'glipp';
2990415a
FR
149use constant PI => 4;
150use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
3779476a 151use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
aaf9c2b2 152BEGIN { delete $::Fcntl::{O_APPEND}; }
2990415a 153use POSIX qw/O_CREAT/;
b3980c39 154sub test {
579a54dc
RGS
155 my $val = shift;
156 my $res = B::Deparse::Wrapper::getcode($val);
507a68aa
NC
157 like($res, qr/use warnings/,
158 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
b3980c39
YO
159}
160my ($q,$p);
161my $x=sub { ++$q,++$p };
162test($x);
163eval <<EOFCODE and test($x);
164 package bar;
165 use strict;
166 use warnings;
167 use warnings::register;
168 package main;
169 1
170EOFCODE
171
d1dc589d
FC
172# Exotic sub declarations
173$a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
174$a =~ s/-e syntax OK\n//g;
175is($a, <<'EOCODG', "sub :::: and sub ::::::");
176sub :::: {
177
178}
179sub :::::: {
180
181}
182EOCODG
183
640d5d41
FC
184# [perl #33752]
185{
186 my $code = <<"EOCODE";
187{
188 our \$\x{1e1f}\x{14d}\x{14d};
189}
190EOCODE
191 my $deparsed
192 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
193 s/$ \n//x for $deparsed, $code;
194 is $deparsed, $code, 'our $funny_Unicode_chars';
195}
196
bdabb2d5
FC
197# [perl #62500]
198$a =
199 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
200$a =~ s/-e syntax OK\n//g;
201is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
202sub BEGIN {
203 *CORE::GLOBAL::require = sub {
204 1;
205 }
206 ;
207}
208EOCODF
209
894e98ac
FC
210# [perl #91384]
211$a =
212 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
213like($a, qr/-e syntax OK/,
214 "Deparse does not hang when traversing stash circularities");
215
bb8996b8 216# [perl #93990]
5c19ffe6 217@* = ();
bb8996b8
HY
218is($deparse->coderef2text(sub{ print "@{*}" }),
219q<{
220 print "@{*}";
221}>, 'curly around to interpolate "@{*}"');
222is($deparse->coderef2text(sub{ print "@{-}" }),
223q<{
224 print "@-";
225}>, 'no need to curly around to interpolate "@-"');
226
1c74777c
FC
227# Strict hints in %^H are mercilessly suppressed
228$a =
229 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
230unlike($a, qr/BEGIN/,
231 "Deparse does not emit strict hh hints");
232
507a68aa
NC
233done_testing();
234
ad46c0be 235__DATA__
507a68aa 236# A constant
ad46c0be
RH
2371;
238####
507a68aa 239# Constants in a block
ad46c0be
RH
240{
241 no warnings;
242 '???';
243 2;
244}
245####
507a68aa 246# Lexical and simple arithmetic
ad46c0be
RH
247my $test;
248++$test and $test /= 2;
249>>>>
250my $test;
251$test /= 2 if ++$test;
252####
507a68aa 253# list x
ad46c0be
RH
254-((1, 2) x 2);
255####
507a68aa 256# lvalue sub
ad46c0be
RH
257{
258 my $test = sub : lvalue {
259 my $x;
260 }
261 ;
262}
263####
507a68aa 264# method
ad46c0be
RH
265{
266 my $test = sub : method {
267 my $x;
268 }
269 ;
270}
271####
507a68aa 272# block with continue
87a42246 273{
ad46c0be 274 234;
f99a63a2 275}
ad46c0be
RH
276continue {
277 123;
87a42246 278}
ce4e655d 279####
507a68aa 280# lexical and package scalars
ce4e655d
RH
281my $x;
282print $main::x;
283####
507a68aa 284# lexical and package arrays
ce4e655d
RH
285my @x;
286print $main::x[1];
14a55f98 287####
507a68aa 288# lexical and package hashes
14a55f98
RH
289my %x;
290$x{warn()};
ad8caead 291####
507a68aa 292# <>
ad8caead
RGS
293my $foo;
294$_ .= <ARGV> . <$foo>;
cef22867 295####
507a68aa 296# \x{}
11454c59 297my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
4ae52e81 298####
507a68aa 299# s///e
4ae52e81 300s/x/'y';/e;
241416b8 301####
507a68aa 302# block
241416b8
DM
303{ my $x; }
304####
507a68aa 305# while 1
241416b8
DM
306while (1) { my $k; }
307####
507a68aa 308# trailing for
241416b8
DM
309my ($x,@a);
310$x=1 for @a;
311>>>>
312my($x, @a);
0bb5f065 313$x = 1 foreach (@a);
241416b8 314####
507a68aa 315# 2 arguments in a 3 argument for
241416b8
DM
316for (my $i = 0; $i < 2;) {
317 my $z = 1;
318}
319####
507a68aa 320# 3 argument for
241416b8
DM
321for (my $i = 0; $i < 2; ++$i) {
322 my $z = 1;
323}
324####
507a68aa 325# 3 argument for again
241416b8
DM
326for (my $i = 0; $i < 2; ++$i) {
327 my $z = 1;
328}
329####
507a68aa 330# while/continue
241416b8
DM
331my $i;
332while ($i) { my $z = 1; } continue { $i = 99; }
333####
507a68aa 334# foreach with my
09d856fb 335foreach my $i (1, 2) {
241416b8
DM
336 my $z = 1;
337}
338####
507a68aa 339# foreach
241416b8
DM
340my $i;
341foreach $i (1, 2) {
342 my $z = 1;
343}
344####
507a68aa 345# foreach, 2 mys
241416b8
DM
346my $i;
347foreach my $i (1, 2) {
348 my $z = 1;
349}
350####
507a68aa 351# foreach
241416b8
DM
352foreach my $i (1, 2) {
353 my $z = 1;
354}
355####
507a68aa 356# foreach with our
241416b8
DM
357foreach our $i (1, 2) {
358 my $z = 1;
359}
360####
507a68aa 361# foreach with my and our
241416b8
DM
362my $i;
363foreach our $i (1, 2) {
364 my $z = 1;
365}
3ac6e0f9 366####
507a68aa 367# reverse sort
3ac6e0f9
RGS
368my @x;
369print reverse sort(@x);
370####
507a68aa 371# sort with cmp
3ac6e0f9
RGS
372my @x;
373print((sort {$b cmp $a} @x));
374####
507a68aa 375# reverse sort with block
3ac6e0f9
RGS
376my @x;
377print((reverse sort {$b <=> $a} @x));
36d57d93 378####
507a68aa 379# foreach reverse
36d57d93
RGS
380our @a;
381print $_ foreach (reverse @a);
aae53c41 382####
507a68aa 383# foreach reverse (not inplace)
aae53c41
RGS
384our @a;
385print $_ foreach (reverse 1, 2..5);
f86ea535 386####
507a68aa 387# bug #38684
f86ea535
SM
388our @ary;
389@ary = split(' ', 'foo', 0);
31c6271a 390####
507a68aa 391# bug #40055
31c6271a
RD
392do { () };
393####
507a68aa 394# bug #40055
31c6271a 395do { my $x = 1; $x };
d9002312 396####
507a68aa 397# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
398my $f = sub {
399 +{[]};
400} ;
8b2d6640 401####
507a68aa 402# bug #43010
8b2d6640
FC
403'!@$%'->();
404####
507a68aa 405# bug #43010
8b2d6640
FC
406::();
407####
507a68aa 408# bug #43010
8b2d6640
FC
409'::::'->();
410####
507a68aa 411# bug #43010
8b2d6640 412&::::;
09d856fb 413####
1b38d782
FC
414# [perl #77172]
415package rt77172;
416sub foo {} foo & & & foo;
417>>>>
418package rt77172;
419foo(&{&} & foo());
420####
507a68aa 421# variables as method names
09d856fb
CK
422my $bar;
423'Foo'->$bar('orz');
35a99a08 424'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 425####
507a68aa 426# constants as method names
09d856fb
CK
427'Foo'->bar('orz');
428####
507a68aa 429# constants as method names without ()
09d856fb 430'Foo'->bar;
0ced6c29 431####
28bfcb02 432# [perl #47359] "indirect" method call notation
1bf8bbb0
FC
433our @bar;
434foo{@bar}+1,->foo;
435(foo{@bar}+1),foo();
436foo{@bar}1 xor foo();
437>>>>
438our @bar;
439(foo { @bar } 1)->foo;
440(foo { @bar } 1), foo();
441foo { @bar } 1 xor foo();
442####
e9c69003 443# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
507a68aa 444# say
7ddd1a01
NC
445say 'foo';
446####
e9c69003 447# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 448# state vars
0ced6c29
RGS
449state $x = 42;
450####
e9c69003 451# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 452# state var assignment
7ddd1a01
NC
453{
454 my $y = (state $x = 42);
455}
456####
e9c69003 457# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
c4a6f826 458# state vars in anonymous subroutines
7ddd1a01
NC
459$a = sub {
460 state $x;
461 return $x++;
462}
463;
644741fd
NC
464####
465# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 466# each @array;
644741fd
NC
467each @ARGV;
468each @$a;
469####
470# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 471# keys @array; values @array
644741fd
NC
472keys @$a if keys @ARGV;
473values @ARGV if values @$a;
35925e80 474####
507a68aa 475# Anonymous arrays and hashes, and references to them
35925e80
RGS
476my $a = {};
477my $b = \{};
478my $c = [];
479my $d = \[];
9210de83
FR
480####
481# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
507a68aa 482# implicit smartmatch in given/when
9210de83
FR
483given ('foo') {
484 when ('bar') { continue; }
485 when ($_ ~~ 'quux') { continue; }
486 default { 0; }
487}
7ecdd211 488####
507a68aa 489# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
490if ($a) { x(); }
491elsif ($b) { x(); }
492elsif ($a and $b) { x(); }
493elsif ($a or $b) { x(); }
494else { x(); }
03b22f1b 495####
507a68aa 496# interpolation in regexps
03b22f1b
RGS
497my($y, $t);
498/x${y}z$t/;
227375e1 499####
4a4b8592 500# TODO new undocumented cpan-bug #33708
507a68aa 501# cpan-bug #33708
227375e1
RU
502%{$_ || {}}
503####
4a4b8592 504# TODO hash constants not yet fixed
507a68aa 505# cpan-bug #33708
227375e1
RU
506use constant H => { "#" => 1 }; H->{"#"}
507####
4a4b8592 508# TODO optimized away 0 not yet fixed
507a68aa 509# cpan-bug #33708
227375e1 510foreach my $i (@_) { 0 }
edbe35ea 511####
507a68aa 512# tests with not, not optimized
07f3cdf5 513my $c;
edbe35ea
VP
514x() unless $a;
515x() if not $a and $b;
516x() if $a and not $b;
517x() unless not $a and $b;
518x() unless $a and not $b;
519x() if not $a or $b;
520x() if $a or not $b;
521x() unless not $a or $b;
522x() unless $a or not $b;
07f3cdf5
VP
523x() if $a and not $b and $c;
524x() if not $a and $b and not $c;
525x() unless $a and not $b and $c;
526x() unless not $a and $b and not $c;
527x() if $a or not $b or $c;
528x() if not $a or $b or not $c;
529x() unless $a or not $b or $c;
530x() unless not $a or $b or not $c;
edbe35ea 531####
507a68aa 532# tests with not, optimized
07f3cdf5 533my $c;
edbe35ea
VP
534x() if not $a;
535x() unless not $a;
536x() if not $a and not $b;
537x() unless not $a and not $b;
538x() if not $a or not $b;
539x() unless not $a or not $b;
07f3cdf5
VP
540x() if not $a and not $b and $c;
541x() unless not $a and not $b and $c;
542x() if not $a or not $b or $c;
543x() unless not $a or not $b or $c;
544x() if not $a and not $b and not $c;
545x() unless not $a and not $b and not $c;
546x() if not $a or not $b or not $c;
547x() unless not $a or not $b or not $c;
548x() unless not $a or not $b or not $c;
edbe35ea 549>>>>
07f3cdf5 550my $c;
edbe35ea
VP
551x() unless $a;
552x() if $a;
553x() unless $a or $b;
554x() if $a or $b;
555x() unless $a and $b;
07f3cdf5
VP
556x() if $a and $b;
557x() if not $a || $b and $c;
558x() unless not $a || $b and $c;
559x() if not $a && $b or $c;
560x() unless not $a && $b or $c;
561x() unless $a or $b or $c;
562x() if $a or $b or $c;
563x() unless $a and $b and $c;
564x() if $a and $b and $c;
565x() unless not $a && $b && $c;
71c4dbc3 566####
507a68aa 567# tests that should be constant folded
71c4dbc3
VP
568x() if 1;
569x() if GLIPP;
570x() if !GLIPP;
571x() if GLIPP && GLIPP;
572x() if !GLIPP || GLIPP;
573x() if do { GLIPP };
574x() if do { no warnings 'void'; 5; GLIPP };
575x() if do { !GLIPP };
576if (GLIPP) { x() } else { z() }
577if (!GLIPP) { x() } else { z() }
578if (GLIPP) { x() } elsif (GLIPP) { z() }
579if (!GLIPP) { x() } elsif (GLIPP) { z() }
580if (GLIPP) { x() } elsif (!GLIPP) { z() }
581if (!GLIPP) { x() } elsif (!GLIPP) { z() }
582if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
583if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
584if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
585>>>>
586x();
587x();
588'???';
589x();
590x();
591x();
592x();
593do {
594 '???'
595};
596do {
597 x()
598};
599do {
600 z()
601};
602do {
603 x()
604};
605do {
606 z()
607};
608do {
609 x()
610};
611'???';
612do {
613 t()
614};
615'???';
616!1;
617####
719c50dc
RGS
618# TODO constant deparsing has been backed out for 5.12
619# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 620# tests that shouldn't be constant folded
ac0f1413
NC
621# It might be fundamentally impossible to make this work on ithreads, in which
622# case the TODO should become a SKIP
71c4dbc3
VP
623x() if $a;
624if ($a == 1) { x() } elsif ($b == 2) { z() }
625if (do { foo(); GLIPP }) { x() }
626if (do { $a++; GLIPP }) { x() }
627>>>>
628x() if $a;
629if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
630if (do { foo(); GLIPP }) { x(); }
631if (do { ++$a; GLIPP }) { x(); }
632####
0fa4a265 633# TODO constant deparsing has been backed out for 5.12
507a68aa 634# tests for deparsing constants
2990415a
FR
635warn PI;
636####
0fa4a265 637# TODO constant deparsing has been backed out for 5.12
507a68aa 638# tests for deparsing imported constants
3779476a 639warn O_TRUNC;
2990415a 640####
0fa4a265 641# TODO constant deparsing has been backed out for 5.12
507a68aa 642# tests for deparsing re-exported constants
2990415a
FR
643warn O_CREAT;
644####
0fa4a265 645# TODO constant deparsing has been backed out for 5.12
507a68aa 646# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 647warn O_APPEND;
2990415a 648####
0fa4a265
DM
649# TODO constant deparsing has been backed out for 5.12
650# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 651# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
652# It might be fundamentally impossible to make this work on ithreads, in which
653# case the TODO should become a SKIP
2990415a
FR
654warn O_EXCL;
655eval '@Fcntl::O_EXCL = qw/affe tiger/;';
656warn O_EXCL;
657####
0fa4a265 658# TODO constant deparsing has been backed out for 5.12
507a68aa 659# tests for deparsing of blessed constant with overloaded numification
2990415a 660warn OVERLOADED_NUMIFICATION;
79289e05
NC
661####
662# TODO Only strict 'refs' currently supported
507a68aa 663# strict
79289e05
NC
664no strict;
665$x;
666####
667# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 668# subsets of warnings
79289e05
NC
669no warnings 'deprecated';
670my $x;
671####
672# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 673# CPAN #33708
79289e05
NC
674use strict;
675no warnings;
676
677foreach (0..3) {
678 my $x = 2;
679 {
680 my $x if 0;
681 print ++$x, "\n";
682 }
683}
d83f38d8 684####
507a68aa 685# no attribute list
d83f38d8
NC
686my $pi = 4;
687####
2dc78664
NC
688# SKIP ?$] > 5.013006 && ":= is now a syntax error"
689# := treated as an empty attribute list
d83f38d8
NC
690no warnings;
691my $pi := 4;
692>>>>
693no warnings;
694my $pi = 4;
695####
507a68aa 696# : = empty attribute list
d83f38d8
NC
697my $pi : = 4;
698>>>>
699my $pi = 4;
689e417f 700####
507a68aa 701# in place sort
689e417f
VP
702our @a;
703my @b;
704@a = sort @a;
705@b = sort @b;
706();
707####
507a68aa 708# in place reverse
689e417f
VP
709our @a;
710my @b;
711@a = reverse @a;
712@b = reverse @b;
713();
06fc6867 714####
507a68aa 715# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
716my($r, $s, @a);
717@a = split(/foo/, $s, 0);
718$r = qr/foo/;
719@a = split(/$r/, $s, 0);
720();
98a1a137 721####
507a68aa 722# package declaration before label
98a1a137
Z
723{
724 package Foo;
725 label: print 123;
726}
538f5756 727####
507a68aa 728# shift optimisation
538f5756
RZ
729shift;
730>>>>
731shift();
732####
507a68aa 733# shift optimisation
538f5756
RZ
734shift @_;
735####
507a68aa 736# shift optimisation
538f5756
RZ
737pop;
738>>>>
739pop();
740####
507a68aa 741# shift optimisation
538f5756 742pop @_;
a539498a 743####
507a68aa 744#[perl #20444]
a539498a
FC
745"foo" =~ (1 ? /foo/ : /bar/);
746"foo" =~ (1 ? y/foo// : /bar/);
5e5a1632 747"foo" =~ (1 ? y/foo//r : /bar/);
a539498a
FC
748"foo" =~ (1 ? s/foo// : /bar/);
749>>>>
750'foo' =~ ($_ =~ /foo/);
751'foo' =~ ($_ =~ tr/fo//);
5e5a1632 752'foo' =~ ($_ =~ tr/fo//r);
a539498a 753'foo' =~ ($_ =~ s/foo//);
e0ab66ad 754####
5e5a1632
FC
755# The fix for [perl #20444] broke this.
756'foo' =~ do { () };
757####
4b58603b
FC
758# [perl #81424] match against aelemfast_lex
759my @s;
760print /$s[1]/;
761####
b9bc576f 762# [perl #91318] /regexp/applaud
09622ee2
FC
763print /a/a, s/b/c/a;
764print /a/aa, s/b/c/aa;
765print /a/p, s/b/c/p;
766print /a/l, s/b/c/l;
767print /a/u, s/b/c/u;
b9bc576f
FC
768{
769 use feature "unicode_strings";
09622ee2 770 print /a/d, s/b/c/d;
b9bc576f
FC
771}
772{
773 use re "/u";
09622ee2 774 print /a/d, s/b/c/d;
b9bc576f
FC
775}
776>>>>
09622ee2
FC
777print /a/a, s/b/c/a;
778print /a/aa, s/b/c/aa;
779print /a/p, s/b/c/p;
780print /a/l, s/b/c/l;
781print /a/u, s/b/c/u;
b9bc576f
FC
782{
783 BEGIN { $^H{'feature_unicode'} = '1'; }
09622ee2 784 print /a/d, s/b/c/d;
b9bc576f
FC
785}
786{
787 BEGIN { $^H{'reflags_charset'} = '2';
788 $^H{'reflags'} = '0'; }
09622ee2 789 print /a/d, s/b/c/d;
b9bc576f
FC
790}
791####
e0ab66ad
NC
792# Test @threadsv_names under 5005threads
793foreach $' (1, 2) {
794 sleep $';
795}
e7afc405
FC
796####
797# y///r
798tr/a/b/r;
cb8157e3
FC
799####
800# y/uni/code/
801tr/\x{345}/\x{370}/;
cb8578ff
FC
802####
803# [perl #90898]
f4002a4b 804<a,>;
09dcfa7d
FC
805####
806# [perl #91008]
807each $@;
808keys $~;
809values $!;
5d8c42c2
FC
810####
811# readpipe with complex expression
812readpipe $a + $b;
93bad3fd
NC
813####
814# aelemfast
815$b::a[0] = 1;
816####
817# aelemfast for a lexical
818my @a;
819$a[0] = 1;
80e3f4ad
FC
820####
821# feature features without feature
822BEGIN {
823 delete $^H{'feature_say'};
824 delete $^H{'feature_state'};
825 delete $^H{'feature_switch'};
826}
827CORE::state $x;
828CORE::say $x;
829CORE::given ($x) {
830 CORE::when (3) {
831 continue;
832 }
833 CORE::default {
e36901c8 834 CORE::break;
80e3f4ad
FC
835 }
836}
7d789282 837CORE::evalbytes '';
84ed0108 838() = CORE::__SUB__;
6ec73527
FC
839####
840# $#- $#+ $#{%} etc.
841my @x;
842@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
843@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
844@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
845@x = ($#{;}, $#{:});
61154ac0
FC
846####
847# ${#} interpolated (the first line magically disables the warning)
848() = *#;
849() = "${#}a";
958ed56b
FC
850####
851# ()[...]
852my(@a) = ()[()];
521795fe
FC
853####
854# sort(foo(bar))
855# sort(foo(bar)) is interpreted as sort &foo(bar)
856# sort foo(bar) is interpreted as sort foo bar
857# parentheses are not optional in this case
858print sort(foo('bar'));
859>>>>
860print sort(foo('bar'));
24fcb59f
FC
861####
862# substr assignment
863substr(my $a, 0, 0) = (foo(), bar());
864$a++;
04be0204
FC
865####
866# hint hash
867BEGIN { $^H{'foo'} = undef; }
868{
869 BEGIN { $^H{'bar'} = undef; }
870 {
871 BEGIN { $^H{'baz'} = undef; }
872 {
873 print $_;
874 }
875 print $_;
876 }
877 print $_;
878}
035146a3
FC
879BEGIN { $^H{q[']} = '('; }
880print $_;
c306e834
FC
881####
882# hint hash changes that serialise the same way with sort %hh
883BEGIN { $^H{'a'} = 'b'; }
884{
885 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
886 print $_;
887}
888print $_;
94bb57f9
FC
889####
890# [perl #47361] do({}) and do +{} (variants of do-file)
891do({});
892do +{};
8b46c09b
FC
893sub foo::do {}
894package foo;
895CORE::do({});
896CORE::do +{};
94bb57f9
FC
897>>>>
898do({});
899do({});
8b46c09b
FC
900package foo;
901CORE::do({});
902CORE::do({});
9c56d9ea
FC
903####
904# [perl #77096] functions that do not follow the llafr
905() = (return 1) + time;
906() = (return ($1 + $2) * $3) + time;
907() = (return ($a xor $b)) + time;
908() = (do 'file') + time;
909() = (do ($1 + $2) * $3) + time;
910() = (do ($1 xor $2)) + time;
41df74e3
FC
911() = (goto 1) + 3;
912() = (require 'foo') + 3;
913() = (require foo) + 3;
266da325 914() = (CORE::dump 1) + 3;
41df74e3
FC
915() = (last 1) + 3;
916() = (next 1) + 3;
917() = (redo 1) + 3;
5830412d
FC
918() = (-R $_) + 3;
919() = (-W $_) + 3;
920() = (-X $_) + 3;
921() = (-r $_) + 3;
922() = (-w $_) + 3;
923() = (-x $_) + 3;
2462c3cc 924####
1cabb3b3
FC
925# [perl #97476] not() *does* follow the llafr
926$_ = ($a xor not +($1 || 2) ** 2);
927####
4d8ac5c7
FC
928# Precedence conundrums with argument-less function calls
929() = (eof) + 1;
930() = (return) + 1;
931() = (return, 1);
7bc8c979
FC
932() = warn;
933() = warn() + 1;
4d8ac5c7
FC
934() = setpgrp() + 1;
935####
2462c3cc
FC
936# [perl #63558] open local(*FH)
937open local *FH;
564cd6cb 938pipe local *FH, local *FH;
843b15cc 939####
b89b7257
FC
940# [perl #91416] open "string"
941open 'open';
942open '####';
943open '^A';
944open "\ca";
945>>>>
946open *open;
947open '####';
948open '^A';
949open *^A;
950####
be6cf5cf
FC
951# "string"->[] ->{}
952no strict 'vars';
953() = 'open'->[0]; #aelemfast
954() = '####'->[0];
955() = '^A'->[0];
956() = "\ca"->[0];
b861b87f 957() = 'a::]b'->[0];
10e8e32b
FC
958() = 'open'->[$_]; #aelem
959() = '####'->[$_];
960() = '^A'->[$_];
961() = "\ca"->[$_];
b861b87f 962() = 'a::]b'->[$_];
10e8e32b
FC
963() = 'open'->{0}; #helem
964() = '####'->{0};
965() = '^A'->{0};
966() = "\ca"->{0};
b861b87f 967() = 'a::]b'->{0};
be6cf5cf
FC
968>>>>
969() = $open[0];
970() = '####'->[0];
971() = '^A'->[0];
972() = $^A[0];
b861b87f 973() = 'a::]b'->[0];
10e8e32b
FC
974() = $open[$_];
975() = '####'->[$_];
976() = '^A'->[$_];
977() = $^A[$_];
b861b87f 978() = 'a::]b'->[$_];
10e8e32b
FC
979() = $open{'0'};
980() = '####'->{'0'};
981() = '^A'->{'0'};
982() = $^A{'0'};
b861b87f 983() = 'a::]b'->{'0'};
be6cf5cf 984####
843b15cc
FC
985# [perl #74740] -(f()) vs -f()
986$_ = -(f());
c75b4828
FC
987####
988# require <binop>
989require 'a' . $1;