Avoid emitting trailing whitespace in test (oh, the irony)
[catagits/Test-EOL.git] / lib / Test / EOL.pm
index 82e2be6..668d499 100644 (file)
@@ -6,8 +6,8 @@ use warnings;
 
 use Test::Builder;
 use File::Spec;
-use FindBin qw($Bin);
 use File::Find;
+use Cwd qw/ cwd /;
 
 use vars qw( $PERL $UNTAINT_PATTERN $PERL_PATTERN);
 
@@ -22,7 +22,8 @@ my %file_find_arg = ($] <= 5.006) ? () : (
 );
 
 my $Test  = Test::Builder->new;
-my $updir = File::Spec->updir();
+
+my $no_plan;
 
 sub import {
     my $self   = shift;
@@ -33,6 +34,11 @@ sub import {
         *{$caller.'::all_perl_files_ok'} = \&all_perl_files_ok;
     }
     $Test->exported_to($caller);
+
+    if ($_[0] && $_[0] eq 'no_plan') {
+        shift;
+        $no_plan = 1;
+    }
     $Test->plan(@_);
 }
 
@@ -42,7 +48,8 @@ sub _all_perl_files {
 }
 
 sub _all_files {
-    my @base_dirs = @_ ? @_ : File::Spec->catdir($Bin, $updir);
+    my @base_dirs = @_ ? @_ : cwd();
+    my $options = pop(@base_dirs) if ref $base_dirs[-1] eq 'HASH';
     my @found;
     my $want_sub = sub {
         return if ($File::Find::dir =~ m![\\/]?CVS[\\/]|[\\/]?\.svn[\\/]!); # Filter out cvs or subversion dirs/
@@ -80,7 +87,7 @@ sub _show_whitespace {
 sub _debug_line {
     my ( $options, $line ) = @_;
     $line->[2] =~ s/\n\z//g;
-    return "line $line->[1]: $line->[0] " . (
+    return "line $line->[1]: $line->[0]" . (
       $options->{show_lines} ? qq{: } . _show_whitespace( $line->[2] )  : q{}
     );
 }
@@ -166,6 +173,7 @@ sub _module_to_path {
 }
 
 sub _make_plan {
+    return if $no_plan;
     unless ($Test->has_plan) {
         $Test->plan( 'no_plan' );
     }
@@ -214,6 +222,13 @@ or
   use Test::EOL;
   all_perl_files_ok({ trailing_whitespace => 1 }, @mydirs );
 
+or
+
+  use Test::More;
+  use Test::EOL 'no_test';
+  all_perl_files_ok();
+  done_testing;
+
 =head1 DESCRIPTION
 
 This module scans your project/distribution for any perl files (scripts,
@@ -229,8 +244,8 @@ if you don't export anything, such as for a purely object-oriented module.
   all_perl_files_ok( [ \%options ], [ @directories ] )
 
 Applies C<eol_unix_ok()> to all perl files found in C<@directories> (and sub
-directories). If no <@directories> is given, the starting point is one level
-above the current running script, that should cover all the files of a typical
+directories). If no <@directories> is given, the starting point is the current
+working directory, as tests are usually run from the top directory in a typical
 CPAN distribution. A perl file is *.pl or *.pm or *.t or a file starting
 with C<#!...perl>