Fabien Potencier > Test-File-Find-Rule-1.00 > Test::File::Find::Rule

Download:
Test-File-Find-Rule-1.00.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  

NAME ^

Test::File::Find::Rule - Test files and directories with File::Find::Rule

SYNOPSIS ^

 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'));

DESCRIPTION ^

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.

EXPORT

 match_rule_nb_results
 match_rule_array
 match_rule_no_result

FUNCTIONS

match_rule_nb_result(RULE, DIR, COMPARE [, NAME])

RULE is a File::Find::Rule object without a query method. The in method will be called automatically.

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.

COMPARE is a Number::Compare object. You have to follow Number::Compare semantics.

NAME is the optional name of the test.

match_rule_no_result(RULE, DIR [, NAME])

Just a convenient shortcut for

 match_rule_nb_result(RULE, DIR, 0 [, NAME])
match_rule_array(RULE, DIR, RESULTS [, 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).

SEE ALSO ^

File::Find::Rule, Number::Compare Test::File, Test::Files Test::More, Test::Builder

AUTHOR ^

Fabien POTENCIER, <fabpot@cpan.org>

COPYRIGHT ^

Copyright 2003-2004, Fabien POTENCIER, All Rights Reserved

LICENSE ^

You may use, modify, and distribute this under the same terms as Perl itself.

syntax highlighting: