Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directive to include files #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/Test/PerlTidy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ sub list_files {
$test->BAIL_OUT('exclude should be an array')
unless ref $excludes eq 'ARRAY';

my $finder = File::Finder->type('f')->name(qr{[.](?:pl|pm|PL|t)$});
my $includes = $args{include} || [qr{[.](?:pl|pm|PL|t)$}];

$test->BAIL_OUT('include should be an array')
unless ref $includes eq 'ARRAY';

my $finder = File::Finder->type('f');
$finder->{options}->{untaint} = 1;
my @files = $finder->in($path);

Expand All @@ -130,6 +135,18 @@ sub list_files {

foreach my $file ( keys %keep ) {

my $include_me;
foreach my $include ( @{$includes} ) {
$include_me =
ref $include ? ( $file =~ $include ) : ( $file =~ /^$include/ );
last if $include_me;
}

if ( not $include_me ) {
delete $keep{$file};
next;
}

foreach my $exclude ( @{$excludes} ) {

my $exclude_me =
Expand Down Expand Up @@ -274,6 +291,13 @@ attempted, which can impact how the exclusion rules apply. If your
exclusion rules do not seem to be working, turn on the C<debug>
option to see the paths of the files that are being kept/excluded.

=item include

By default, C<run_tests()> will check all files matching the regex object
C<qr{[.](?:pl|pm|PL|t)$}>. Set C<include> to define additional files
to include in the list. See C<exclude> for an explaination how files
are matched.

=item path

Set C<path> to the path to the top-level directory which contains
Expand Down
1 change: 1 addition & 0 deletions t/exclude_files.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ my @wanted_files = sort qw(
t/critic.t
t/exclude_files.t
t/exclude_perltidy.t
t/include_files.t
t/is_file_tidy.t
t/list_files.t
t/perltidy.t
Expand Down
32 changes: 32 additions & 0 deletions t/include_files.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!perl -T

use strict;
use warnings;

use Test::More tests => 1;

use Test::PerlTidy;

my @wanted_files = sort qw(
MANIFEST
Makefile.PL
t/critic.t
t/exclude_files.t
t/exclude_perltidy.t
t/include_files.t
t/is_file_tidy.t
t/list_files.t
t/perltidy.t
t/pod-coverage.t
t/pod.t
t/strict.t
);

my @found_files = Test::PerlTidy::list_files(
path => '.',
include => [ qr(\.(?:PL|t)$), qr(MANIFEST) ],
exclude => [ 'blib', 'lib' ],
debug => 0,
);

is_deeply( \@wanted_files, \@found_files );
1 change: 1 addition & 0 deletions t/list_files.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ my @wanted_files = sort qw(
t/critic.t
t/exclude_files.t
t/exclude_perltidy.t
t/include_files.t
t/is_file_tidy.t
t/list_files.t
t/perltidy.t
Expand Down