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