Skip Menu |

This queue is for tickets about the Test-PerlTidy CPAN distribution.

Report information
The Basics
Id: 44893
Status: resolved
Priority: 0/
Queue: Test-PerlTidy

People
Owner: larryl [...] cpan.org
Requestors: duncan_j_ferguson [...] yahoo.co.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 20070911
Fixed in: 20110320



Subject: Ability to exclude specific directories from the test
At the moment all directories for the module are searched and checked - however, using Module::Install puts in an 'inc' directory and the test complains about untidy code within there (which is outside of my direct control). Would be good to allow and arg to be passed which can exclude this (or any other user specified) directory.
Subject: PATCH: Ability to exclude specific directories from the test
Attached is a patch that allows for excludes of directories - not sure what perltidy options were originally used so just added in code with a style as closely as i can see from other code It also exposes a debug option (to see what is excluded/included) and also the MUTE
diff -ur Test-PerlTidy-20070911.orig/lib/Test/PerlTidy.pm Test-PerlTidy-20070911/lib/Test/PerlTidy.pm --- Test-PerlTidy-20070911.orig/lib/Test/PerlTidy.pm 2007-09-11 17:50:39.000000000 +0000 +++ Test-PerlTidy-20070911/lib/Test/PerlTidy.pm 2009-09-21 09:57:39.000000000 +0000 @@ -28,8 +28,11 @@ # Skip all tests if instructed to. $Test->skip_all("All tests skipped.") if $args{skip_all}; + $args{top} ||= '.'; + $MUTE ||= $args{mute}; + # Get files to work with and set the plan. - my @files = list_files('.'); + my @files = list_files(%args); $Test->plan( tests => scalar @files ); # Check ech file in turn. @@ -80,7 +83,24 @@ } sub list_files { - my $path = shift; + my $args_ref = \@_; + my %args; + + my $path; + my $exclude = [ './blib/' ]; # filter out blib by default + + if(scalar(@$args_ref) > 1) { + %args=@$args_ref; + + $Test->BAIL_OUT( 'exclude should be an array' ) + if( $args{exclude} && ref $args{exclude} ne 'ARRAY' ); + + $exclude = $args{exclude}; + $path=$args{top}; + } else { + $path = $args_ref->[0]; + } + die "You need to specify which directory to scan" unless defined $path && length $path; @@ -92,6 +112,24 @@ # Find files using File::Finder. @files = File::Finder->type('f')->in($path); + if($exclude) { + my @removed; + my @include; + + foreach my $item(@$exclude) { + push(@removed, grep{ m|^$item| } @files ); + push(@include, grep{ !m|^$item| } @files ); + + @files=@include; + @include = (); + } + + if( $args{debug}) { + $Test->diag( 'Files excluded: ', join("\n\t", @removed),$/ ); + $Test->diag( 'Files remaining ', join("\n\t", @files),$/ ); + } + } + return # Sort the output so that it is repeatable @@ -100,8 +138,7 @@ # Filter out only the files that end in .pl, .pm, .PL or .t grep { m/\.(pl|pm|PL|t)$/; } - # Filter out blib - grep { !m|^\./blib/|; } @files; + @files; } sub load_file { @@ -124,6 +161,8 @@ # In a file like 't/perltidy.t' use Test::PerlTidy; run_tests(); + # or + run_tests( top => '.', exclude => [ './blib/' ], debug => 0, mute => 0 ); =head1 DESCRIPTION diff -ur Test-PerlTidy-20070911.orig/t/list_files.t Test-PerlTidy-20070911/t/list_files.t --- Test-PerlTidy-20070911.orig/t/list_files.t 2007-09-11 18:09:53.000000000 +0000 +++ Test-PerlTidy-20070911/t/list_files.t 2009-09-21 09:33:31.000000000 +0000 @@ -9,6 +9,8 @@ ( './Makefile.PL', # './lib/Test/PerlTidy.pm', # + './t/exclude_files.t', # + './t/exclude_perltidy.t', # './t/list_files.t', # './t/perltidy.t', # './t/is_file_tidy.t', #
use strict; use warnings; use Test::More tests => 1; use Test::PerlTidy; my @wanted_files = sort # ( './Makefile.PL', # './t/exclude_files.t', # './t/exclude_perltidy.t', # './t/list_files.t', # './t/perltidy.t', # './t/is_file_tidy.t', # ); my @exclude = sort ( './blib', './lib', ); my @found_files = Test::PerlTidy::list_files( top => '.', exclude => \@exclude , debug => 0, ); is_deeply( \@wanted_files, \@found_files );
use strict; use warnings; use Test::PerlTidy; run_tests( top => '.', exclude => [ './blib/' ], debug => 0 );
From: world.mind [...] yahoo.com
I need the same. I need to pass directory names to run_tests().
This is fixed in Test-PerlTidy-20110320