Skip Menu |

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

Report information
The Basics
Id: 87065
Status: new
Priority: 0/
Queue: Test-Files

People
Owner: Nobody in particular
Requestors: yanick+cpan [...] babyl.dyndns.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Add possibility to filter out complete files in compaire_dirs_filter_ok
This patch allows to filter on the files themselves. Useful, for example, when you want to compare the directories but want to skip log files: compare_dirs_filter_ok( 'mydir' => 'target_dir', [ sub { my( $name, $dir_a, $dir_b ) = @_; return $name !~ /\.log$/; } ] ); Btw, I see that the last release is fairly old. If you want to punt the maintenance bit of this module my way, I can help. :-) Joy, `/anick
Subject: 0001-add-file-filtering-function.patch
From cc4ca78d21ac49aee02f3ea35607c52a170b4dfd Mon Sep 17 00:00:00 2001 From: Yanick Champoux <yanick@babyl.dyndns.org> Date: Fri, 19 Jul 2013 13:16:46 -0400 Subject: [PATCH] add file filtering function ... in a backward compatible way too! --- Files.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Files.pm b/Files.pm index 24c5b5b..9eabe80 100644 --- a/Files.pm +++ b/Files.pm @@ -286,6 +286,12 @@ sub compare_dirs_filter_ok { my $filter = shift; my $name = shift; + my $file_filter; + + if( ref $filter eq 'ARRAY' ) { + ( $file_filter, $filter ) = @$filter; + } + unless (-d $first_dir) { $Test->ok(0, $name); $Test->diag("$first_dir is not a valid directory"); @@ -315,6 +321,10 @@ sub compare_dirs_filter_ok { $name = File::Spec->abs2rel( $name, $first_dir ); return if length($name) < 1; # skip the base directory + if ( $file_filter ) { + return unless $file_filter->( $name, $first_dir, $second_dir ); + } + my $first_file = File::Spec->catfile( $first_dir, $name ); my $second_file = File::Spec->catfile( $second_dir, $name ); @@ -453,6 +463,40 @@ works like compare_dirs_ok, but calls a filter function on each line of input, allowing you to exclude or alter some text to avoid spurious failures (like timestamp disagreements). +It's also possible to pass an arrayref for the filter functions. In that case, +the first filter function will determine if the files are to be compared at +all. The arguments passed to the file filter are the path +of the file (relative to the directories passed to +C<compare_dirs_filter_ok>) and the two +root directories for the compare. E.g.: + + # skip all lines in files that are comments + compare_dirs_filter_ok( + 'mydir' => 'target_dir', + sub { my $line = shift; $line !~ /^\s*#/ } + ); + + # skip all files that have a '.log' extension + compare_dirs_filter_ok( + 'mydir' => 'target_dir', + [ sub { + my( $name, $dir_a, $dir_b ) = @_; + return $name !~ /\.log$/; + } ] + ); + + # skip log files, in other files skip comment lines + compare_dirs_filter_ok( + 'mydir' => 'target_dir', + [ + sub { + my( $name, $dir_a, $dir_b ) = @_; + return $name !~ /\.log$/; + }, + sub { my $line = shift; $line !~ /^\s*#/ } + ] + ); + =back Though the SYNOPSIS examples don't all have names, you can and should provide -- 1.8.1.2