diff --git a/Changes b/Changes index 8a821c7..5a8178d 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Revision history for perl-generators. -1.01 Tue May 22 2014 +1.02 Fri Dec 12 2014 +- Fix BZ#1172716 - update regex to properly match the module name +- Update tests suite +- Update the steps to get package version + +1.01 Tue Oct 21 2014 - Fixed BZ#1160263 - do not catch numeric substring in the variable name for VERSION - Update requires generator to: diff --git a/Makefile.PL b/Makefile.PL index 6b7d30b..39ab562 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -5,7 +5,7 @@ use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'generators', - 'VERSION' => '1.01', + 'VERSION' => '1.02', 'AUTHOR' => 'Jitka Plesnikova ', 'LICENSE' => 'gpl', 'EXE_FILES' => [ ( glob 'bin/*' ) ], diff --git a/TODO b/TODO index 5bfda40..af74109 100644 --- a/TODO +++ b/TODO @@ -17,6 +17,5 @@ no File::Path; # Does not find modules defined at 'eval' eval{ require File::Spec; 1} or die; -# Does not support multi-line statements -use overload - + = \+ +https://metacpan.org/source/ETHER/Module-Runtime-Conflicts-0.001/lib/Module/Runtime/Conflicts.pm +BEGIN { use Test::More } diff --git a/bin/perl.prov b/bin/perl.prov index 1254ce3..baca33a 100755 --- a/bin/perl.prov +++ b/bin/perl.prov @@ -96,7 +96,7 @@ sub process_file { } if ($incomment || $inover) { - next; + next; } # skip the data section @@ -108,17 +108,18 @@ sub process_file { # package name so we report all namespaces except some common # false positives as if they were provided packages (really ugly). - if (m/^\s*package\s+([_:a-zA-Z0-9]+)\s*;/) { + if (m/^\s*package\s+([_:a-zA-Z0-9]+)\s*v?([0-9._]+)?\s*;/) { $package = $1; - undef $version; + $version = defined($2) ? $2 : undef; if ($package eq 'main') { undef $package; + undef $version; } else { # If $package already exists in the $require hash, it means # the package definition is broken up over multiple blocks. # In that case, don't stomp a previous $VERSION we might have # found. (See BZ#214496.) - $require{$package} = undef unless (exists $require{$package}); + $require{$package} = $version unless (exists $require{$package}); } } @@ -137,7 +138,7 @@ sub process_file { # or with the new "our" pragma you could (read will) see: # # our $VERSION = '1.00' - if ($package && m/^\s*(our\s+)?\$(\Q$package\E::)?VERSION\s*=\s*/) { + if ($package && m/^\s*(our\s+)?\$(\Q$package\E::)?VERSION\s*=[^=~>]\s*/) { # first see if the version string contains the string # '$Revision' this often causes bizarre strings and is the most @@ -145,7 +146,7 @@ sub process_file { if (m/\$Revision: (\d+[.0-9]+)/) { $version = $1; - } elsif (m/\b['"]?[v]?(\d+(?:\.[.0-9]+)?)(_\d*|[a-zA-Z]*)?['"]?\b/) { + } elsif (m/\b['"]?v?(\d+(?:\.[.0-9]+)?)(_\d*|[a-zA-Z]*)?['"]?\b/) { # look for a static number hard coded in the script diff --git a/bin/perl.req b/bin/perl.req index c92b792..3c848c7 100755 --- a/bin/perl.req +++ b/bin/perl.req @@ -155,16 +155,16 @@ sub process_file { (require|use)\s+(?!\{) # do not want 'do {' loops # quotes around name are always legal $begin_re?\s* - ([^)"'!|} \t#;]*?) - \s*$end_re?[\t; ] + ([\w:\.\/]+?) + \s*$end_re?[^\w]*?[\t; \n] # the syntax for 'use' allows version requirements - \s*($modver_re|)\s* + \s*($modver_re)?\s* # catch parameter like '-norequire,' - (-[\w,]+|)\s* + (-[\w,]+)?\s* # the latter part is for "use base qw(Foo)" and friends special case (?:$begin_re\s* ([^)\/"'\$!|}]*?) - \s*$end_re|['"][^'"]+['"]|) + \s*$end_re|['"][^'"]+['"]|)\s* /x) ) { my ($whitespace, $statement, $module, $version, $params, $list) = ($1, $2, $3, $4, $5, $6); diff --git a/t/01_basic.t b/t/01_basic.t index 9983c8b..8b1b4ef 100644 --- a/t/01_basic.t +++ b/t/01_basic.t @@ -1,9 +1,9 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 2; use Test::Simple; -my $files = "t/data/basic t/data/whitespace"; +my $files = "t/data/basic"; my @requires = qx(bin/perl.req $files); my @provides = qx(bin/perl.prov $files); @@ -12,38 +12,25 @@ my @provides = qx(bin/perl.prov $files); is(scalar(@provides), 0, 'No package is provided'); # -# Non-versioned modules requires -my @list_requires = ( "Alpha::One", "Alpha::Two", "Beta", "Gamma", - "Epsilon", "Eta", "Theta", "Iota", "Kappa", "Lambda"); +# Requires +my @expectedrequires = ( + "perl >= 1:5.6.1\n", + "perl >= 0:5.006_001\n", + "perl >= 1:5.010\n", + "perl(Alpha) >= 0.12\n", + "perl(Alpha::One)\n", + "perl(Alpha::Two)\n", + "perl(Beta)\n", + "perl(Epsilon)\n", + "perl(Eta)\n", + "perl(ExtUtils::MM_Unix)\n", + "perl(ExtUtils::MakeMaker)\n", + "perl(Gamma)\n", + "perl(Iota)\n", + "perl(Kappa)\n", + "perl(Lambda)\n", + "perl(Theta)\n", +); + +is_deeply([ sort @requires ], [ sort @expectedrequires ], "Only expected requires were found."); -foreach my $mod (@list_requires) { - ok(grep(/^perl\($mod\)$/,@requires), "'$mod' is required") -} - -# -# Versioned modules -ok(grep(/^perl\(Alpha\) >= 0.12$/, @requires), "'perl(Alpha) >= 0.12' is required"); - -# Perl version -foreach my $v ('1:5.6.1', '0:5.006_001', '1:5.010') { - ok(grep(/^perl >= $v$/, @requires), "'perl >= $v' is required"); -} - -# Should not be listed -ok(!grep(/^perl\(Alpha\)$/, @requires), "Unversion 'perl(Alpha)' is not required"); - -# TODO: Should recognize more than one 'use' or 'require' at one line -ok(!grep(/^perl\(Zeta\)$/, @requires), "'perl(Zeta)' is not required"); - -# 'use' prefixed by whitespace should be also find -ok(grep(/^perl\(Use::WhiteSpace\)/, @requires), "'perl(Use::WhiteSpace)' is required"); - -# TODO: Stop ignoring 'require' with whitespaces at the beginning -ok(!grep(/^perl\(Require::WhiteSpace\)/, @requires), "'perl(Require::WhiteSpace)' is required"); - -# 'use' does not accept module name with .pm -ok(!grep(/^perl\(Ignore\)/, @requires), "'perl(Ignore)' is not required"); - -# -# Check if expected amount of modules was found -is(scalar(@requires), scalar(@list_requires) + 5, "Expected amount of modules was found"); diff --git a/t/02_list.t b/t/02_list.t index 90d8b48..a4afb15 100644 --- a/t/02_list.t +++ b/t/02_list.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 2; my $file = "t/data/list"; my @requires = qx(bin/perl.req $file); @@ -11,24 +11,19 @@ my @provides = qx(bin/perl.prov $file); is(scalar(@provides), 0, 'No package is provided'); # -# Requiremets to be found -my @found = ("Alpha", "Beta", "Gamma", 'Delta', "Epsilon", - "Some::Crazy::Module", "Another::Crazy::Module", "aliased", "base", - "parent" +# Requires +my @expectedrequires = ( + "perl(Alpha)\n", + "perl(Beta)\n", + "perl(Gamma)\n", + "perl(Delta)\n", + "perl(Epsilon)\n", + "perl(Some::Crazy::Module)\n", + "perl(Another::Crazy::Module)\n", + "perl(aliased)\n", + "perl(base)\n", + "perl(parent)\n", + "perl(overload)\n", ); -foreach my $mod (@found) { - ok(grep(/^perl\($mod\)$/,@requires), "'$mod' is required") -} -# Requirements to be ignore -my @ignored = ("Zeta", "Iota", "ShorterName"); -foreach my $mod (@ignored) { - ok(!grep(/^perl\($mod\)$/,@requires), "'$mod' is not required") -} - -# TODO: Find multiple line use -ok(!grep(/^perl\(overload\)$/, @requires), "'perl(overload)' is not found"); - -# -# Check if expected amount of modules was found -is(scalar(@requires), scalar(@requires), "Expected amount of modules was found"); +is_deeply([ sort @requires ], [ sort @expectedrequires ], "Only expected requires were found."); diff --git a/t/03_anymoose.t b/t/03_anymoose.t index 3adadda..512153e 100644 --- a/t/03_anymoose.t +++ b/t/03_anymoose.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 2; my $file = "t/data/anymoose"; my @requires = qx(bin/perl.req $file); @@ -11,15 +11,11 @@ my @provides = qx(bin/perl.prov $file); is(scalar(@provides), 0, 'No package is provided'); # -# Requiremets to be found -ok(grep(/^perl\(Any::Moose\) >= 0.18$/,@requires), "'perl(Any::Moose) >= 0.18' is required"); -ok(grep(/^perl\(Mouse\)$/,@requires), "'perl(Mouse)' is required"); -ok(grep(/^perl\(Mouse::Role\)$/,@requires), "'perl(Mouse::Role)' is required"); +# Requires +my @expectedrequires = ( + "perl(Any::Moose) >= 0.18\n", + "perl(Mouse)\n", + "perl(Mouse::Role)\n", +); -# -# Requirements to be ignore -ok(!grep(/^perl\(Any::Moose\)$/,@requires), "Unversioned 'perl(Any::Moose)' is not found"); - -# -# Check if expected amount of modules was found -is(scalar(@requires), 3, "Expected amount of modules was found"); +is_deeply([ sort @requires ], [ sort @expectedrequires ], "Only expected requires were found."); diff --git a/t/04_provides.t b/t/04_provides.t index 2a636c9..37d2bb6 100644 --- a/t/04_provides.t +++ b/t/04_provides.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 20; +use Test::More tests => 2; my $file = "t/data/provides"; my @requires = qx(bin/perl.req $file); @@ -10,70 +10,28 @@ my @provides = qx(bin/perl.prov $file); # Requires is(scalar(@requires), 0, 'No module is required'); -# -# Provides to be found -ok(grep(/^perl\(Alpha\)$/, @provides), "'perl(Alpha)' is provided"); -ok(grep(/^perl\(Beta\) = 1.00$/, @provides), "'perl(Beta) = 1.00' is provided"); -ok(grep(/^perl\(Gamma\) = 2.00$/, @provides), "'perl(Gamma) = 2.00' is provided"); -ok(grep(/^perl\(Delta\) = 0.50$/, @provides), "'perl(Delta) = 0.50' is provided"); - -# BZ#1160263 -#package Test::Pod::No404s; -#$Test::Pod::No404s::VERSION = '0.02'; -ok(grep(/^perl\(Test::Pod::No404s\) = 0.02$/, @provides), "'perl(Test::Pod::No404s) = 0.02' is provided"); - -#package FindBin; -#our $VERSION = $VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)$/, @provides); -ok(grep(/^perl\(FindBin\) = 1.9$/, @provides), "'perl(FindBin) = 1.9' is provided"); - -#package ExtUtils::Install; -#$VERSION = substr q$Revision: 1.8 $, 10; -ok(grep(/^perl\(ExtUtils::Install\) = 1.8$/, @provides), "'perl(ExtUtils::Install) = 1.8' is provided"); - -#package CGI::Apache; -#$VERSION = (qw$Revision: 1.7 $)[1]; -ok(grep(/^perl\(CGI::Apache\) = 1.7$/, @provides), "'perl(CGI::Apache) = 1.7' is provided"); - -#package DynaLoader; -#$VERSION = $VERSION = "1.03"; # avoid typo warning -ok(grep(/^perl\(DynaLoader\) = 1.03$/, @provides), "'perl(DynaLoader) = 1.03' is provided"); - -#package Config::General; -#$Config::General::VERSION = 2.33; -ok(grep(/^perl\(Config::General\) = 2.33$/, @provides), "'perl(Config::General) = 2.33' is provided"); - -#package Alpha::Beta123; -#our $VERSION = $Alpha::Beta123::VERSION=1.23; -ok(grep(/^perl\(Alpha::Beta123\) = 1.23$/, @provides), "'perl(Alpha::Beta123) = 1.23' is provided"); - -#package Template; -#$Template::VERSION ="3.45"; -ok(grep(/^perl\(Template\) = 3.45$/, @provides), "'perl(Template) = 3.45' is provided"); - -#package Zeta; -#$VERSION = "1.01"; -#$VERSION = $VERSION + 0.05; -ok(grep(/^perl\(Zeta\) = 0.05$/, @provides), "'perl(Zeta) = 0.05' is provided"); - -#package Theta; -#$tmp = 1.56 -#$VERSION = $tmp; -ok(grep(/^perl\(Theta\)$/, @provides), "'perl(Theta)' is provided"); - -ok(grep(/^perl\(Iota\) = 1$/, @provides), "'perl(Iota) = 1' is provided"); - -# package Omega; -# $VERSION="9.87_65"; -ok(grep(/^perl\(Omega\) = 9.87$/, @provides), "'perl(Omega) = 9.87' is provided"); - -# package Test::Kwalitee::Extra; -# our $VERSION = 'v0.3.0'; -ok(grep(/^perl\(Test::Kwalitee::Extra\) = 0.3.0$/, @provides), "'perl(Test::Kwalitee::Extra) = 0.3.0' is provided"); - -# package XML::Grove; -# $VERSION = '0.46alpha'; -ok(grep(/^perl\(XML::Grove\) = 0.46$/, @provides), "'perl(XML::Grove) = 0.46' is provided"); - -# -# Check if expected amount of modules was found -is(scalar(@provides), 18, "Expected amount of modules was found"); +my @expectedprovides = ( + "perl(Alpha)\n", + "perl(Alpha::Beta123) = 1.23\n", + "perl(Beta) = 1.00\n", + "perl(CGI::Apache) = 1.7\n", + "perl(Config::General)\n", + "perl(Delta) = 0.50\n", + "perl(DynaLoader) = 1.03\n", + "perl(ExtUtils::Install) = 1.8\n", + "perl(ExtUtils::MM_Unix)\n", + "perl(FindBin) = 1.9\n", + "perl(Gamma) = 2.00\n", + "perl(Iota) = 1\n", + "perl(Kappa::Lambda) = 5.43\n", + "perl(Omega) = 9.87\n", + "perl(Template) = 3.45\n", + "perl(Test::Kwalitee::Extra) = 0.3.0\n", + "perl(Test::Pod::No404s) = 0.02\n", + "perl(Theta)\n", + "perl(XML::Grove) = 0.46\n", + "perl(Xi)\n", + "perl(Zeta) = 0.05\n", +); + +is_deeply([ sort @provides ], [ sort @expectedprovides ], "All expected provides were found."); diff --git a/t/05_whitespace.t b/t/05_whitespace.t index 90d8b48..0c34681 100644 --- a/t/05_whitespace.t +++ b/t/05_whitespace.t @@ -1,8 +1,8 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 2; -my $file = "t/data/list"; +my $file = "t/data/whitespace"; my @requires = qx(bin/perl.req $file); my @provides = qx(bin/perl.prov $file); @@ -11,24 +11,9 @@ my @provides = qx(bin/perl.prov $file); is(scalar(@provides), 0, 'No package is provided'); # -# Requiremets to be found -my @found = ("Alpha", "Beta", "Gamma", 'Delta', "Epsilon", - "Some::Crazy::Module", "Another::Crazy::Module", "aliased", "base", - "parent" +# Requires +my @expectedrequires = ( + "perl(Use::WhiteSpace)\n", ); -foreach my $mod (@found) { - ok(grep(/^perl\($mod\)$/,@requires), "'$mod' is required") -} -# Requirements to be ignore -my @ignored = ("Zeta", "Iota", "ShorterName"); -foreach my $mod (@ignored) { - ok(!grep(/^perl\($mod\)$/,@requires), "'$mod' is not required") -} - -# TODO: Find multiple line use -ok(!grep(/^perl\(overload\)$/, @requires), "'perl(overload)' is not found"); - -# -# Check if expected amount of modules was found -is(scalar(@requires), scalar(@requires), "Expected amount of modules was found"); +is_deeply([ sort @requires ], [ sort @expectedrequires ], "Only expected requires were found."); diff --git a/t/data/basic b/t/data/basic index 08ff5d2..6e53811 100644 --- a/t/data/basic +++ b/t/data/basic @@ -1,9 +1,12 @@ +# Inversioned Alpha should not be listed use Alpha; use Alpha 0.12; + use Alpha::One; use qw(Alpha::Two); use Beta (); require Gamma; +use ExtUtils::MM_Unix; eval { require Delta }; @@ -14,8 +17,12 @@ require v5.6.1; require 5.006_001; use 5.010; +# 'use' does not accept module name with .pm use 'Ignore.pm'; +# Dist-Zilla-5.027/lib/Dist/Zilla/Plugin/MakeMaker.pm +use ExtUtils::MakeMaker{{ defined $eumm_version && 0+$eumm_version ? ' ' . $eumm_version : '' }}; + require Eta; require 'Theta.pm'; require "Iota.pm"; diff --git a/t/data/list b/t/data/list index a0212e8..a068657 100644 --- a/t/data/list +++ b/t/data/list @@ -2,14 +2,15 @@ use base 'Alpha'; use base qw(Beta Gamma); use base qw(Delta); use parent 'Epsilon'; + +# 'Zeta', 'Iota' should not be found use parent -norequire, qw(Zeta Iota); + use aliased "Some::Crazy::Module"; # 'ShorterName' should not be found use aliased "Another::Crazy::Module" => "ShorterName"; - -# TODO: Find multiple line use. use overload '+' => \&myadd, '-' => \&mysub; diff --git a/t/data/provides b/t/data/provides index f870d74..e1e3751 100644 --- a/t/data/provides +++ b/t/data/provides @@ -25,8 +25,9 @@ $VERSION = (qw$Revision: 1.7 $)[1]; package DynaLoader; $VERSION = $VERSION = "1.03"; # avoid typo warning +# version should not be found package Config::General; -$Config::General::VERSION = 2.33; +$Config::General::VERSION == 2.33; package Alpha::Beta123; our $VERSION = $Alpha::Beta123::VERSION=1.23; @@ -53,3 +54,20 @@ our $VERSION = 'v0.3.0'; package XML::Grove; $VERSION = '0.46alpha'; + +package Kappa::Lambda v5.43; + +# version should not be found + package Xi; + $VERSION =~ s/1.24/1.00/; + +package ExtUtils::MM_Unix; + +# Multiline module definition are ignored for now +package # hide form PAUSE + DBIx::Class::CDBICompat::AbstractSearch; + +package + Sigma + 1.27 + ; diff --git a/t/data/whitespace b/t/data/whitespace index 4c31581..1aec654 100644 --- a/t/data/whitespace +++ b/t/data/whitespace @@ -1,4 +1,5 @@ - use Use::WhiteSpace; - # TODO: Stop ignoring 'require' with whitespaces at the beginning require Require::WhiteSpace; + +# 'use' prefixed by whitespace should be find + use Use::WhiteSpace