This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.17
in repository libdist-zilla-plugin-test-eol-perl.

commit b76361f98294e6c342c91804d65f9370c0739914
Author: Karen Etheridge <et...@cpan.org>
Date:   Fri Jan 30 23:26:13 2015 -0800

    add support for custom filefinders
---
 Changes                           |  5 +++
 lib/Dist/Zilla/Plugin/Test/EOL.pm | 84 ++++++++++++++++++++++++++++++++-------
 t/01-basic.t                      | 15 +++++--
 t/{01-basic.t => 03-finder.t}     | 59 ++++++++++-----------------
 4 files changed, 108 insertions(+), 55 deletions(-)

diff --git a/Changes b/Changes
index baec570..2d52d21 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@ Revision history for {{$dist->name}}
 
 {{$NEXT}}
         - include trailing_whitespace in config dumped into metadata
+        - now includes the list of files to check inside the test, allowing
+          customization of files to search via filefinder options (adds
+          searching of .pod by default); also works around issue with older
+          Test::EOL Test::NoTabs that tests nothing when the test is two levels
+          deep from the dist root (see RT#66177)
 
 0.16    2014-11-17 03:00:59Z
         - allow tests to pass even while upstream modules have warnings under
diff --git a/lib/Dist/Zilla/Plugin/Test/EOL.pm 
b/lib/Dist/Zilla/Plugin/Test/EOL.pm
index e9cb9e0..f6d73de 100644
--- a/lib/Dist/Zilla/Plugin/Test/EOL.pm
+++ b/lib/Dist/Zilla/Plugin/Test/EOL.pm
@@ -5,14 +5,22 @@ package Dist::Zilla::Plugin::Test::EOL;
 # KEYWORDS: plugin test testing author development whitespace newline linefeed 
formatting
 
 use Moose;
+use Path::Tiny;
 use Sub::Exporter::ForMethods 'method_installer';
 use Data::Section 0.004 # fixed header_re
     { installer => method_installer }, '-setup';
+use Moose::Util::TypeConstraints 'role_type';
 use namespace::autoclean;
 
 with
     'Dist::Zilla::Role::FileGatherer',
+    'Dist::Zilla::Role::FileMunger',
     'Dist::Zilla::Role::TextTemplate',
+    'Dist::Zilla::Role::FileFinderUser' => {
+        method          => 'found_files',
+        finder_arg_names => [ 'finder' ],
+        default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ],
+    },
     'Dist::Zilla::Role::PrereqSource',
 ;
 
@@ -28,13 +36,17 @@ has filename => (
     default => sub { return 'xt/author/eol.t' },
 );
 
+has _file_obj => (
+    is => 'rw', isa => role_type('Dist::Zilla::Role::File'),
+);
+
 around dump_config => sub
 {
     my ($orig, $self) = @_;
     my $config = $self->$orig;
 
     $config->{+__PACKAGE__} = {
-         map { $_ => $self->$_ } qw(filename trailing_whitespace),
+         map { $_ => $self->$_ } qw(filename trailing_whitespace finder),
     };
     return $config;
 };
@@ -46,17 +58,40 @@ sub gather_files
     require Dist::Zilla::File::InMemory;
 
     $self->add_file(
-        Dist::Zilla::File::InMemory->new(
-            name => $self->filename,
-            content => $self->fill_in_string(
-                ${$self->section_data('__TEST__')},
-                {
-                    plugin => \$self,
-                    trailing_ws => \$self->trailing_whitespace
-                },
-            ),
+        $self->_file_obj(
+            Dist::Zilla::File::InMemory->new(
+                name => $self->filename,
+                content => ${$self->section_data('__TEST__')},
+            )
+        )
+    );
+
+    return;
+}
+
+sub munge_files
+{
+    my $self = shift;
+
+    my @filenames = map { path($_->name)->relative('.')->stringify }
+        grep { not ($_->can('is_bytes') and $_->is_bytes) }
+        @{ $self->found_files };
+
+    $self->log_debug('adding file ' . $_) foreach @filenames;
+
+    my $file = $self->_file_obj;
+    $file->content(
+        $self->fill_in_string(
+            $file->content,
+            {
+                dist => \($self->zilla),
+                plugin => \$self,
+                filenames => [ sort @filenames ],
+                trailing_ws => \$self->trailing_whitespace,
+            },
         )
     );
+
     return;
 }
 
@@ -68,8 +103,8 @@ sub register_prereqs
             type  => 'requires',
             phase => 'develop',
         },
-        'Test::More' => 0,
-        'Test::EOL' => 0,
+        'Test::More' => '0.88',
+        'Test::EOL' => '0',
     );
 }
 
@@ -98,11 +133,25 @@ L<Test::EOL/all_perl_files_ok>. It defaults to C<1>.
 What this option is going to do is test for the lack of trailing whitespace at
 the end of the lines (also known as "trailing space").
 
+=head2 C<finder>
+
+=for stopwords FileFinder
+
+This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder> for finding
+files to check.  The default value is C<:InstallModules>,
+C<:ExecFiles> (see also L<Dist::Zilla::Plugin::ExecDir>) and C<:TestFiles>;
+this option can be used more than once.
+
+Other predefined finders are listed in
+L<Dist::Zilla::Role::FileFinderUser/default_finders>.
+You can define your own with the
+L<[FileFinder::ByName]|Dist::Zilla::Plugin::FileFinder::ByName> plugin.
+
 =head2 C<filename>
 
 The filename of the test to add - defaults to F<xt/author/test-eol.t>.
 
-=for Pod::Coverage gather_files register_prereqs
+=for Pod::Coverage gather_files munge_files register_prereqs
 
 =head1 ACKNOWLEDGMENTS
 
@@ -125,7 +174,12 @@ use warnings;
 
 # this test was generated with {{ ref($plugin) . ' ' . ($plugin->VERSION || 
'<self>') }}
 
-use Test::More;
+use Test::More 0.88;
 use Test::EOL;
 
-all_perl_files_ok({ trailing_whitespace => {{ $trailing_ws }} });
+my @files = (
+{{ join(",\n", map { "    '" . $_ . "'" } map { s/'/\\'/g; $_ } @filenames) }}
+);
+
+eol_unix_ok($_, { trailing_whitespace => {{ $trailing_ws }} }) foreach @files;
+done_testing;
diff --git a/t/01-basic.t b/t/01-basic.t
index b08a556..de0f152 100644
--- a/t/01-basic.t
+++ b/t/01-basic.t
@@ -56,13 +56,22 @@ my $content = $file->slurp_utf8;
 unlike($content, qr/[^\S\n]\n/m, 'no trailing whitespace in generated test');
 unlike($content, qr/\t/m, 'no tabs in generated test');
 
+my @files = (
+    path(qw(lib Foo.pm)),
+    path(qw(lib Bar.pod)),
+    path(qw(bin myscript)),
+    path(qw(t foo.t)),
+);
+
+like($content, qr/'\Q$_\E'/m, "test checks $_") foreach @files;
+
 cmp_deeply(
     $tzil->distmeta,
     superhashof({
         prereqs => {
             develop => {
                 requires => {
-                    'Test::More' => '0',
+                    'Test::More' => '0.88',
                     'Test::EOL' => '0',
                 },
             },
@@ -75,6 +84,7 @@ cmp_deeply(
                         'Dist::Zilla::Plugin::Test::EOL' => {
                             filename => 'xt/author/eol.t',
                             trailing_whitespace => 1,
+                            finder => [ ':InstallModules', ':ExecFiles', 
':TestFiles' ],
                         },
                     },
                     name => 'Test::EOL',
@@ -99,8 +109,7 @@ subtest 'run the generated test' => sub
     $files_tested = Test::Builder->new->current_test;
 };
 
-# this should be 4 - but .pod is not being picked up by Test::EOL
-is($files_tested, 3, 'correct number of files were tested');
+is($files_tested, @files, 'correct number of files were tested');
 
 diag 'got log messages: ', explain $tzil->log_messages
     if not Test::Builder->new->is_passing;
diff --git a/t/01-basic.t b/t/03-finder.t
similarity index 53%
copy from t/01-basic.t
copy to t/03-finder.t
index b08a556..b6de62a 100644
--- a/t/01-basic.t
+++ b/t/03-finder.t
@@ -2,11 +2,16 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Warnings 0.009 ':no_end_test', ':all';
+use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
 use Test::DZil;
 use Path::Tiny;
 use File::pushd 'pushd';
-use Test::Deep;
+
+BEGIN {
+    use Dist::Zilla::Plugin::Test::EOL;
+    $Dist::Zilla::Plugin::Test::EOL::VERSION = 9999
+        unless $Dist::Zilla::Plugin::Test::EOL::VERSION;
+}
 
 my $tzil = Builder->from_config(
     { dist_root => 't/does-not-exist' },
@@ -15,8 +20,8 @@ my $tzil = Builder->from_config(
             path(qw(source dist.ini)) => simple_ini(
                 [ GatherDir => ],
                 [ ExecDir => ],
-                [ MetaConfig => ],
-                [ 'Test::EOL' ],
+                [ 'FileFinder::ByName' => ExtraTestFiles => { dir => 'xt' } ],
+                [ 'Test::EOL' => { finder => [ ':InstallModules', ':TestFiles' 
] } ],
             ),
             path(qw(source lib Foo.pm)) => <<'MODULE',
 package Foo;
@@ -50,41 +55,23 @@ $tzil->build;
 
 my $build_dir = path($tzil->tempdir)->child('build');
 my $file = $build_dir->child(qw(xt author eol.t));
-ok( -e $file, $file . ' created');
+ok( -e $file, 'test created');
 
 my $content = $file->slurp_utf8;
 unlike($content, qr/[^\S\n]\n/m, 'no trailing whitespace in generated test');
 unlike($content, qr/\t/m, 'no tabs in generated test');
 
-cmp_deeply(
-    $tzil->distmeta,
-    superhashof({
-        prereqs => {
-            develop => {
-                requires => {
-                    'Test::More' => '0',
-                    'Test::EOL' => '0',
-                },
-            },
-        },
-        x_Dist_Zilla => superhashof({
-            plugins => supersetof(
-                {
-                    class => 'Dist::Zilla::Plugin::Test::EOL',
-                    config => {
-                        'Dist::Zilla::Plugin::Test::EOL' => {
-                            filename => 'xt/author/eol.t',
-                            trailing_whitespace => 1,
-                        },
-                    },
-                    name => 'Test::EOL',
-                    version => ignore,
-                },
-            ),
-        }),
-    }),
-    'prereqs are properly injected for the develop phase',
-) or diag 'got distmeta: ', explain $tzil->distmeta;
+my @files = (
+    path(qw(lib Foo.pm)),
+    path(qw(lib Bar.pod)),
+    path(qw(t foo.t)),
+);
+like($content, qr/'\Q$_\E'/m, "test checks $_") foreach @files;
+
+unlike($content, qr/'\Q$_\E'/m, "test does not check $_") foreach (
+    path(qw(bin myscript)),
+    path(qw(xt bar.t)),
+);
 
 my $files_tested;
 
@@ -99,11 +86,9 @@ subtest 'run the generated test' => sub
     $files_tested = Test::Builder->new->current_test;
 };
 
-# this should be 4 - but .pod is not being picked up by Test::EOL
-is($files_tested, 3, 'correct number of files were tested');
+is($files_tested, @files, 'correct number of files were tested');
 
 diag 'got log messages: ', explain $tzil->log_messages
     if not Test::Builder->new->is_passing;
 
-had_no_warnings if $ENV{AUTHOR_TESTING};
 done_testing;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libdist-zilla-plugin-test-eol-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to