Test-Files-0.24/0000755000175100017540000000000014567202321012455 5ustar jurijjurijTest-Files-0.24/t/0000755000175100017540000000000014567202320012717 5ustar jurijjurijTest-Files-0.24/t/Test/0000755000175100017540000000000014567202320013636 5ustar jurijjurijTest-Files-0.24/t/Test/Files/0000755000175100017540000000000014567202320014700 5ustar jurijjurijTest-Files-0.24/t/Test/Files/_get_file_info.t0000644000175100017540000000553614566672711020044 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; use Test::Files::Constants qw( $FMT_ABSENT $FMT_ABSENT_WITH_ERROR $FMT_UNDEF ); const my $SUB => 'some::subroutine'; my $mock_this = mock $CLASS => ( override => [ _get_caller_sub => sub { $SUB } ] ); my $expected; plan( 3 ); $expected = [ sprintf( $FMT_UNDEF, '$file', $SUB ), undef ]; is( [ $METHOD_REF->( undef, sub {}, '$file' ) ], $expected, 'file undefined' ); const my $CONTENT => "line 0\nline 1\n"; SKIP: { const my $FILE => path( $TEMP_DIR )->child( 'file' ); const my $UNTESTABLE_OS => $^O eq 'MSWin32' || !path( '/dev/null' )->exists; skip "$^O does not support special device files" if $UNTESTABLE_OS; subtest 'file name supplied' => sub { subtest 'file is absent' => sub { plan( 3 ); $expected = [ sprintf( $FMT_ABSENT, $FILE ), undef ]; is( [ $METHOD_REF->( $FILE, {}, '$file' ) ], $expected, 'file does not exist' ); subtest 'file is a cpecial one' => sub { plan( 2 ); my $options; $options = { EXISTENCE_ONLY => 0 }; $expected = [ sprintf( $FMT_ABSENT, '/dev/null' ), undef ]; is( [ $METHOD_REF->( '/dev/null', $options, '$file' ) ], $expected, 'get content' ); $options = { EXISTENCE_ONLY => 1 }; $expected = [ undef, 1 ]; is( [ $METHOD_REF->( '/dev/null', $options, '$file' ) ], $expected, 'check existence' ); }; $expected = [ sprintf( $FMT_ABSENT, $TEMP_DIR ), undef ]; is( [ $METHOD_REF->( $TEMP_DIR, {}, '$file' ) ], $expected, 'file is a directory' ); }; $FILE->spew( $CONTENT ); ok( [ $METHOD_REF->( $FILE, { EXISTENCE_ONLY => 1 }, '$file' ) ], 'file existence' ); $expected = [ undef, length( $CONTENT ) ]; is( [ $METHOD_REF->( $FILE, { SIZE_ONLY => 1 }, '$file' ) ], $expected, 'file size' ); subtest 'filter omitted, reading failed' => sub { plan( 2 ); $FILE->chmod( 0 ); my $expected = sprintf( $FMT_ABSENT_WITH_ERROR, $FILE, '.+' ); my @got = $METHOD_REF->( $FILE, {}, '$file' ); like( $got[ 0 ], qr/$expected/, 'error message' ); is ( $got[ 1 ], undef, 'file content' ); }; $FILE->chmod( 'u+r' ); $expected = [ undef, "line 0\n" ]; is( [ $METHOD_REF->( $FILE, { FILTER => sub { /0/ ? $_ : undef } }, '$file' ) ], $expected, 'filter supplied, reading succeeded' ); }; } subtest 'scalar reference supplied' => sub { plan( 2 ); $expected = [ undef, length( $CONTENT ) ]; is( [ $METHOD_REF->( \$CONTENT, { SIZE_ONLY => 1 }, '$expected' ) ], $expected, 'content size' ); $expected = [ undef, $CONTENT ]; is( [ $METHOD_REF->( \$CONTENT, {}, '$expected' ) ], $expected, 'content returned' ); }; Test-Files-0.24/t/Test/Files/compare_filter_ok.t0000644000175100017540000000050714561716621020563 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mock_this = mock $CLASS => ( override => [ _compare_ok => sub {} ] ); plan( 1 ); lives_ok { $METHOD_REF->( 'got', 'expected' ) } 'executed'; Test-Files-0.24/t/Test/Files/file_ok.t0000644000175100017540000000052214561716657016515 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mock_this = mock $CLASS => ( override => [ _compare_ok => sub {} ] ); plan( 1 ); lives_ok { $METHOD_REF->( 'file', 'string' ) } 'comparison performed'; Test-Files-0.24/t/Test/Files/_validate_options.t0000644000175100017540000000325614566422664020614 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; use Test::Files::Constants qw( $DIRECTORY_OPTIONS $FMT_FILTER_ISNT_CODEREF $FILE_OPTIONS $FMT_INVALID_NAME_PATTER $FMT_INVALID_OPTIONS $FILE_OPTIONS ); my $expected; plan( 2 ); subtest failure => sub { plan( 3 ); const my $DEFAULT => $DIRECTORY_OPTIONS; $expected = sprintf( $FMT_INVALID_OPTIONS, 'X' ); is ( $METHOD_REF->( { X => 0 }, $DEFAULT ), $expected, 'invalid option' ); $expected = sprintf( $FMT_FILTER_ISNT_CODEREF, '.+' ) =~ s/([()])/\\$1/gr; like( $METHOD_REF->( { FILTER => 0 }, $DEFAULT ), qr/$expected/, 'filter is not a code reference' ); $expected = sprintf( $FMT_INVALID_NAME_PATTER, '\[', '.+', '.+' ); like( $METHOD_REF->( { NAME_PATTERN => '[' }, $DEFAULT ), qr/$expected/, 'invalid name pattern' ); }; subtest success => sub { plan( 2 ); subtest 'both filter and name pattern supplied' => sub { plan( 2 ); const my $DEFAULT => $DIRECTORY_OPTIONS; my $filter = sub {}; my ( $diag, %args ) = $METHOD_REF->( { FILTER => $filter, NAME_PATTERN => '..' }, $DEFAULT ); is( $diag, undef, 'no errors' ); is( \%args, { ( %$DEFAULT, FILTER => $filter, NAME_PATTERN => '..' ) }, 'arguments determined' ); }; subtest 'both filter and name pattern omitted' => sub { plan( 2 ); const my $DEFAULT => $FILE_OPTIONS; my ( $diag, %args ) = $METHOD_REF->( {}, $DEFAULT ); is( $diag, undef, 'no errors' ); is( \%args, $DEFAULT, 'arguments determined' ); }; }; Test-Files-0.24/t/Test/Files/compare_dirs_filter_ok.t0000644000175100017540000000105714561716607021611 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $diag; my $mock_this = mock $CLASS => ( override => [ _compare_dirs => sub {}, _show_failure => sub { $_[ 1 ] }, _validate_options => sub { $diag }, ] ); plan( 2 ); $diag = undef; is( $METHOD_REF->( 'first_dir', 'second_dir', sub {} ), $diag, 'success' ); $diag = 'ERROR'; is( $METHOD_REF->( 'first_dir', 'second_dir', sub {} ), $diag, 'failure' ); Test-Files-0.24/t/Test/Files/_compare_files.t0000644000175100017540000000325514561716451020052 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; use Test::Files::Constants qw( $FMT_DIFFERENT_SIZE $FMT_FIRST_FILE_ABSENT $FMT_SECOND_FILE_ABSENT ); const my $FIRST_FILE => path( $TEMP_DIR )->child( 'first_file' ); const my $SECOND_FILE => path( $TEMP_DIR )->child( 'second_file' ); plan( 3 ); my $expected; subtest 'compare existence only' => sub { plan( 3 ); $expected = [ sprintf( $FMT_SECOND_FILE_ABSENT, $FIRST_FILE, $SECOND_FILE ) ]; is( $METHOD_REF->( 0, 1, { EXISTENCE_ONLY => 1 }, $FIRST_FILE, $SECOND_FILE ), $expected, 'first file missing' ); $expected = [ sprintf( $FMT_FIRST_FILE_ABSENT, $FIRST_FILE, $SECOND_FILE ) ]; is( $METHOD_REF->( 1, 0, { EXISTENCE_ONLY => 1 }, $FIRST_FILE, $SECOND_FILE ), $expected, 'second file missing' ); $expected = []; is( $METHOD_REF->( 1, 1, { EXISTENCE_ONLY => 1 }, $FIRST_FILE, $SECOND_FILE ), $expected, 'both files exist' ); }; subtest 'compare size' => sub { plan( 2 ); $expected = [ sprintf( $FMT_DIFFERENT_SIZE, $FIRST_FILE, $SECOND_FILE, 1, 0 ) ]; is( $METHOD_REF->( 1, 0, { SIZE_ONLY => 1 }, $FIRST_FILE, $SECOND_FILE ), $expected, 'different size' ); $expected = []; is( $METHOD_REF->( 1, 1, { SIZE_ONLY => 1 }, $FIRST_FILE, $SECOND_FILE ), $expected, 'equal size' ); }; subtest 'compare content' => sub { plan( 2 ); ok( scalar( @{ $METHOD_REF->( '1', '0', { STYLE => 'OldStyle'}, $FIRST_FILE, $SECOND_FILE ) } ), 'different content' ); ok( !scalar( @{ $METHOD_REF->( '1', '1', { CONTEXT => 2 }, $FIRST_FILE, $SECOND_FILE ) } ), 'identical content' ); }; Test-Files-0.24/t/Test/Files/compare_ok.t0000644000175100017540000000050714555506500017212 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mock_this = mock $CLASS => ( override => [ _compare_ok => sub {} ] ); plan( 1 ); lives_ok { $METHOD_REF->( 'got', 'expected' ) } 'executed'; Test-Files-0.24/t/Test/Files/_show_failure.t0000644000175100017540000000114214567176304017725 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Builder::Tester tests => 1; use Test::Expander; const my $MESSAGE => 'message'; const my $SEP => $^O eq 'MSWin32' ? '\\' : '/'; const my $TITLE => 'failure reported'; test_out( "not ok 1 - $TITLE" ); test_err( "# Failed test '$TITLE'", '# at ' . path( $TEST_FILE )->relative( cwd() ) =~ s{ [/\\] }{$SEP}grx . ' line ' . line_num( +5 ) . '.', "# $MESSAGE" ); $METHOD_REF->( $TITLE, $MESSAGE ); test_test( title => $TITLE ); Test-Files-0.24/t/Test/Files/_get_caller_sub.t0000644000175100017540000000123214561716476020214 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; use Test::Files::Constants qw( $UNKNOWN ); plan( 2 ); public_sub( 'main::public_sub', 'public subroutine detected' ); _another_private_sub( $UNKNOWN, 'no public subroutine detected' ); sub _another_private_sub { return _private_sub( @_ ) } ## no critic (RequireArgUnpacking) sub _private_sub { my ( $expected, $title ) = @_; return is( $METHOD_REF->(), $expected, $title ); } sub public_sub { return _private_sub( @_ ) } ## no critic (RequireArgUnpacking) Test-Files-0.24/t/Test/Files/compare_dirs_ok.t0000644000175100017540000000107114561716613020235 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $diag; my $mock_this = mock $CLASS => ( override => [ _compare_dirs => sub {}, _show_failure => sub { $_[ 1 ] }, _validate_trailing_args => sub { ( $diag, {} ) }, ] ); plan( 2 ); $diag = undef; is( $METHOD_REF->( 'first_dir', 'second_dir' ), $diag, 'success' ); $diag = 'ERROR'; is( $METHOD_REF->( 'first_dir', 'second_dir' ), $diag, 'failure' ); Test-Files-0.24/t/Test/Files/_get_two_files_info.t0000644000175100017540000000154114561716511021100 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; const my $CONTENT => 'content'; const my $ERROR => 'error'; my @result; my $mock_this = mock $CLASS => ( override => [ _get_file_info => sub { @{ shift( @result ) } } ] ); plan( 2 ); my $expected; @result = ( [ $ERROR, undef ], [ undef, $CONTENT ] ); $expected = [ [ $ERROR ], undef, $CONTENT ]; is( [ $METHOD_REF->( 'first_file', 'second_file', undef, 'first_name', 'second_name' ) ], $expected, 'first file reading failed' ); @result = ( [ undef, $CONTENT ], [ $ERROR, undef ] ); $expected = [ [ $ERROR ], $CONTENT, undef ]; is( [ $METHOD_REF->( 'first_file', 'second_file', undef, 'first_name', 'second_name' ) ], $expected, 'second file reading failed' ); Test-Files-0.24/t/Test/Files/file_filter_ok.t0000644000175100017540000000053314561716651020056 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mock_this = mock $CLASS => ( override => [ _compare_ok => sub {} ] ); plan( 1 ); is( $METHOD_REF->( 'file', 'string', sub {} ), undef, 'comparison performed' ); Test-Files-0.24/t/Test/Files/find_ok.t0000644000175100017540000000216314566422557016517 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; use Test::Files::Constants qw( $DIRECTORY_OPTIONS $FMT_SUB_FAILED ); my $diag; my $sub = sub { path( shift )->basename eq 'GOOD' }; my $mockThis = mock $CLASS => ( override => [ _show_failure => sub { pass( 'Failure reported' ); undef }, _show_result => sub { my $expected = $FMT_SUB_FAILED =~ s/%s/path( $TEMP_DIR )->child( 'BAD' )/er; is( $_[ 2 ], $expected, 'Negative results reported' ); return; }, _validate_args => sub { shift; ( $diag, path( shift ), shift, $DIRECTORY_OPTIONS ) }, ] ); path( $TEMP_DIR )->child( 'SUBDIR' )->mkdir; path( $TEMP_DIR )->child( 'BAD' )->touch; path( $TEMP_DIR )->child( 'GOOD' )->touch; plan( 2 ); subtest 'valid arguments' => sub { plan( 2 ); $diag = 'ERROR'; is( $METHOD_REF->( $TEMP_DIR, $sub ), undef, 'executed' ); }; subtest 'invalid arguments' => sub { plan( 2 ); $diag = undef; is( $METHOD_REF->( $TEMP_DIR, $sub ), undef, 'executed' ); }; Test-Files-0.24/t/Test/Files/_compare_ok.t0000644000175100017540000000330414561716457017362 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; my ( $args_valid, $expected, $file_diff, $files_info ); my $mock_this = mock $CLASS => ( override => [ _compare_files => sub { $file_diff }, _get_two_files_info => sub { $files_info }, _show_failure => sub { is( [ @_[ 1 .. $#_ ] ], $expected, 'failure reported' ); return }, _show_result => sub { is( [ @_[ 2 .. $#_ ] ], $expected, 'comparison result reported' ); return }, _validate_trailing_args => sub { $args_valid ? ( undef, $_[ 0 ]->[ 0 ], $_[ 0 ]->[ 1 ] ) : 'ARG ERROR' }, ] ); plan( 4 ); subtest 'invalid optional arguments' => sub { plan( 2 ); ( $args_valid, $expected, $file_diff, $files_info ) = ( 0, [ 'ARG ERROR' ], [], [] ); is( $METHOD_REF->( 'got_file', 'expected_file' ), undef, 'executed' ); }; subtest 'file info cannot be gathered' => sub { plan( 2 ); ( $args_valid, $expected, $file_diff, $files_info ) = ( 1, [ 'INFO ERROR' ], [], [ 'INFO ERROR' ] ); is( $METHOD_REF->( 'got_file', 'expected_file' ), undef, 'executed' ); }; subtest 'expected file passed, differences detected' => sub { plan( 2 ); ( $args_valid, $expected, $file_diff, $files_info ) = ( 1, [ 'DIFF ERROR' ], [ 'DIFF ERROR' ], [] ); is( $METHOD_REF->( 'got_file', 'expected_file' ), undef, 'executed' ); }; subtest 'expected content passed, differences detected' => sub { plan( 2 ); ( $args_valid, $expected, $file_diff, $files_info ) = ( 1, [ 'DIFF ERROR' ], [ 'DIFF ERROR' ], [] ); is( $METHOD_REF->( 'got_file', \'expected_content' ), undef, 'executed' ); }; Test-Files-0.24/t/Test/Files/dir_only_contains_ok.t0000644000175100017540000000117714564110616021304 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $diag; my $mockThis = mock $CLASS => ( override => [ _dir_contains_ok => sub { [] }, _show_failure => sub { $_[ 1 ] }, _show_result => sub {}, _validate_trailing_args => sub { ( $diag, {} ) }, ] ); plan( 2 ); $diag = undef; is( $METHOD_REF->( 'dir', [ 'file' ] ), $diag, 'comparison performed' ); $diag = 'ERROR'; is( $METHOD_REF->( 'dir', [ 'file' ] ), $diag, 'invalid arguments, comparison rejected' ); Test-Files-0.24/t/Test/Files/_validate_trailing_args.t0000644000175100017540000000313514566422607021737 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; use Test::Files::Constants qw( $DIRECTORY_OPTIONS $FMT_INVALID_ARGUMENT ); my ( $diag, %options ); my $mockThis = mock $CLASS => ( override => [ _validate_options => sub { ( $diag, %options ) } ] ); const my $DEFAULT => $DIRECTORY_OPTIONS; my $expected; plan( 5 ); $expected = [ undef, $DEFAULT ]; is( [ $METHOD_REF->( [], $DEFAULT ) ], $expected, 'trailing arguments omitted' ); $expected = [ undef, $DEFAULT, 'title' ]; is( [ $METHOD_REF->( [ 'title' ], $DEFAULT ) ], $expected, 'options omitted, title supplied' ); subtest 'options supplied' => sub { plan( 2 ); ( $diag, %options ) = ( 'ERROR' ); $expected = [ $diag ]; is( [ $METHOD_REF->( [ { X => 0 } ], $DEFAULT ) ], $expected, 'invalid option detected' ); ( $diag, %options ) = ( undef, SIZE_ONLY => 1 ); $expected = [ $diag, { %$DEFAULT, %options }, 'title' ]; is( [ $METHOD_REF->( [ \%options, 'title' ], $DEFAULT ) ], $expected, 'options updated' ); }; my $filter = sub {}; ( $diag, %options ) = ( undef, FILTER => $filter ); $expected = [ undef, { %$DEFAULT, %options }, 'title' ]; is ( [ $METHOD_REF->( [ $filter, 'title' ], $DEFAULT ) ], $expected, 'filter and title supplied, options updated' ); $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'hash reference / code reference / string', '3rd' ); like( $METHOD_REF->( [ [] ], $DEFAULT ), qr/$expected/, 'invalid argument type' ); Test-Files-0.24/t/Test/Files/_dir_contains_ok.t0000644000175100017540000000573314567175115020414 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; use Test::Files::Constants qw( $FMT_ABSENT $FMT_FAILED_TO_SEE $FMT_UNEXPECTED ); const my $MISSING_FILE => 'MISSING_FILE'; my $expected; { my $mockThis = mock $CLASS => ( override => [ _validate_args => sub { 'ERROR' } ] ); is( $METHOD_REF->( $TEMP_DIR, [] ), [ 'ERROR' ], 'invalid arguments' ); } const my @EXISTING_FILES => qw( file0 file1 subdir/file2 subdir/file3 ); foreach my $file ( map { [ split( m{/} ) ] } @EXISTING_FILES ) { path( $TEMP_DIR )->child( @$file[ 0 .. ( $#$file - 1 ) ] )->mkdir if $#$file; path( $TEMP_DIR )->child( @$file )->touch; } const my $SPECIAL_FILE => 'special_file'; SKIP: { const my $UNTESTABLE_OS => $^O eq 'MSWin32' || !path( '/dev/null' )->exists; skip "$^O does not support special device files" if $UNTESTABLE_OS; symlink( '/dev/null', path( $TEMP_DIR )->child( $SPECIAL_FILE ) ); $expected = [ [ sprintf( $FMT_FAILED_TO_SEE, path( $TEMP_DIR )->child( $MISSING_FILE ) ) ], [ map { path( $_ ) } @EXISTING_FILES ], ]; is( [ $METHOD_REF->( $TEMP_DIR, [ @EXISTING_FILES, $MISSING_FILE ], { EXISTENCE_ONLY => 1, RECURSIVE => 1 } ) ], $expected, 'check existence only with special file, name pattern omitted' ); $expected = [ [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $SPECIAL_FILE ) ) ], [ map { /[01]/ ? path( $_ ) : () } @EXISTING_FILES ], ]; is( [ $METHOD_REF->( $TEMP_DIR, \@EXISTING_FILES, { NAME_PATTERN => '[01]', RECURSIVE => 1 } ) ], $expected, 'check something but existence with special file, specify name pattern' ); } const my $UNACCESSIBLE_FILE => 'UNACCESSIBLE'; const my $UNEXPECTED_FILE => 'UNEXPECTED'; path( $TEMP_DIR )->child( $_ )->touch foreach $UNACCESSIBLE_FILE, $UNEXPECTED_FILE; path( $TEMP_DIR )->child( $SPECIAL_FILE )->remove; my $mockPathTiny = mock 'Path::Tiny' => ( override => [ stat => sub {} ] ); $mockPathTiny->override( stat => sub { my $orig = $mockPathTiny->orig( 'stat' ); $_[ 0 ]->basename eq $UNACCESSIBLE_FILE ? undef : $_[ 0 ]->$orig; } ); $expected = [ [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $UNACCESSIBLE_FILE ) ), sprintf( $FMT_UNEXPECTED, path( $TEMP_DIR )->child( $UNEXPECTED_FILE ) ), ], [ map { path( $_ ) } @EXISTING_FILES ], ]; is( [ $METHOD_REF->( $TEMP_DIR, \@EXISTING_FILES, { EXISTENCE_ONLY => 1, RECURSIVE => 1, SYMMETRIC => 1 } ) ], $expected, 'detect supefluous file in symmetric approach, name pattern omitted' ); path( $TEMP_DIR )->child( $_ )->touch foreach $UNACCESSIBLE_FILE, $UNEXPECTED_FILE; $expected = [ [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $UNACCESSIBLE_FILE ) ) ], [ map { path( $_ ) } @EXISTING_FILES ], ]; is( [ $METHOD_REF->( $TEMP_DIR, \@EXISTING_FILES, { EXISTENCE_ONLY => 1, RECURSIVE => 1 } ) ], $expected, 'detect unaccessible file, name pattern omitted' ); done_testing(); Test-Files-0.24/t/Test/Files/_validate_args.t0000644000175100017540000000267514561716561020056 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; use Test::Files::Constants qw( $FMT_INVALID_ARGUMENT $FMT_INVALID_DIR $FMT_UNDEF ); const my $MISSING_FILE => 'MISSING_FILE'; plan( 6 ); my ( $expected, $valid_trailing_args ); my $mockThis = mock $CLASS => ( override => [ _validate_trailing_args => sub { $valid_trailing_args ? () : 'ARG ERROR' } ] ); $valid_trailing_args = undef; is( $METHOD_REF->( 'ARRAY', $TEMP_DIR, [] ), 'ARG ERROR', 'invalid options' ); $valid_trailing_args = 1; $expected = sprintf( $FMT_UNDEF, '\$dir', '.+' ); like( $METHOD_REF->( 'ARRAY', undef, [] ), qr/$expected/, 'directory undefined' ); $expected = sprintf( $FMT_INVALID_DIR, path( $TEMP_DIR )->child( $MISSING_FILE ) ); like( $METHOD_REF->( 'ARRAY', path( $TEMP_DIR )->child( $MISSING_FILE ), [] ), qr/$expected/, 'not a directory' ); $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'array reference', '2nd' ); like( $METHOD_REF->( 'ARRAY', $TEMP_DIR, {} ), qr/$expected/, 'file list has a wrong type' ); $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'code reference', '2nd' ); like( $METHOD_REF->( 'CODE', $TEMP_DIR, {} ), qr/$expected/, 'code reference has a wrong type' ); $expected = [ undef, path( $TEMP_DIR ), [], undef, undef ]; is( [ $METHOD_REF->( 'ARRAY', $TEMP_DIR, [] ) ], $expected, 'arguments are valid' ); Test-Files-0.24/t/Test/Files/_show_result.t0000644000175100017540000000101314462241450017576 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Builder::Tester tests => 2; use Test::Expander; my $mock_this = mock $CLASS => ( override => [ _show_failure => sub {} ] ); my $title; $title = 'success reported'; test_out( "ok 1 - $title" ); $METHOD_REF->( 1, $title ); test_test( title => $title ); $title = 'failure reported'; test_out(); $METHOD_REF->( 0, $title ); test_test( title => $title ); Test-Files-0.24/t/Test/Files/dir_contains_ok.t0000644000175100017540000000117714561716635020255 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $diag; my $mockThis = mock $CLASS => ( override => [ _dir_contains_ok => sub { [] }, _show_failure => sub { $_[ 1 ] }, _show_result => sub {}, _validate_trailing_args => sub { ( $diag, {} ) }, ] ); plan( 2 ); $diag = undef; is( $METHOD_REF->( 'dir', [ 'file' ] ), $diag, 'comparison performed' ); $diag = 'ERROR'; is( $METHOD_REF->( 'dir', [ 'file' ] ), $diag, 'invalid arguments, comparison rejected' ); Test-Files-0.24/t/Test/Files/_compare_dirs.t0000644000175100017540000000304314561716437017710 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempdir => {}; my ( $diag, $error, $expected, $file_list ); my $mock_this = mock $CLASS => ( override => [ _compare_files => sub { [] }, _dir_contains_ok => sub { ( [], $file_list ) }, _get_two_files_info => sub { $error }, _show_failure => sub { pass( 'failure reported' ); return }, _show_result => sub { is( !!shift, !!$expected, 'result reported' ); return }, _validate_trailing_args => sub { $diag }, ] ); plan( 5 ); subtest 'trailing arguments invalid' => sub { plan( 2 ); $diag = 'ERROR'; is( $METHOD_REF->(), undef, 'comparison performed' ); }; $diag = undef; subtest 'first directory undefined' => sub { plan( 2 ); is( $METHOD_REF->(), undef, 'comparison performed' ); }; subtest 'second directory undefined' => sub { plan( 2 ); is( $METHOD_REF->( 'FIRST_DIR' ), undef, 'comparison performed' ); }; path( $TEMP_DIR )->child( 'SUBDIR' )->mkdir; path( $TEMP_DIR )->child( 'PLAIN_FILE' )->touch; ( $error, $expected, $file_list ) = ( [], 1, [ 'file' ] ); subtest 'directories identical' => sub { plan( 2 ); is( $METHOD_REF->( 'FIRST_DIR', $TEMP_DIR ), undef, 'comparison performed' ); }; ( $error, $expected, $file_list ) = ( [ 'ERROR' ], 0, [ 'file' ] ); subtest 'differences detected' => sub { plan( 2 ); is( $METHOD_REF->( 'FIRST_DIR', $TEMP_DIR ), undef, 'comparison performed' ); }; Test-Files-0.24/t/.perlcriticrc0000644000175100017540000002320414566672272015426 0ustar jurijjurij# You may disable specific policies appending the following annotation # # ## no critic (..., ...) # # to the corresponding code line. To direct perlcritic to ignore the # "## no critic" annotations, use the --force option. # Policies shipped with Perl::Critic 1.125 were considered for the below # defintion of the new policy theme "critic". severity = brutal theme = critic verbose = %f: %m at line %l, column %c. (Policy: %p)\n [Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval] add_themes = critic allow_includes = 1 [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitUselessTopic] # KNOWN BUGS: This policy flags a false positive on reverse() called in list # context, since reverse() in list context does not assume $_. add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap] add_themes = critic [Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock] add_themes = critic [Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA] # Note: Some people prefer parent over base. add_themes = critic [Perl::Critic::Policy::CodeLayout::ProhibitHardTabs] add_themes = critic allow_leading_tabs = 0 [Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace] add_themes = critic [Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines] add_themes = critic [Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops] add_themes = critic [Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse] add_themes = critic max_elsif = 1 [Perl::Critic::Policy::ControlStructures::ProhibitDeepNests] # Martin Fowler's book "Refactoring: Improving The Design of Existing Code". add_themes = critic max_nests = 5 [Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames] add_themes = critic [Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions] # Read the LIMITATIONS that this policy has. add_themes = critic [Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions] add_themes = critic [Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode] add_themes = critic [Perl::Critic::Policy::Documentation::PodSpelling] add_themes = [Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators] add_themes = critic only_in_void_context = 1 [Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitInteractiveTest] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop] add_themes = critic [Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen] add_themes = critic [Perl::Critic::Policy::InputOutput::RequireBriefOpen] # http://www.perlmonks.org/?node_id=1134785 add_themes = critic lines = 9 [Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls] # Covers the policies # Perl::Critic::Policy::InputOutput::RequireCheckedClose and # Perl::Critic::Policy::InputOutput::RequireCheckedOpen add_themes = critic exclude_functions = print say symlink functions = :builtins [Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer] add_themes = critic [Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic] add_themes = critic [Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic] add_themes = critic [Perl::Critic::Policy::Modules::ProhibitAutomaticExportation] add_themes = critic [Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements] add_themes = critic [Perl::Critic::Policy::Modules::ProhibitEvilModules] add_themes = critic modules = Class::ISA Error Pod::Plainer Shell Switch [Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = critic max_mccabe = 20 [Perl::Critic::Policy::Modules::ProhibitMultiplePackages] add_themes = critic [Perl::Critic::Policy::Modules::RequireBarewordIncludes] add_themes = critic #[Perl::Critic::Policy::Modules::RequireEndWithOne] #add_themes = critic [Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage] add_themes = critic [Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish] add_themes = critic [Perl::Critic::Policy::Objects::ProhibitIndirectSyntax] add_themes = critic # The new() subroutine is configured by default; any additional forbid values # are in addition to new(). forbid = create destroy [Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches] add_themes = critic [Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation] add_themes = critic [Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture] add_themes = critic [Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters] add_themes = critic allow_all_brackets = 0 [Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic] add_themes = critic [Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline] add_themes = critic allow_all_brackets = 0 [Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils] add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms] # Read the CAVEATS. add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = critic max_mccabe = 20 [Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef] # http://perlmonks.org/index.pl?node_id=741847 add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitManyArgs] add_themes = critic max_arguments = 5 [Perl::Critic::Policy::Subroutines::ProhibitNestedSubs] add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitReturnSort] # KNOWN BUGS: This Policy is not sensitive to the wantarray() function. add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes] add_themes = critic [Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines] add_themes = critic [Perl::Critic::Policy::Subroutines::ProtectPrivateSubs] add_themes = critic [Perl::Critic::Policy::Subroutines::RequireArgUnpacking] add_themes = critic allow_delegation_to = SUPER:: NEXT:: allow_subscripts = 0 short_subroutine_statements = 0 [Perl::Critic::Policy::Subroutines::RequireFinalReturn] add_themes = critic terminal_funcs = return carp croak die exec exit goto throw [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict] add_themes = critic allow = refs [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings] add_themes = critic allow_with_category_restriction = 1 [Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride] add_themes = critic statements = 3 [Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict] add_themes = critic [Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings] add_themes = critic [Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals] add_themes = critic allow_if_string_contains_single_quote = 1 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros] add_themes = critic [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls] add_themes = critic max_chain_length = 3 #[Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers] # Not yet configured completely. #add_themes = critic #allowed_values = -1 0 1 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators] add_themes = critic [Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters] add_themes = critic back_quote_allowed_operators = double_quote_allowed_operators = single_quote_allowed_operators = [Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator] add_themes = critic [Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion] add_themes = critic allow_version_without_use_on_same_line = 1 [Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators] add_themes = critic min_value = 10000 [Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator] add_themes = critic [Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator] add_themes = critic [Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations] add_themes = critic [Perl::Critic::Policy::Variables::ProhibitLocalVars] add_themes = critic [Perl::Critic::Policy::Variables::ProhibitMatchVars] add_themes = critic [Perl::Critic::Policy::Variables::ProhibitUnusedVariables] add_themes = critic [Perl::Critic::Policy::Variables::RequireInitializationForLocalVars] add_themes = critic [Perl::Critic::Policy::Variables::RequireLexicalLoopIterators] add_themes = critic [Perl::Critic::Policy::Variables::RequireLocalizedPunctuationVars] add_themes = critic allow = [Perl::Critic::Policy::Variables::RequireNegativeIndices] add_themes = critic Test-Files-0.24/t/.proverc-cover0000644000175100017540000000003214457161713015517 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.24/t/.proverc0000644000175100017540000000003214457161677014414 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.24/lib/0000755000175100017540000000000014567202320013222 5ustar jurijjurijTest-Files-0.24/lib/.perlcriticrc0000644000175100017540000002653514140010270015707 0ustar jurijjurij# You may disable specific policies appending the following annotation # # ## no critic (..., ...) # # to the corresponding code line. To direct perlcritic to ignore the # "## no critic" annotations, use the --force option. # Policies shipped with Perl::Critic 1.125 were considered for the below # defintion of the new policy theme "knib". severity = brutal theme = knib verbose = %f: %m at line %l, column %c. (Policy: %p)\n [Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval] add_themes = knib allow_includes = 1 [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitUselessTopic] # KNOWN BUGS: This policy flags a false positive on reverse() called in list # context, since reverse() in list context does not assume $_. add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap] add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[BuiltinFunctions::RequireGlobFunction] #add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock] add_themes = knib [Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA] # Note: Some people prefer parent over base. add_themes = knib [Perl::Critic::Policy::CodeLayout::ProhibitHardTabs] add_themes = knib allow_leading_tabs = 0 # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists] #add_themes = knib #min_elements = 1 #strict = 1 [Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace] add_themes = knib [Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines] add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::CodeLayout::RequireTrailingCommas] #add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse] add_themes = knib max_elsif = 1 [Perl::Critic::Policy::ControlStructures::ProhibitDeepNests] # Martin Fowler's book "Refactoring: Improving The Design of Existing Code". add_themes = knib max_nests = 5 [Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions] # Read the LIMITATIONS that this policy has. add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode] add_themes = knib # Available With Perl::Critic v1.126 #[Perl::Critic::Policy::ControlStructures::ProhibitYadaOperator] #add_themes = knib [Perl::Critic::Policy::Documentation::PodSpelling] add_themes = # "spell" is the spell checker avalable on our AIX system. The default spell # checker "aspell" was not available. spell_command = spell #stop_words = ... stop_words_file = PodSpelling_stop_words.txt [Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName] add_themes = knib #[Perl::Critic::Policy::Documentation::RequirePodSections] #add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval] #add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators] add_themes = knib # 14.01.2016 policy configuration changed after a discussion with the team only_in_void_context = 1 [Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitInteractiveTest] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen] add_themes = knib [Perl::Critic::Policy::InputOutput::RequireBriefOpen] # http://www.perlmonks.org/?node_id=1134785 add_themes = knib lines = 9 [Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls] # Covers the policies # Perl::Critic::Policy::InputOutput::RequireCheckedClose and # Perl::Critic::Policy::InputOutput::RequireCheckedOpen add_themes = knib exclude_functions = print say functions = :builtins [Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer] add_themes = knib [Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic] add_themes = knib [Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitAutomaticExportation] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitEvilModules] add_themes = knib modules = Class::ISA Error Pod::Plainer Shell Switch [Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = knib max_mccabe = 20 [Perl::Critic::Policy::Modules::ProhibitMultiplePackages] add_themes = knib [Perl::Critic::Policy::Modules::RequireBarewordIncludes] add_themes = knib [Perl::Critic::Policy::Modules::RequireEndWithOne] add_themes = knib [Perl::Critic::Policy::Modules::RequireExplicitPackage] add_themes = knib allow_import_of = utf8 exempt_scripts = 0 [Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage] add_themes = knib [Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish] add_themes = knib [Perl::Critic::Policy::Modules::RequireVersionVar] # Read the TO DO section of this policy and think about its implication. add_themes = knib # Perl::Critic::Policy::NamingConventions::Capitalization # It takes some time to configure this policy! [Perl::Critic::Policy::Objects::ProhibitIndirectSyntax] add_themes = knib # The new() subroutine is configured by default; any additional forbid values # are in addition to new(). forbid = create destroy [Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches] add_themes = knib [Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation] add_themes = knib [Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture] add_themes = knib # 14.01.2016 policy still enabled after a discussion with the team [Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters] add_themes = knib allow_all_brackets = 0 [Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic] add_themes = knib [Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline] add_themes = knib allow_all_brackets = 0 [Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms] # Read the CAVEATS. add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = knib max_mccabe = 20 [Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef] # http://perlmonks.org/index.pl?node_id=741847 add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitManyArgs] add_themes = knib max_arguments = 5 [Perl::Critic::Policy::Subroutines::ProhibitNestedSubs] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitReturnSort] # KNOWN BUGS: This Policy is not sensitive to the wantarray() function. add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines] add_themes = knib [Perl::Critic::Policy::Subroutines::ProtectPrivateSubs] add_themes = knib #[Perl::Critic::Policy::Subroutines::RequireArgUnpacking] #add_themes = knib #allow_delegation_to = SUPER:: NEXT:: #allow_subscripts = 0 #short_subroutine_statements = 0 [Perl::Critic::Policy::Subroutines::RequireFinalReturn] add_themes = knib terminal_funcs = return carp croak die exec exit goto throw [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict] add_themes = knib allow = refs [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings] add_themes = knib allow_with_category_restriction = 1 [Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride] add_themes = knib statements = 3 # The following policy seems to have a bug for the ok() test. #[Perl::Critic::Policy::TestingAndDebugging::RequireTestLabels] #add_themes = knib #modules = Test::Exception Test::More [Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict] add_themes = knib [Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals] add_themes = knib allow_if_string_contains_single_quote = 1 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls] add_themes = knib max_chain_length = 3 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers] # Not yet configured completely. add_themes = knib # 14.01.2016 2 is considered a magic number as well after a discussion with the team allowed_values = -1 0 1 # 11.02.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators] #add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters] add_themes = knib back_quote_allowed_operators = double_quote_allowed_operators = single_quote_allowed_operators = [Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion] add_themes = allow_version_without_use_on_same_line = 1 [Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators] add_themes = knib min_value = 10000 [Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitLocalVars] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitMatchVars] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitUnusedVariables] add_themes = knib [Perl::Critic::Policy::Variables::RequireInitializationForLocalVars] add_themes = knib [Perl::Critic::Policy::Variables::RequireLexicalLoopIterators] add_themes = knib [Perl::Critic::Policy::Variables::RequireLocalizedPunctuationVars] add_themes = knib allow = [Perl::Critic::Policy::Variables::RequireNegativeIndices] add_themes = knib Test-Files-0.24/lib/Test/0000755000175100017540000000000014567202320014141 5ustar jurijjurijTest-Files-0.24/lib/Test/Files.pm0000644000175100017540000003163314567202036015553 0ustar jurijjurijpackage Test::Files; our $VERSION = '0.24'; ## no critic (RequireUseStrict, RequireUseWarnings) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline portable recursion ); use Cwd qw( abs_path ); use Data::Compare qw( Compare ); use Exporter qw( import ); use Fcntl qw( :mode ); use Path::Tiny qw( path ); use Test::Builder; use Text::Diff qw( diff ); use Test::Files::Constants qw( $CONTAINER_OPTIONS $DIRECTORY_OPTIONS $EXPECTED_CONTENT $FMT_ABSENT $FMT_ABSENT_WITH_ERROR $FMT_DIFFERENT_SIZE $FMT_FAILED_TO_SEE $FMT_FILTER_ISNT_CODEREF $FMT_FIRST_FILE_ABSENT $FMT_INVALID_ARGUMENT $FMT_INVALID_DIR $FMT_INVALID_NAME_PATTER $FMT_INVALID_OPTIONS $FMT_SECOND_FILE_ABSENT $FMT_SUB_FAILED $FMT_UNDEF $FMT_UNEXPECTED $FILE_OPTIONS $UNKNOWN %DIFF_OPTIONS ); ## no critic (ProhibitAutomaticExportation) our @EXPORT = qw( compare_dirs_filter_ok compare_dirs_ok compare_filter_ok compare_ok dir_contains_ok dir_only_contains_ok file_filter_ok file_ok find_ok ); my $Test = Test::Builder->new; sub compare_dirs_filter_ok { my ( $got_dir, $expected_dir, $filter, $name ) = @_; my $options = { FILTER => $filter }; my ( $diag ) = _validate_options( $options, $DIRECTORY_OPTIONS ); return $diag ? _show_failure( $name, $diag ) : _compare_dirs( $got_dir, $expected_dir, $options, $name ); } sub compare_dirs_ok { my ( $got_dir, $expected_dir, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return $diag ? _show_failure( $name, $diag ) : _compare_dirs( $got_dir, $expected_dir, $options, $name ); } sub compare_filter_ok { my ( $got_file, $expected_file, $filter, $name ) = @_; return _compare_ok( $got_file, $expected_file, { %$FILE_OPTIONS, FILTER => $filter }, $name ); } sub compare_ok { return _compare_ok( @_ ) } sub dir_contains_ok { my ( $dir, $file_list, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return _show_failure( $name, $diag ) if $diag; ( $diag ) = _dir_contains_ok( $dir, $file_list, { %$options, EXISTENCE_ONLY => 1 }, $name ); return _show_result( !@$diag, $name, @$diag ); } sub dir_only_contains_ok { my ( $dir, $file_list, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return _show_failure( $name, $diag ) if $diag; ( $diag ) = _dir_contains_ok( $dir, $file_list, { %$options, EXISTENCE_ONLY => 1, SYMMETRIC => 1 }, $name ); return _show_result( !@$diag, $name, @$diag ); } sub file_filter_ok { my ( $file, $expected_string, $filter, $name ) = @_; return _compare_ok( $file, \$expected_string, { %$FILE_OPTIONS, FILTER => $filter }, $name ); } sub file_ok { my ( $file, $expected_string, @rest ) = @_; return _compare_ok( $file, \$expected_string, @rest ); } sub find_ok { my ( $diag, $dir, $sub, $options, $name ) = _validate_args( 'CODE', @_ ); return _show_failure( $name, $diag ) if $diag; $diag = []; my $match = sub { push( @$diag, $_ ) if $_->is_file && !$sub->( "$_" ) }; path( $dir )->visit( $match, { recurse => $options->{ RECURSIVE } } ); return _show_result( !@$diag, $name, sprintf( $FMT_SUB_FAILED, join( "', ", sort @$diag ) ) ); } sub _compare_dirs { my ( $got_dir, $expected_dir, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return _show_failure( $name, $diag ) if $diag; return _show_failure( $name, sprintf( $FMT_UNDEF, '$got_dir', _get_caller_sub() ) ) unless defined( $got_dir ); return _show_failure( $name, sprintf( $FMT_UNDEF, '$expected_dir', _get_caller_sub() ) ) unless defined( $expected_dir ); my $expected_file_list = []; path( $expected_dir )->visit( sub { push( @$expected_file_list, $_->relative( $expected_dir ) ) unless $_->is_dir }, { recurse => $options->{ RECURSIVE } }, ); my $file_list; ( $diag, $file_list ) = _dir_contains_ok( $got_dir, $expected_file_list, $options, $name ); $got_dir = path( $got_dir ); $expected_dir = path( $expected_dir ); foreach my $file ( @$file_list ) { my $got_file = $got_dir ->child( $file ); my $expected_file = $expected_dir->child( $file ); my ( $error, $got_info, $expected_info ) = _get_two_files_info( $got_file, $expected_file, $options ); push( @$diag, @$error ? @$error : @{ _compare_files( $got_info, $expected_info, $options, $got_file, $expected_file ) } ); } return _show_result( !@$diag, $name, sort @$diag ); } sub _compare_files { my ( $got_data, $expected_data, $options, $got_file, $expected_file ) = @_; if ( $options->{ EXISTENCE_ONLY } ) { return [ sprintf( $FMT_SECOND_FILE_ABSENT, $got_file, $expected_file ) ] unless $got_data; return [ sprintf( $FMT_FIRST_FILE_ABSENT, $got_file, $expected_file ) ] unless $expected_data; return []; } if ( $options->{ SIZE_ONLY } ) { return $got_data == $expected_data ? [] : [ sprintf( $FMT_DIFFERENT_SIZE, $got_file, $expected_file, $got_data, $expected_data ) ]; } my %diff_options = ( %DIFF_OPTIONS, map { $_ eq 'STYLE' ? ( $_ => $options->{ $_ } ) : () } keys( %$options ) ); chomp( my $diff = diff( \$got_data, \$expected_data, { %diff_options, FILENAME_A => $got_file, FILENAME_B => $expected_file } ) ); return $diff eq '' ? [] : [ $diff ]; } sub _compare_ok { my ( $got_file, $expected_file, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $FILE_OPTIONS ); return _show_failure( $name, $diag ) if $diag; my ( $got, $expected ); ( $diag, $got, $expected ) = _get_two_files_info( $got_file, $expected_file, $options, qw( $got_file $expected_file ) ); return _show_failure( $name, @$diag ) if @$diag; my $diff = _compare_files( $got, $expected, $options, $got_file, ref( $expected_file ) ? $EXPECTED_CONTENT : $expected_file ); return _show_result( !@$diff, $name, @$diff ); } # Verifies if the directory (1st parameter) contains all files from the file list (2nd parameter). # If symmetric approach is required inside of option hash passed by reference (3rd parameter), # also verifies if the directory does not contain any other files. # If a certain file name pattern is required inside of option hash, files not matching this pattern are skipped. # Subdirectories are not involved in the verification, but files located therein are considered # if recursive appraoch is required inside of option hash. # Special files like named pipes are involved in the verification only # if the sole file existence is required inside of option hash, # otherwise they are skipped and reported as error. # Returns two references to: # 1. Sorted array of detected errors. # 2. Sorted array of files found in the directory and matching all requirements. sub _dir_contains_ok { my ( $diag, $dir, $file_list, $options, $name ) = _validate_args( 'ARRAY', @_ ); return [ $diag ] if $diag; my $name_pattern = $options->{ NAME_PATTERN }; $name_pattern = qr/$name_pattern/; my ( $existence_only, $symmetric ) = @$options{ qw( EXISTENCE_ONLY SYMMETRIC ) }; my $detected = []; my %file_list = map { $_ => 1 } @$file_list; $diag = []; my $matches = sub { my ( $file ) = @_; my $file_stat = eval { $file->stat }; return push( @$diag, sprintf( $FMT_ABSENT, $file ) ) unless $file_stat; return if S_ISDIR( $file_stat->mode ); return push( @$diag, sprintf( $FMT_ABSENT, $file ) ) if $file_stat->rdev && !$existence_only; my $relative_name = $file->relative( $dir ); if ( exists( $file_list{ $relative_name } ) ) { delete( $file_list{ $relative_name } ); push( @$detected, $relative_name ) if $relative_name =~ $name_pattern; return; } return push( @$diag, sprintf( $FMT_UNEXPECTED, $file ) ) if $symmetric; return; }; path( abs_path( $dir ) )->visit( $matches, { recurse => $options->{ RECURSIVE } } ); push( @$diag, sprintf( $FMT_FAILED_TO_SEE, $dir->child( $_ ) ) ) foreach grep { /$name_pattern/ } keys( %file_list ); return ( [ sort @$diag ], [ sort @$detected ] ); } sub _get_caller_sub { # Identify closest public caller subroutine my $caller_sub; for ( my $depth = 1; ; ++$depth ) { ## no critic (ProhibitCStyleForLoops) ( undef, undef, undef, $caller_sub ) = caller( $depth ); last unless defined( $caller_sub ) && $caller_sub =~ /\b_/; } return defined( $caller_sub ) ? $caller_sub : $UNKNOWN; } sub _get_file_info { my ( $file, $options, $arg_name ) = @_; return ( sprintf( $FMT_UNDEF, $arg_name, _get_caller_sub() ), undef ) unless defined( $file ); my $is_real_file = ref( $file ) ne 'SCALAR'; my $file_stat; if ( $is_real_file ) { # File name supplied $file = path( $file ); $file_stat = eval { $file->stat }; # Error if file is absent or is not a plain one return ( sprintf( $FMT_ABSENT, $file ), undef ) if !$file_stat || S_ISDIR( $file_stat->mode ) || $file_stat->rdev && !$options->{ EXISTENCE_ONLY }; } return ( undef, 1 ) if $options->{ EXISTENCE_ONLY }; return ( undef, $is_real_file ? $file_stat->size : length( $$file ) ) if $options->{ SIZE_ONLY }; local $. = 0; my $filter = $options->{ FILTER }; my $content = $is_real_file ? eval { $filter ? join( '', map { ++$.; my $filtered = $filter->( $_ ); defined( $filtered ) ? $filtered : () } $file->lines ) : $file->slurp } : $$file; my $diag = $@ ? sprintf( $FMT_ABSENT_WITH_ERROR, $file, $@ ) : undef; return ( $diag, $content ); } sub _get_two_files_info { my ( $got_file, $expected_file, $options, $got_name, $expected_name ) = @_; my ( $got_diag, $got_data ) = _get_file_info( $got_file, $options, $got_name ); my ( $expected_diag, $expected_data ) = _get_file_info( $expected_file, $options, $expected_name ); return ( [ defined( $got_diag ) ? $got_diag : (), defined( $expected_diag ) ? $expected_diag : () ], $got_data, $expected_data ); } sub _show_failure { my ( $name, @message ) = @_; $Test->ok( 0, $name ); $Test->diag( join( "\n", @message, '' ) ); return; } sub _show_result { my ( $success, $name, @message ) = @_; return $success ? $Test->ok( 1, $name ) : _show_failure( $name, @message ); } sub _validate_args { my ( $expected_type, $dir, $file_list_or_sub, @rest ) = @_; my ( $diag, $options, $name ) = _validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return $diag if $diag; return sprintf( $FMT_UNDEF, '$dir', _get_caller_sub() ) unless defined( $dir ); $dir = path( $dir ); return sprintf( $FMT_INVALID_DIR, $dir ) unless $dir->is_dir; return sprintf( $FMT_INVALID_ARGUMENT, _get_caller_sub(), ( $expected_type eq 'ARRAY' ? 'array' : 'code' ) . ' reference', '2nd' ) if ref( $file_list_or_sub ) ne $expected_type; return ( undef, $dir, $file_list_or_sub, $options, $name ); } sub _validate_options { my ( $options, $default ) = @_; my @invalid_options = grep { !exists( $default->{ $_ } ) } keys( %$options ); return sprintf( $FMT_INVALID_OPTIONS, join( "', '", @invalid_options ) ) if @invalid_options; if ( defined( $options->{ FILTER } ) ) { return sprintf( $FMT_FILTER_ISNT_CODEREF, _get_caller_sub() ) if ref( $options->{ FILTER } ) ne 'CODE'; } else { $options->{ FILTER } = $default->{ FILTER }; } if ( exists( $default->{ NAME_PATTERN } ) ) { if ( defined( $options->{ NAME_PATTERN } ) ) { eval { qr/$options->{ NAME_PATTERN }/ }; my $error = $@; return sprintf( $FMT_INVALID_NAME_PATTER, $options->{ NAME_PATTERN }, _get_caller_sub(), $error ) if $error; } else { $options->{ NAME_PATTERN } = $default->{ NAME_PATTERN }; } } return ( undef, %$default, %$options ); } sub _validate_trailing_args { my ( $args, $default ) = @_; return ( undef, $default ) unless @$args; # 1st trailing arg omitted: use default options, no title my ( $first_arg, $second_arg ) = @$args; my $first_arg_type = ref( $first_arg ); return ( undef, $default, $first_arg ) # Scalar: use default options and 3rd param as title unless $first_arg_type; if ( $first_arg_type eq 'HASH' ) { # Hash reference: forward both options and title my ( $diag, %options ) = _validate_options( $first_arg, $default ); return $diag ? ( $diag ) : ( undef, { %$default, %options }, $second_arg ) } return ( undef, { %$default, FILTER => $first_arg }, $second_arg ) if $first_arg_type eq 'CODE'; # Code reference: forward filter as option and title # Invalid type return sprintf( $FMT_INVALID_ARGUMENT, _get_caller_sub(), 'hash reference / code reference / string', '3rd' ); } 1; Test-Files-0.24/lib/Test/Files.pod0000644000175100017540000004622614566725741015741 0ustar jurijjurij=head1 NAME B - A L based module to ease testing with files and dirs. In general, the following can be tested: =over 2 =item If the contents of the file being tested match the expected pattern. =item If the file being tested is identical to the expected file in regard to contents, or size, or existence. If necessary, some parts of the contents can be excluded from the comparison. =item If the directory being tested contains all expected files. =item If the files in the directory being tested are identical to the files in the reference directory in regard to contents, or size, or existence. If necessary, some files as well as some parts of contents can be excluded from the comparison. =item If all files in the directory being tested fulfill certain requirements. =back =head1 SYNOPSIS All examples listed below can be found and executed using B. use Path::Tiny qw( path ); use Test::Files; my $got_file = path( 'path' )->child( qw( got file ) ); my $reference_file = path( 'path' )->child( qw( reference file ) ); my $got_dir = path( 'path' )->child( qw( got dir ) ); my $reference_dir = path( 'path' )->child( qw( reference dir with some stuff ) ); my @file_list = qw( expected file ); my ( $content_check, $expected, $filter, $options ); plan( 22 ); # Simply compares file contents to a string: $expected = "contents\nof file"; file_ok( $got_file, $expected, 'got file has expected contents' ); # Two identical variants comparing file contents # to a string ignoring differences in time stamps: $expected = "filtered contents\nof file\ncreated at 00:00:00"; $filter = sub { shift =~ s{ \b (?: [01] \d | 2 [0-3] ) : (?: [0-5] \d ) : (?: [0-5] \d ) \b } {00:00:00}grx }; $options = { FILTER => $filter }; file_ok ( $got_file, $expected, $options, "'$got_file' has contents expected after filtering" ); file_filter_ok( $got_file, $expected, $filter, "'$got_file' has contents expected after filtering" ); # Simply compares two file contents: compare_ok( $got_file, $reference_file, 'files are the same' ); # Two identical variants comparing contents of two files # ignoring differences in time stamps: $filter = sub { shift =~ s{ \b (?: [01] \d | 2 [0-3] ) : (?: [0-5] \d ) : (?: [0-5] \d ) \b } {00:00:00}grx }; $options = { FILTER => $filter }; compare_ok ( $got_file, $reference_file, $options, 'files are almost the same' ); compare_filter_ok( $got_file, $reference_file, $filter, 'files are almost the same' ); # Verifies if both got file and reference file exist: $options = { EXISTENCE_ONLY => 1 }; compare_ok( $got_file, $reference_file, $options, 'both files exist' ); # Verifies if got file and reference file have identical size: $options = { SIZE_ONLY => 1 }; compare_ok( $got_file, $reference_file, $options, 'both files have identical size' ); # Verifies if the directory has all expected files (not recursively!): $expected = [ qw( files got_dir must contain ) ]; dir_contains_ok( $got_dir, $expected, 'directory has all files in list' ); # Two identical variants doing the same verification as before, # but additionally verifying if the directory has nothing # but the expected files (not recursively!): $options = { SYMMETRIC => 1 }; dir_contains_ok ( $got_dir, $expected, $options, 'directory has exactly the files in the list' ); dir_only_contains_ok( $got_dir, $expected, 'directory has exactly the files in the list' ); # The same as before, but recursive: $options = { RECURSIVE => 1, SYMMETRIC => 1 }; dir_contains_ok( $got_dir, $expected, $options, 'directory and its subdirectories have exactly the files in the list' ); # The same as before, but ignoring files, # which names do not match the required pattern (file "must" will be skipped): $options = { NAME_PATTERN => '^[cfg]', RECURSIVE => 1, SYMMETRIC => 1 }; dir_contains_ok( $got_dir, $expected, $options, 'directory and its subdirectories ' . "have exactly the files in the list except of file 'must'" ); # Compares two directories by comparing file contents (not recursively!): compare_dirs_ok( $got_dir, $reference_dir, "all files from '$got_dir' are the same in '$reference_dir' " . '(same names, same contents), subdirs are skipped' ); # The same as before, but subdirectories are considered, too: $options = { RECURSIVE => 1 }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' and its subdirs are the same in '$reference_dir'" ); # The same as before, but only file sizes are compared: $options = { RECURSIVE => 1, SIZE_ONLY => 1 }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' and its subdirs have same sizes in '$reference_dir'" ); # The same as before, but only file existence is verified: $options = { EXISTENCE_ONLY => 1, RECURSIVE => 1 }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' and its subdirs exist in '$reference_dir'" ); # The same as before, but only files with base names starting with 'A' are considered: $options = { EXISTENCE_ONLY => 1, NAME_PATTERN => '^A', RECURSIVE => 1 }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' and its subdirs " . "with base names starting with 'A' exist in '$reference_dir'" ); # The same as before, but the symmetric verification is requested: $options = { EXISTENCE_ONLY => 1, NAME_PATTERN => '^A', RECURSIVE => 1, SYMMETRIC => 1, }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' and its subdirs with base names " . "starting with 'A' exist in '$reference_dir' and vice versa" ); # Two identical variants of comparison of two directories by file contents, # whereas these contents are first filtered # so that time stamps in form of 'HH:MM:SS' are replaced by '00:00:00' # like in examples for file_filter_ok and compare_filter_ok: $filter = sub { shift =~ s{ \b (?: [01] \d | 2 [0-3] ) : (?: [0-5] \d ) : (?: [0-5] \d ) \b } {00:00:00}grx }; $options = { FILTER => $filter }; compare_dirs_ok( $got_dir, $reference_dir, $options, "all files from '$got_dir' are the same in '$reference_dir', " . 'subdirs are skipped, differences of time stamps ignored' ); compare_dirs_filter_ok( $got_dir, $reference_dir, $filter, "all files from '$got_dir' are the same in '$reference_dir', " . 'subdirs are skipped, differences of time stamps ignored' ); # Verifies if all plain files in directory and its subdirectories # contain the word 'good' (take into consideration the -f test below # excluding special files from comparison!): $content_check = sub { my ( $file ) = @_; ! -f $file or path( $file )->slurp =~ / \b good \b /x; }; $options = { RECURSIVE => 1 }; find_ok( $got_dir, $content_check, $options, "all files from '$got_dir' and subdirectories contain the word 'good'" ); =head1 DESCRIPTION This module is like L or L, in fact you should use that first as shown above. It supports comparison of files and directories in different ways. Any file or directory passed to functions of this module can be both a string or an object of L. Though the test names i.e. the last parameter of every function is optional, you should provide a name of each test for a better maintainability. You should follow the lead of the L examples and use L or, if you prefer, L. This makes it much more likely that your tests will pass on a different operating system. All of the contents comparison routines provide diff diagnostic output when they report failure. The diff output style can be changed using the option B