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