This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: better handle BEGIN { use_ok() }
authorDavid Mitchell <davem@iabyn.com>
Fri, 24 Feb 2017 16:11:34 +0000 (16:11 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 5 Jun 2017 11:52:18 +0000 (12:52 +0100)
Commit v5.25.3-111-g8071973 added handling for the bad deparsing of

    BEGIN { use_ok() }

Basically by stripping out the bad code text *after* it had been deparsed.
However, this didn't catch all bad cases - in particular, where #line
directives got added:

    use Socket (@{
    #line 10 "t/000_load.t"
    $args[0];});

Under TEST -deparse, this fixes the following unexpectedly failing
scripts:

    ../cpan/Term-ANSIColor/t/taint/basic.t
    ../cpan/autodie/t/00-load.t
    ../dist/Locale-Maketext/t/01_about_verbose.t
    ../dist/Locale-Maketext/t/10_make.t
    ../dist/Locale-Maketext/t/20_get.t
    ../dist/Locale-Maketext/t/40_super.t
    ../dist/Locale-Maketext/t/50_super.t
    ../dist/Locale-Maketext/t/60_super.t
    ../dist/Locale-Maketext/t/70_fail_auto.t
    ../dist/Locale-Maketext/t/91_backslash.t
    ../ext/File-Glob/t/taint.t
    ../ext/Hash-Util/t/Util.t
    ../lib/DB.t
    ../lib/File/Basename.t

and fixes the following expected-to-fail script:

    ../dist/Net-Ping/t/000_load.t

Porting/deparse-skips.txt
lib/B/Deparse.pm

index 2a1473f..0d386db 100644 (file)
@@ -32,7 +32,6 @@
 __DEPARSE_FAILURES__
 
 ../cpan/Scalar-List-Utils/t/proto.t
-../cpan/Term-ANSIColor/t/taint/basic.t
 ../cpan/autodie/t/internal.t
 ../cpan/AutoLoader/t/01AutoLoader.t
 ../cpan/CGI/t/utf8.t
@@ -48,7 +47,6 @@ __DEPARSE_FAILURES__
 ../cpan/Test-Simple/t/plan_bad.t
 ../cpan/Test-Simple/t/subtest/line_numbers.t
 ../cpan/Test-Simple/t/subtest/predicate.t
-../cpan/autodie/t/00-load.t
 ../cpan/autodie/t/autodie.t
 ../cpan/autodie/t/blog_hints.t
 ../cpan/autodie/t/caller.t
@@ -91,14 +89,6 @@ __DEPARSE_FAILURES__
 ../dist/Exporter/t/Exporter.t
 ../dist/Filter-Simple/t/data.t
 ../dist/IO/t/io_sel.t
-../dist/Locale-Maketext/t/01_about_verbose.t
-../dist/Locale-Maketext/t/10_make.t
-../dist/Locale-Maketext/t/20_get.t
-../dist/Locale-Maketext/t/40_super.t
-../dist/Locale-Maketext/t/50_super.t
-../dist/Locale-Maketext/t/60_super.t
-../dist/Locale-Maketext/t/70_fail_auto.t
-../dist/Locale-Maketext/t/91_backslash.t
 ../dist/Math-BigInt/t/const_mbf.t
 ../dist/Math-BigInt/t/constant.t
 ../dist/PathTools/t/cwd.t
@@ -126,8 +116,6 @@ __DEPARSE_FAILURES__
 ../ext/B/t/optree_samples.t
 ../ext/B/t/xref.t
 ../ext/Devel-Peek/t/Peek.t
-../ext/File-Glob/t/taint.t
-../ext/Hash-Util/t/Util.t
 ../ext/IPC-Open3/t/IPC-Open2.t
 ../ext/IPC-Open3/t/IPC-Open3.t
 ../ext/XS-APItest/t/autoload.t
@@ -136,9 +124,7 @@ __DEPARSE_FAILURES__
 ../ext/XS-APItest/t/cleanup.t
 ../ext/XS-APItest/t/fetch_pad_names.t
 ../ext/XS-APItest/t/svpeek.t
-../lib/DB.t
 ../lib/English.t
-../lib/File/Basename.t
 ../lib/charnames.t
 ../lib/overload.t
 base/lex.t                # checks regexp stringification
index bf45482..5f0afa2 100644 (file)
@@ -574,7 +574,17 @@ sub next_todo {
                 #  makes use of a lexical var that's not in scope.
                 #  So strip it out.
                 return $pragmata
-                            if $use_dec =~ /^use \S+ \(@\{\$args\[0\];\}\);/;
+                        if $use_dec =~
+                            m/
+                                \A
+                                use \s \S+ \s \(\@\{
+                                (
+                                    \s*\#line\ \d+\ \".*"\s*
+                                )?
+                                \$args\[0\];\}\);
+                                \n
+                                \Z
+                            /x;
 
                $use_dec =~ s/^(use|no)\b/$self->keyword($1)/e;
            }