Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

--files-from now warns if a non-existent file shows up

  • Loading branch information...
commit 203521dcd8a19447a1dbbf6c8c1301381c0ac634 1 parent a3309c1
@petdance authored
Showing with 41 additions and 13 deletions.
  1. +1 −1  Makefile.PL
  2. +3 −2 Resources.pm
  3. +37 −10 t/ack-files-from.t
View
2  Makefile.PL
@@ -36,7 +36,7 @@ my %parms = (
'Term::ANSIColor' => 0,
'Getopt::Long' => 2.36, # For GetOptionsFromArray()
'Test::More' => 0.96, # For subtest()
- 'File::Next' => 1.09_02,
+ 'File::Next' => 1.09_03,
'File::Basename' => 0,
'Pod::Usage' => 0,
},
View
5 Resources.pm
@@ -56,8 +56,9 @@ sub from_file {
my $iter =
File::Next::from_file( {
- error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
- sort_files => $opt->{sort_files},
+ error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
+ warning_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
+ sort_files => $opt->{sort_files},
}, $file ) or return undef;
return bless {
View
47 t/ack-files-from.t
@@ -5,29 +5,31 @@ use warnings;
use lib 't';
use File::Temp;
-use Test::More tests => 5;
+use Test::More tests => 3;
use Util;
prep_environment();
-NO_SWITCHES_MULTIPLE_FILES: {
+
+subtest 'Basic reading from files, no switches' => sub {
+ plan tests => 2;
+
my $target_file = File::Next::reslash( 't/swamp/options.pl' );
my @expected = split( /\n/, <<"EOF" );
$target_file:2:use strict;
EOF
- my $tempfile = File::Temp->new;
- print $tempfile "$_\n" for qw( t/swamp/options.pl t/swamp/pipe-stress-freaks.F );
- close $tempfile;
+ my $tempfile = fill_temp_file( qw( t/swamp/options.pl t/swamp/pipe-stress-freaks.F ) );
- my @args = qw( strict );
- my @results = run_ack( '--files-from=' . $tempfile->filename, @args );
+ ack_lists_match( [ '--files-from=' . $tempfile->filename, 'strict' ], \@expected, 'Looking for strict in multiple files' );
+ unlink $tempfile->filename;
+};
- lists_match( \@results, \@expected, 'Looking for strict in multiple files' );
-}
-NON_EXISTENT_FILE: {
+subtest 'Non-existent file specified' => sub {
+ plan tests => 3;
+
my @args = qw( strict );
my ( $stdout, $stderr ) = run_ack_with_stderr( '--files-from=non-existent-file', @args);
@@ -35,4 +37,29 @@ NON_EXISTENT_FILE: {
is( scalar @{$stderr}, 1, 'One line of STDERR for non-existent file' );
like( $stderr->[0], qr/Unable to open non-existent-file:/,
'Correct warning message for non-existent file' );
+};
+
+
+subtest 'Source file exists, but non-existent files mentioned in the file' => sub {
+ plan tests => 4;
+
+ my $tempfile = fill_temp_file( qw( t/swamp/options.pl file-that-isnt-there ) );
+ my ( $stdout, $stderr ) = run_ack_with_stderr( '--files-from=' . $tempfile->filename, 'CASE');
+
+ is( scalar @{$stdout}, 1, 'One hit found' );
+ like( $stdout->[0], qr/THIS IS ALL IN UPPER CASE/, 'Find the one line in the file' );
+
+ is( scalar @{$stderr}, 1, 'One line of STDERR for non-existent file' );
+ like( $stderr->[0], qr/file-that-isnt-there: No such file/, 'Correct warning message for non-existent file' );
+};
+
+
+sub fill_temp_file {
+ my @lines = @_;
+
+ my $tempfile = File::Temp->new;
+ print $tempfile "$_\n" for @lines;
+ close $tempfile;
+
+ return $tempfile;
}
Please sign in to comment.
Something went wrong with that request. Please try again.