6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 44; # not counting those in the __DATA__ section
19 my $deparse = B::Deparse->new();
20 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
27 # This code is pinched from the t/lib/common.pl for TODO.
28 # It's not clear how to avoid duplication
29 my %meta = (context => '');
30 foreach my $what (qw(skip todo context options)) {
31 s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
32 # If the SKIP reason starts ? then it's taken as a code snippet to
33 # evaluate. This provides the flexibility to have conditional SKIPs
34 if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35 my $temp = eval $meta{$what};
37 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
45 die "Missing name in test $_" unless defined $desc;
48 SKIP: { skip($meta{skip}) };
52 my ($input, $expected);
53 if (/(.*)\n>>>>\n(.*)/s) {
54 ($input, $expected) = ($1, $2);
57 ($input, $expected) = ($_, $_);
60 # parse options if necessary
61 my $deparse = $meta{options}
62 ? $deparse{$meta{options}} ||=
63 new B::Deparse split /,/, $meta{options}
66 my $coderef = eval "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
67 # Tell B::Deparse about our ambient pragmas
68 my ($hint_bits, $warning_bits, $hinthash);
70 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
72 $deparse->ambient_pragmas (
73 hint_bits => $hint_bits,
74 warning_bits => $warning_bits,
79 local $::TODO = $meta{todo};
81 is($@, "", "compilation of $desc");
84 my $deparsed = $deparse->coderef2text( $coderef );
85 my $regex = $expected;
86 $regex =~ s/(\S+)/\Q$1/g;
87 $regex =~ s/\s+/\\s+/g;
88 $regex = '^\{\s*' . $regex . '\s*\}$';
90 like($deparsed, qr/$regex/, $desc);
94 # Reset the ambient pragmas
98 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
100 $deparse->ambient_pragmas (
107 use constant 'c', 'stuff';
108 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
109 'the subroutine generated by use constant deparses');
112 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
113 'anon sub capturing an external lexical');
115 use constant cr => ['hello'];
116 my $string = "sub " . $deparse->coderef2text(\&cr);
117 my $val = (eval $string)->() or diag $string;
118 is(ref($val), 'ARRAY', 'constant array references deparse');
119 is($val->[0], 'hello', 'and return the correct value');
121 my $path = join " ", map { qq["-I$_"] } @INC;
123 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
124 $a =~ s/-e syntax OK\n//g;
125 $a =~ s/.*possible typo.*\n//; # Remove warning line
126 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
127 $b = quotemeta <<'EOF';
128 BEGIN { $^I = ".bak"; }
130 BEGIN { $/ = "\n"; $\ = "\n"; }
131 LINE: while (defined($_ = <ARGV>)) {
133 our(@F) = split(' ', $_, 0);
137 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
139 'command line flags deparse as BEGIN blocks setting control variables');
141 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
142 $a =~ s/-e syntax OK\n//g;
143 is($a, "use constant ('PI', 4);\n",
144 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
146 #Re: perlbug #35857, patch #24505
147 #handle warnings::register-ed packages properly.
148 package B::Deparse::Wrapper;
151 use warnings::register;
153 my $deparser = B::Deparse->new();
154 return $deparser->coderef2text(shift);
158 use overload '0+' => sub { 42 };
163 use constant GLIPP => 'glipp';
164 use constant PI => 4;
165 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
166 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
167 BEGIN { delete $::Fcntl::{O_APPEND}; }
168 use POSIX qw/O_CREAT/;
171 my $res = B::Deparse::Wrapper::getcode($val);
172 like($res, qr/use warnings/,
173 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
176 my $x=sub { ++$q,++$p };
178 eval <<EOFCODE and test($x);
182 use warnings::register;
187 # Exotic sub declarations
188 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
189 $a =~ s/-e syntax OK\n//g;
190 is($a, <<'EOCODG', "sub :::: and sub ::::::");
200 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
201 $a =~ s/-e syntax OK\n//g;
202 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
211 my $code = <<"EOCODE";
213 our \$\x{1e1f}\x{14d}\x{14d};
217 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
218 s/$ \n//x for $deparsed, $code;
219 is $deparsed, $code, 'our $funny_Unicode_chars';
224 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
225 $a =~ s/-e syntax OK\n//g;
226 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
228 *CORE::GLOBAL::require = sub {
237 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
238 like($a, qr/-e syntax OK/,
239 "Deparse does not hang when traversing stash circularities");
243 is($deparse->coderef2text(sub{ print "foo@{]}" }),
246 }>, 'curly around to interpolate "@{]}"');
247 is($deparse->coderef2text(sub{ print "foo@{-}" }),
250 }>, 'no need to curly around to interpolate "@-"');
252 # Strict hints in %^H are mercilessly suppressed
254 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
255 unlike($a, qr/BEGIN/,
256 "Deparse does not emit strict hh hints");
258 # ambient_pragmas should not mess with strict settings.
260 skip "requires 5.11", 1 unless $] >= 5.011;
263 # Clear out all hints
266 new B::Deparse -> ambient_pragmas(strict => 'all');
268 use 5.011; # should enable strict
269 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
270 'ambient_pragmas do not mess with compiling scope';
274 # multiple statements on format lines
275 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
276 $a =~ s/-e syntax OK\n//g;
277 is($a, <<'EOCODH', 'multiple statements on format lines');
284 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
285 prog => "format =\n\@\n\$;\n.\n"),
286 <<'EOCODM', '$; on format line';
293 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
294 prog => "format =\n\@\n\$foo\n.\n"),
295 <<'EOCODM', 'formats with -l';
302 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
303 prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
304 <<'EOCODN', 'formats nested inside blocks';
315 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
316 .qq` my sub format; CORE::format =" -e. 2>&1`;
317 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
319 # literal big chars under 'use utf8'
320 is($deparse->coderef2text(sub{ use utf8; /€/; }),
326 # STDERR when deparsing sub calls
327 # For a short while the output included 'While deparsing'
328 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
329 $a =~ s/-e syntax OK\n//g;
330 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
334 # Sub calls compiled before importation
335 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
338 Test::More::->import;
342 'sub calls compiled before importation of prototype subs';
344 # [perl #121050] Prototypes with whitespace
345 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
347 sub _121050(\$ \$) { }
349 sub _121050empty( ) {}
350 () = _121050empty() + 1;
352 <<'EOCODP', '[perl #121050] prototypes with whitespace';
353 sub _121050 (\$ \$) {
357 sub _121050empty ( ) {
360 () = _121050empty + 1;
364 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
365 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
366 like($a, qr/my sub no;\nCORE::no less;/,
367 'CORE::no after my sub no');
370 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
371 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
372 like($a, qr/my sub use;\nCORE::use less;/,
373 'CORE::use after my sub use');
376 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
377 .qq`"use feature q|:all|; my sub __DATA__; `
378 .qq`CORE::__DATA__" 2>&1`;
379 like($a, qr/my sub __DATA__;\n.*\nCORE::__DATA__/s,
380 'CORE::__DATA__ after my sub __DATA__');
383 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
384 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
385 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
386 prog => 'sub f($); sub f($){}'),
387 qr/sub f\s*\(\$\)\s*\{\s*\}/,
388 'predeclared prototyped subs';
389 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
390 prog => 'use Scalar::Util q-weaken-;
392 BEGIN { weaken($_=\$::{f}) }'),
393 qr/sub f\s*\(\$\)\s*;/,
394 'prototyped stub with weak reference to the stash entry';
395 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
396 prog => 'sub f () { 42 }'),
397 qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
398 'constant perl sub declaration';
402 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
416 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
417 $a =~ s/-e syntax OK\n//g;
418 is($a, <<'EOCODJ', 'BEGIN blocks');
438 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
447 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
464 # BEGIN blocks should not be called __ANON__
465 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
466 prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
467 qr/sub BEGIN/, 'anonymised BEGIN';
470 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
471 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
472 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
473 use constant ('FOO', do {
480 # BEGIN blocks inside predeclared subs
481 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
485 sub run_tests { BEGIN { } die }'),
486 qr/sub run_tests \{\s*sub BEGIN/,
487 'BEGIN block inside predeclared sub';
489 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
490 prog => 'package foo; use overload qr=>sub{}'),
491 qr/package foo;\s*use overload/,
494 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
495 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
496 qr/^sub main::f \{/m,
497 'sub decl when lex sub is in scope';
499 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
500 prog => 'sub foo{foo()}'),
501 qr/^sub foo \{\s+foo\(\)/m,
504 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
505 prog => '$x =~ (1?/$a/:0)'),
506 '$x =~ ($_ =~ /$a/);'."\n",
507 '$foo =~ <branch-folded match> under taint mode';
509 unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
510 prog => 'BEGIN { undef &foo }'),
511 qr'Use of uninitialized value',
512 'no warnings for undefined sub';
514 done_testing($tests);
517 # TODO [perl #120950] This succeeds when run a 2nd time
521 # y/uni/code/ [perl #120950] This 2nd instance succeeds
527 # Constants in a block
528 # CONTEXT no warnings;
534 # List of constants in void context
535 # CONTEXT no warnings;
542 # Lexical and simple arithmetic
544 ++$test and $test /= 2;
547 $test /= 2 if ++$test;
552 # Assignment to list x
553 ((undef) x 3) = undef;
557 my $test = sub : lvalue {
565 my $test = sub : method {
571 # anonsub attrs at statement start
572 my $x = do { +sub : lvalue { my $y; } };
573 my $z = do { foo: +sub : method { my $a; } };
575 # block with continue
583 # lexical and package scalars
587 # lexical and package arrays
592 # lexical and package hashes
597 our($foo, $bar, $baz);
599 # CONTEXT { package Dog } use feature "state";
600 # variables with declared classes
610 my Dog ($foo, @bar, %baz);
611 our Dog ($phoo, @barr, %bazz);
612 state Dog ($fough, @barre, %bazze);
616 local our($rhu, $barb);
620 $_ .= <ARGV> . <$foo>;
628 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
632 # TODO ? ord("A") != 65 && "EBCDIC"
633 my $baz = "B\366\x{100}";
634 my $bba = qr/B\366\x{100}/;
639 s/x/complex_expression();/e;
654 # 2 arguments in a 3 argument for
655 for (my $i = 0; $i < 2;) {
660 for (my $i = 0; $i < 2; ++$i) {
664 # 3 argument for again
665 for (my $i = 0; $i < 2; ++$i) {
669 # 3-argument for with inverted condition
670 for (my $i; not $i;) {
673 for (my $i; not $i; ++$i) {
676 for (my $a; not +($1 || 2) ** 2;) {
679 Something_to_put_the_loop_in_void_context();
683 while ($i) { my $z = 1; } continue { $i = 99; }
686 foreach my $i (1, 2) {
691 # foreach with my under -p
704 foreach my $i (1, 2) {
709 foreach our $i (1, 2) {
713 # foreach with my and our
715 foreach our $i (1, 2) {
720 # CONTEXT use feature "state";
721 foreach state $i (1, 2) {
725 # foreach with sub call
726 foreach $_ (hcaerof()) {
732 print reverse sort(@x);
736 print((sort {$b cmp $a} @x));
738 # reverse sort with block
740 print((reverse sort {$b <=> $a} @x));
744 print $_ foreach (reverse @a);
746 # foreach reverse (not inplace)
748 print $_ foreach (reverse 1, 2..5);
752 @ary = split(' ', 'foo', 0);
755 our @array = split(//, 'foo', 0);
758 my @array = split(//, 'foo', 0);
764 do { my $x = 1; $x };
766 # <20061012113037.GJ25805@c4.convolution.nl>
785 sub foo {} foo & & & foo;
790 # variables as method names
793 'Foo'->$bar('orz') = 'a stranger stranger than before';
795 # constants as method names
798 # constants as method names without ()
801 # [perl #47359] "indirect" method call notation
805 foo{@bar}1 xor foo();
808 (foo { @bar } 1)->foo;
809 (foo { @bar } 1), foo();
810 foo { @bar } 1 xor foo();
812 # indirops with blocks
814 print {*STDOUT;} 'foo';
815 printf {*STDOUT;} 'foo';
816 say {*STDOUT;} 'foo';
817 system {'foo';} '-foo';
818 exec {'foo';} '-foo';
820 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
821 # CONTEXT use feature ':5.10';
825 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
826 # CONTEXT use 5.10.0;
827 # say in the context of use 5.10.0
830 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
831 # say with use 5.10.0
839 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
840 # say with use feature ':5.10';
844 use feature 'say', 'state', 'switch';
847 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
848 # CONTEXT use feature ':5.10';
849 # say with use 5.10.0 in the context of use feature
857 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
858 # CONTEXT use 5.10.0;
859 # say with use feature ':5.10' in the context of use 5.10.0
865 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
866 # CONTEXT use feature ':5.15';
870 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
871 # CONTEXT use 5.15.0;
872 # __SUB__ in the context of use 5.15.0
875 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
876 # __SUB__ with use 5.15.0
884 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
885 # __SUB__ with use feature ':5.15';
889 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
892 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
893 # CONTEXT use feature ':5.15';
894 # __SUB__ with use 5.15.0 in the context of use feature
902 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
903 # CONTEXT use 5.15.0;
904 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
910 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
911 # CONTEXT use feature ':5.10';
915 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
916 # CONTEXT use feature ':5.10';
917 # state var assignment
919 my $y = (state $x = 42);
922 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
923 # CONTEXT use feature ':5.10';
924 # state vars in anonymous subroutines
931 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
936 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
937 # keys @array; values @array
938 keys @$a if keys @ARGV;
939 values @ARGV if values @$a;
941 # Anonymous arrays and hashes, and references to them
947 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
948 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
949 # implicit smartmatch in given/when
951 when ('bar') { continue; }
952 when ($_ ~~ 'quux') { continue; }
956 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
959 elsif ($a and $b) { x(); }
960 elsif ($a or $b) { x(); }
963 # interpolation in regexps
967 # TODO new undocumented cpan-bug #33708
971 # TODO hash constants not yet fixed
973 use constant H => { "#" => 1 }; H->{"#"}
975 # TODO optimized away 0 not yet fixed
977 foreach my $i (@_) { 0 }
979 # tests with not, not optimized
982 x() if not $a and $b;
983 x() if $a and not $b;
984 x() unless not $a and $b;
985 x() unless $a and not $b;
988 x() unless not $a or $b;
989 x() unless $a or not $b;
990 x() if $a and not $b and $c;
991 x() if not $a and $b and not $c;
992 x() unless $a and not $b and $c;
993 x() unless not $a and $b and not $c;
994 x() if $a or not $b or $c;
995 x() if not $a or $b or not $c;
996 x() unless $a or not $b or $c;
997 x() unless not $a or $b or not $c;
999 # tests with not, optimized
1003 x() if not $a and not $b;
1004 x() unless not $a and not $b;
1005 x() if not $a or not $b;
1006 x() unless not $a or not $b;
1007 x() if not $a and not $b and $c;
1008 x() unless not $a and not $b and $c;
1009 x() if not $a or not $b or $c;
1010 x() unless not $a or not $b or $c;
1011 x() if not $a and not $b and not $c;
1012 x() unless not $a and not $b and not $c;
1013 x() if not $a or not $b or not $c;
1014 x() unless not $a or not $b or not $c;
1015 x() unless not $a or not $b or not $c;
1020 x() unless $a or $b;
1022 x() unless $a and $b;
1024 x() if not $a || $b and $c;
1025 x() unless not $a || $b and $c;
1026 x() if not $a && $b or $c;
1027 x() unless not $a && $b or $c;
1028 x() unless $a or $b or $c;
1029 x() if $a or $b or $c;
1030 x() unless $a and $b and $c;
1031 x() if $a and $b and $c;
1032 x() unless not $a && $b && $c;
1034 # tests that should be constant folded
1038 x() if GLIPP && GLIPP;
1039 x() if !GLIPP || GLIPP;
1040 x() if do { GLIPP };
1041 x() if do { no warnings 'void'; 5; GLIPP };
1042 x() if do { !GLIPP };
1043 if (GLIPP) { x() } else { z() }
1044 if (!GLIPP) { x() } else { z() }
1045 if (GLIPP) { x() } elsif (GLIPP) { z() }
1046 if (!GLIPP) { x() } elsif (GLIPP) { z() }
1047 if (GLIPP) { x() } elsif (!GLIPP) { z() }
1048 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1049 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1050 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1051 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1085 # TODO constant deparsing has been backed out for 5.12
1086 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1087 # tests that shouldn't be constant folded
1088 # It might be fundamentally impossible to make this work on ithreads, in which
1089 # case the TODO should become a SKIP
1091 if ($a == 1) { x() } elsif ($b == 2) { z() }
1092 if (do { foo(); GLIPP }) { x() }
1093 if (do { $a++; GLIPP }) { x() }
1096 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1097 if (do { foo(); GLIPP }) { x(); }
1098 if (do { ++$a; GLIPP }) { x(); }
1100 # TODO constant deparsing has been backed out for 5.12
1101 # tests for deparsing constants
1104 # TODO constant deparsing has been backed out for 5.12
1105 # tests for deparsing imported constants
1108 # TODO constant deparsing has been backed out for 5.12
1109 # tests for deparsing re-exported constants
1112 # TODO constant deparsing has been backed out for 5.12
1113 # tests for deparsing imported constants that got deleted from the original namespace
1116 # TODO constant deparsing has been backed out for 5.12
1117 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1118 # tests for deparsing constants which got turned into full typeglobs
1119 # It might be fundamentally impossible to make this work on ithreads, in which
1120 # case the TODO should become a SKIP
1122 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1125 # TODO constant deparsing has been backed out for 5.12
1126 # tests for deparsing of blessed constant with overloaded numification
1127 warn OVERLOADED_NUMIFICATION;
1141 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1142 # subsets of warnings
1143 no warnings 'deprecated';
1146 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1162 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1163 # := treated as an empty attribute list
1170 # : = empty attribute list
1189 # #71870 Use of uninitialized value in bitwise and B::Deparse
1191 @a = split(/foo/, $s, 0);
1193 @a = split(/$r/, $s, 0);
1196 # package declaration before label
1202 # shift optimisation
1207 # shift optimisation
1210 # shift optimisation
1215 # shift optimisation
1219 "foo" =~ (1 ? /foo/ : /bar/);
1220 "foo" =~ (1 ? y/foo// : /bar/);
1221 "foo" =~ (1 ? y/foo//r : /bar/);
1222 "foo" =~ (1 ? s/foo// : /bar/);
1224 'foo' =~ ($_ =~ /foo/);
1225 'foo' =~ ($_ =~ tr/fo//);
1226 'foo' =~ ($_ =~ tr/fo//r);
1227 'foo' =~ ($_ =~ s/foo//);
1229 # The fix for [perl #20444] broke this.
1232 # [perl #81424] match against aelemfast_lex
1248 use constant QR_CONSTANT => qr/a/soupmix;
1257 # [perl #91318] /regexp/applaud
1258 print /a/a, s/b/c/a;
1259 print /a/aa, s/b/c/aa;
1260 print /a/p, s/b/c/p;
1261 print /a/l, s/b/c/l;
1262 print /a/u, s/b/c/u;
1264 use feature "unicode_strings";
1265 print /a/d, s/b/c/d;
1269 print /a/d, s/b/c/d;
1273 print /a/d, s/b/c/d;
1276 print /a/a, s/b/c/a;
1277 print /a/aa, s/b/c/aa;
1278 print /a/p, s/b/c/p;
1279 print /a/l, s/b/c/l;
1280 print /a/u, s/b/c/u;
1282 use feature 'unicode_strings';
1283 print /a/d, s/b/c/d;
1286 BEGIN { $^H{'reflags'} = '0';
1287 $^H{'reflags_charset'} = '2'; }
1288 print /a/d, s/b/c/d;
1292 use feature ':5.12';
1293 print /a/d, s/b/c/d;
1296 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1300 "" =~ /a(?{ print q|
1303 '' =~ /a(?{ print "\n"; })/;
1306 $_ = qr/(??{<<END})/
1311 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1313 # More regexp code block madness
1320 /a(??{ die $b; })a/;
1321 /$a(??{ die $b; })/;
1322 /@a(??{ die $b; })/;
1324 qr/a(?{ die $b; })a/;
1325 qr/$a(?{ die $b; })/;
1326 qr/@a(?{ die $b; })/;
1327 qr/(??{ die $b; })/;
1328 qr/a(??{ die $b; })a/;
1329 qr/$a(??{ die $b; })/;
1330 qr/@a(??{ die $b; })/;
1332 s/a(?{ die $b; })a//;
1333 s/$a(?{ die $b; })//;
1334 s/@a(?{ die $b; })//;
1335 s/(??{ die $b; })//;
1336 s/a(??{ die $b; })a//;
1337 s/$a(??{ die $b; })//;
1338 s/@a(??{ die $b; })//;
1340 # /(?x)<newline><tab>/
1345 tr/a/b/r + $a =~ tr/p/q/r;
1347 # y///d in list [perl #119815]
1354 # CONTEXT no warnings 'experimental::autoderef';
1359 # readpipe with complex expression
1365 # aelemfast for a lexical
1369 # feature features without feature
1370 # CONTEXT no warnings 'experimental::smartmatch';
1385 # feature features when feature has been disabled by use VERSION
1386 # CONTEXT no warnings 'experimental::smartmatch';
1387 use feature (sprintf(":%vd", $^V));
1415 # (the above test with CONTEXT, and the output is equivalent but different)
1416 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1417 # feature features when feature has been disabled by use VERSION
1418 use feature (sprintf(":%vd", $^V));
1434 use feature ':default';
1448 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1449 # lexical subroutines and keywords of the same name
1450 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1474 CORE::default { die; }
1475 CORE::if ($1) { die; }
1476 CORE::if ($1) { die; }
1477 CORE::elsif ($1) { die; }
1479 CORE::for (die; $1; die) { die; }
1480 CORE::foreach $_ (1 .. 10) { die; }
1481 die CORE::foreach (1);
1482 CORE::given ($1) { die; }
1487 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1490 () = CORE::sub { die; } ;
1492 CORE::unless ($1) { die; }
1493 CORE::until ($1) { die; }
1496 CORE::when ($1 ~~ $2) { die; }
1497 CORE::while ($1) { die; }
1501 use feature 'current_sub', 'evalbytes';
1507 no feature 'unicode_strings';
1510 use feature 'current_sub', 'evalbytes';
1513 use feature ':default';
1516 use feature ':5.12';
1518 no feature 'unicode_strings';
1521 # $#- $#+ $#{%} etc.
1523 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1524 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1525 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1526 @x = ($#{;}, $#{:}, $#{1});
1529 # It's a known TODO that warnings are deparsed as bits, not textually.
1533 # [perl #86060] $( $| $) in regexps need braces
1544 # sort(foo(bar)) is interpreted as sort &foo(bar)
1545 # sort foo(bar) is interpreted as sort foo bar
1546 # parentheses are not optional in this case
1547 print sort(foo('bar'));
1549 print sort(foo('bar'));
1552 substr(my $a, 0, 0) = (foo(), bar());
1555 # This following line works around an unfixed bug that we are not trying to
1557 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1559 BEGIN { $^H{'foo'} = undef; }
1561 BEGIN { $^H{'bar'} = undef; }
1563 BEGIN { $^H{'baz'} = undef; }
1571 BEGIN { $^H{q[']} = '('; }
1574 # This following line works around an unfixed bug that we are not trying to
1576 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1577 # hint hash changes that serialise the same way with sort %hh
1578 BEGIN { $^H{'a'} = 'b'; }
1580 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1585 # [perl #47361] do({}) and do +{} (variants of do-file)
1599 # [perl #77096] functions that do not follow the llafr
1600 () = (return 1) + time;
1601 () = (return ($1 + $2) * $3) + time;
1602 () = (return ($a xor $b)) + time;
1603 () = (do 'file') + time;
1604 () = (do ($1 + $2) * $3) + time;
1605 () = (do ($1 xor $2)) + time;
1607 () = (require 'foo') + 3;
1608 () = (require foo) + 3;
1609 () = (CORE::dump 1) + 3;
1620 # require(foo()) and do(foo())
1632 # [perl #97476] not() *does* follow the llafr
1633 $_ = ($a xor not +($1 || 2) ** 2);
1635 # Precedence conundrums with argument-less function calls
1643 # loopexes have assignment prec
1644 () = (CORE::dump a) | 'b';
1645 () = (goto a) | 'b';
1646 () = (last a) | 'b';
1647 () = (next a) | 'b';
1648 () = (redo a) | 'b';
1650 # [perl #63558] open local(*FH)
1652 pipe local *FH, local *FH;
1654 # [perl #91416] open "string"
1667 () = 'open'->[0]; #aelemfast
1672 () = 'open'->[$_]; #aelem
1677 () = 'open'->{0}; #helem
1698 () = 'a::]b'->{'0'};
1700 # [perl #74740] -(f()) vs -f()
1706 #[perl #30504] foreach-my postfix/prefix difference
1707 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1708 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1709 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1711 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1712 foreach $_ (my($foo2, $bar2, $baz2)) {
1715 foreach my $i (my($foo3, $bar3, $baz3)) {
1719 #[perl #108224] foreach with continue block
1720 foreach (1 .. 3) { print } continue { print "\n" }
1721 foreach (1 .. 3) { } continue { }
1722 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1723 foreach my $i (1 .. 3) { } continue { }
1725 foreach $_ (1 .. 3) {
1731 foreach $_ (1 .. 3) {
1737 foreach my $i (1 .. 3) {
1743 foreach my $i (1 .. 3) {
1764 # 'my' works with padrange op
1771 ($m3, $m4) = (1, 2);
1773 my($m5, $m6) = (1, 2);
1774 my($m7, undef, $m8) = (1, 2, 3);
1775 @z = ($m7, undef, $m8);
1776 ($m7, undef, $m8) = (1, 2, 3);
1778 # 'our/local' works with padrange op
1789 ($o3, $o4) = (1, 2);
1790 local($o3, $o4) = (1, 2);
1792 @z = local($o3, $o4);
1793 our($o5, $o6) = (1, 2);
1794 our($o7, undef, $o8) = (1, 2, 3);
1795 @z = ($o7, undef, $o8);
1796 @z = local($o7, undef, $o8);
1797 ($o7, undef, $o8) = (1, 2, 3);
1798 local($o7, undef, $o8) = (1, 2, 3);
1800 # 'state' works with padrange op
1801 # CONTEXT no strict; use feature 'state';
1808 ($s3, $s4) = (1, 2);
1810 # assignment of state lists isn't implemented yet
1811 #state($s5, $s6) = (1, 2);
1812 #state($s7, undef, $s8) = (1, 2, 3);
1813 #@z = ($s7, undef, $s8);
1814 ($s7, undef, $s8) = (1, 2, 3);
1816 # anon arrays with padrange
1821 # slices with padrange
1827 # binops with padrange
1841 my($a, $b, $c, $d, @e);
1846 @e = ($a, $b, $c) x $d;
1850 my($a, $b, $c) = @_;
1852 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1853 # lexical subroutine
1854 use feature 'lexical_subs';
1855 no warnings "experimental::lexical_subs";
1859 use feature 'lexical_subs';
1860 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
1862 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1865 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1868 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1869 # lexical "state" subroutine
1870 use feature 'state', 'lexical_subs';
1871 no warnings 'experimental::lexical_subs';
1875 use feature 'lexical_subs';
1876 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
1878 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1879 use feature 'state';
1882 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1883 use feature 'state';
1886 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1887 # lexical subroutine scoping
1888 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1906 # self-referential lexical subroutine
1907 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
1914 # lexical subroutine with outer declaration and inner definition
1915 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1923 # Elements of %# should not be confused with $#{ array }
1932 # Ampersand calls and scalar context
1939 &foo(scalar bar(), scalar baz());
1941 # coderef2text and prototyped sub calls [perl #123435]
1944 # prototypes with unary precedence
1947 sub optdollar(;$) {}
1948 sub optoptdollar(;;$) {}
1951 sub optoptsplat(;;*) {}
1954 sub optoptbar(;;_) {}
1957 sub optoptplus(;;+) {}
1960 sub optoptwack(;;\$) {}
1961 sub wackbrack(\[$]) {}
1962 sub optwackbrack(;\[$]) {}
1963 sub optoptwackbrack(;;\[$]) {}
1966 optoptdollar($a < $b);
1967 splat($a < $b); # Some of these deparse with ‘&’; if that changes, just
1968 optsplat($a < $b); # change the tests.
1969 optoptsplat($a < $b);
1975 optoptplus($a < $b);
1978 optoptwack($a = $b);
1980 optwackbrack($a = $b);
1981 optoptwackbrack($a = $b);
1986 optoptdollar($a < $b);
1989 &optoptsplat($a < $b);
1995 &optoptplus($a < $b);
1997 &optwack(\($a = $b));
1998 &optoptwack(\($a = $b));
1999 &wackbrack(\($a = $b));
2000 &optwackbrack(\($a = $b));
2001 &optoptwackbrack(\($a = $b));
2003 # ensure aelemfast works in the range -128..127 and that there's no
2007 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2008 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2010 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2011 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
2013 # 'm' must be preserved in m??
2016 # \(@array) and \(..., (@array), ...)
2017 my(@array, %hash, @a, @b, %c, %d);
2020 () = \(@a, (@b), (%c), %d);
2021 () = \(@Foo::array);
2023 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
2025 # subs synonymous with keywords
2029 use feature 'state';
2033 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
2045 \($x, my $a) = @{[\$x, \$x]};
2046 (\$x, \my $b) = @{[\$x, \$x]};
2058 \local($a[1]) = foo();
2061 \local @a[0,1] = (\$a)x2;
2068 \local($h{b}) = \$x;
2069 \@h{'a','b'} = foo();
2071 \local @h{'a','b'} = (\$x)x2;
2107 (\$_, $_) = \(1, 2);
2108 $_ == 3 ? \$_ : $_ = \3;
2109 $_ == 3 ? \$_ : \$x = \3;
2110 \($_ == 3 ? $_ : $x) = \3;
2111 for \my $topic (\$1, \$2) {
2114 for \state $topic (\$1, \$2) {
2117 for \our $topic (\$1, \$2) {
2120 for \$_ (\$1, \$2) {
2123 for \my @a ([1,2], [3,4]) {
2126 for \state @a ([1,2], [3,4]) {
2129 for \our @a ([1,2], [3,4]) {
2132 for \@_ ([1,2], [3,4]) {
2135 for \my %a ({5,6}, {7,8}) {
2138 for \our %a ({5,6}, {7,8}) {
2141 for \state %a ({5,6}, {7,8}) {
2144 for \%_ ({5,6}, {7,8}) {
2149 for \&a (sub { 9; }, sub { 10; }) {
2153 for \&a (sub { 9; }, sub { 10; }) {
2168 (\$x, \my $a) = @{[\$x, \$x];};
2169 (\$x, \my $b) = @{[\$x, \$x];};
2181 (\local $a[1]) = foo();
2182 (\@a[0, 1]) = foo();
2183 (\@a[2, 3]) = foo();
2184 (\local @a[0, 1]) = (\$a) x 2;
2190 \local $h{'a'} = \$x;
2191 (\local $h{'b'}) = \$x;
2192 (\@h{'a', 'b'}) = foo();
2193 (\@h{2, 3}) = foo();
2194 (\local @h{'a', 'b'}) = (\$x) x 2;
2220 (\our %zz) = {1, 2};
2230 (\$_, $_) = \(1, 2);
2231 $_ == 3 ? \$_ : $_ = \3;
2232 $_ == 3 ? \$_ : \$x = \3;
2233 ($_ == 3 ? \$_ : \$x) = \3;
2234 foreach \my $topic (\$1, \$2) {
2237 foreach \state $topic (\$1, \$2) {
2240 foreach \our $topic (\$1, \$2) {
2243 foreach \$_ (\$1, \$2) {
2246 foreach \my @a ([1, 2], [3, 4]) {
2249 foreach \state @a ([1, 2], [3, 4]) {
2252 foreach \our @a ([1, 2], [3, 4]) {
2255 foreach \@_ ([1, 2], [3, 4]) {
2258 foreach \my %a ({5, 6}, {7, 8}) {
2261 foreach \our %a ({5, 6}, {7, 8}) {
2264 foreach \state %a ({5, 6}, {7, 8}) {
2267 foreach \%_ ({5, 6}, {7, 8}) {
2272 foreach \&a (sub { 9; } , sub { 10; } ) {
2276 foreach \&a (sub { 9; } , sub { 10; } ) {
2285 $_ = join('???', pos $_);
2291 # my @a; exists $a[0]
2299 # my @a; delete $a[0]
2314 # my $x = "$h{foo}";
2316 my $x = "$h{'foo'}";
2318 # weird constant hash key
2320 my $x = $h{"\000\t\x{100}"};
2322 # multideref and packages
2324 my(%bar) = ('a', 'b');
2326 $bar{'k'} = $bar[200];
2327 $main::bar{'k'} = $main::bar[200];
2328 $foo::bar{'k'} = $foo::bar[200];
2330 $bar{'k'} = $bar[200];
2331 $main::bar{'k'} = $main::bar[200];
2332 $foo::bar{'k'} = $foo::bar[200];
2335 my(%bar) = ('a', 'b');
2337 $bar{'k'} = $bar[200];
2338 $main::bar{'k'} = $main::bar[200];
2339 $foo::bar{'k'} = $bar[200];
2341 $bar{'k'} = $foo::bar[200];
2342 $main::bar{'k'} = $main::bar[200];
2343 $foo::bar{'k'} = $foo::bar[200];
2345 # multideref and local
2347 local $h{'foo'}[0] = 1;
2349 # multideref and exists
2351 my $e = exists $h{'foo'}[$i];
2353 # multideref and delete
2355 my $e = delete $h{'foo'}[$i];
2357 # multideref with leading expression
2359 my $x = ($r // [])->{'foo'}[0];
2361 # multideref with complex middle index
2363 my $x = $h{'foo'}[$i + $j]{$k};