Test::File::Find::Rule - Test files and directories with File::Find::Rule
use Test::File::Find::Rule; # Check that all files in $dir have sensible names my $rule = File::Find::Rule ->file ->relative ->not_name(qr/^[\w]{1,8}\.[a-z]{3,4}$/); match_rule_no_result($rule, $dir, 'File names ok'); # Check that all our perl scripts have use strict ! my $rule = File::Find::Rule ->file ->relative ->name(@perl_ext) ->not_grep(qr/^\s*use\s+strict;/m, sub { 1 }); match_rule_no_result($rule, $dir, 'use strict usage'); # With some help of File::Find::Rule::MMagic # Check that there is less than 10 images in $dir # with a size > 1Mo my $rule = File::Find::Rule ->file ->relative ->magic('image/*') ->size('>1Mo'); match_rule_nb_result($rule, $dir, '<10', 'Few big images'); # We can reuse our F:F:R object match_rule_nb_result($rule, $another_dir, '>100', 'A lot of big images'); # Check the exact result from a rule my $dirs = [qw(web lib data tmp)]; my $rule = File::Find::Rule ->directory ->mindepth(1) ->maxdepth(1) ->relative; match_rule_array($rule, $dir, $dirs, 'Directory structure ok'));
This module provides some functions to test files and directories with all the power of the wonderful File::Find::Rule module.
The test functionnality is based on Test::Builder.
match_rule_nb_results match_rule_array match_rule_no_result
RULE is a File::Find::Rule object without a query method. The in method will be called automatically.
in
DIR is a directory. To be safe, I recommend to give an absolute directory and use the relative function for your rule so that error messages are shorter.
relative
COMPARE is a Number::Compare object. You have to follow Number::Compare semantics.
NAME is the optional name of the test.
Just a convenient shortcut for
match_rule_nb_result(RULE, DIR, 0 [, NAME])
The only difference with the match_rule_nb_result is the RESULTS param wich is an array ref with the expected results (order does not matter).
match_rule_nb_result
File::Find::Rule, Number::Compare Test::File, Test::Files Test::More, Test::Builder
Fabien POTENCIER, <fabpot@cpan.org>
Copyright 2003-2004, Fabien POTENCIER, All Rights Reserved
You may use, modify, and distribute this under the same terms as Perl itself.
To install Test::File::Find::Rule, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::File::Find::Rule
CPAN shell
perl -MCPAN -e shell install Test::File::Find::Rule
For more information on module installation, please visit the detailed CPAN module installation guide.