Test-Files-0.26/0000755000175100017540000000000014572631707012471 5ustar jurijjurijTest-Files-0.26/t/0000755000175100017540000000000014572631707012734 5ustar jurijjurijTest-Files-0.26/t/Test/0000755000175100017540000000000014572631707013653 5ustar jurijjurijTest-Files-0.26/t/Test/Files/0000755000175100017540000000000014572631707014715 5ustar jurijjurijTest-Files-0.26/t/Test/Files/dir_contains_ok.t0000644000175100017540000000115414570674063020250 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mockThis = mock $CLASS => ( override => [ _dir_contains_ok => sub {}, _show_failure => sub {}, _show_result => sub { 1 }, _validate_trailing_args => sub { shift }, ], ); plan( 2 ); ok( $METHOD_REF->( 'dir', [ 'file' ] ), 'comparison performed' ); $mockThis->override( diag => sub { [ 'ERROR' ] } ); ok( !$METHOD_REF->( 'dir', [ 'file' ] ), 'invalid arguments, comparison rejected' ); Test-Files-0.26/t/Test/Files/_show_failure.t0000644000175100017540000000067014572021004017712 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_test_builder = mock 'Test::Builder' => ( override => [ diag => sub {}, ok => sub {} ] ); my $self = $CLASS->_init; plan( 2 ); ok( !$self->$METHOD, 'empty message' ); ok( !$self->$METHOD( 'message' ), 'non-empty message' ); Test-Files-0.26/t/Test/Files/_validate_args.t0000644000175100017540000000460314570674063020051 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 ); plan( 6 ); subtest 'invalid options' => sub { plan( 2 ); my $expected = 'ARG ERROR'; my $mockThis = mock $CLASS => ( override => [ _validate_trailing_args => sub { shift->diag( [ $expected ] ) } ] ); my $self = $CLASS->_init; is( $self->$METHOD( 'ARRAY', $TEMP_DIR, [] ), undef, 'empty result' ); is( $self->diag, [ $expected ], 'error message' ); }; subtest 'directory undefined' => sub { plan( 2 ); my $expected = sprintf( $FMT_UNDEF, '\$dir', '.+' ); my $self = $CLASS->_init; is ( $self->$METHOD( 'ARRAY' ), undef, 'empty result' ); like( $self->diag, [ qr/$expected/ ], 'error message' ); }; subtest 'not a directory' => sub { plan( 2 ); const my $MISSING_FILE => 'MISSING_FILE'; my $expected = sprintf( $FMT_INVALID_DIR, path( $TEMP_DIR )->child( $MISSING_FILE ) ); my $self = $CLASS->_init; is ( $self->$METHOD( 'ARRAY', path( $TEMP_DIR )->child( $MISSING_FILE ), [] ), undef, 'empty result' ); like( $self->diag, [ qr/$expected/ ], 'error message' ); }; subtest 'file list has a wrong type' => sub { plan( 2 ); my $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'array reference', '2nd' ); my $self = $CLASS->_init; is ( $self->$METHOD( 'ARRAY', $TEMP_DIR, {} ), undef, 'empty result' ); like( $self->diag, [ qr/$expected/ ], 'error message' ); }; subtest 'code reference has a wrong type' => sub { plan( 2 ); my $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'code reference', '2nd' ); my $self = $CLASS->_init; is ( $self->$METHOD( 'CODE', $TEMP_DIR, {} ), undef, 'empty result' ); like( $self->diag, [ qr/$expected/ ], 'error message' ); }; subtest 'arguments are valid' => sub { plan( 2 ); my $expected = [ 'file' ]; my $self = $CLASS->_init; is( $self->$METHOD( 'ARRAY', $TEMP_DIR, $expected ), $expected, 'expected result' ); is( $self->diag, [], 'no error message' ); }; Test-Files-0.26/t/Test/Files/compare_dirs_filter_ok.t0000644000175100017540000000142014572012036021570 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 2 ); subtest success => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ _compare_dirs => sub { pass( 'compared' ) }, _validate_options => sub { shift }, ] ); lives_ok { $METHOD_REF->( 'first_dir', 'second_dir', sub {} ) } 'executed'; }; subtest failure => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ _show_failure => sub { pass( 'error detected' ) }, _validate_options => sub { shift->diag( [ 'ERROR' ] ) }, ] ); lives_ok { $METHOD_REF->( 'first_dir', 'second_dir', sub {} ) } 'executed'; }; Test-Files-0.26/t/Test/Files/_validate_trailing_args.t0000644000175100017540000000501514571157520021733 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 { shift->diag( $diag )->options( \%options ) } ] ); const my $DEFAULT => $DIRECTORY_OPTIONS; plan( 6 ); subtest 'trailing arguments omitted' => sub { plan( 4 ); ( $diag, %options ) = ( [] ); my $self = $CLASS->_init; isa_ok( $self->$METHOD( [], $DEFAULT ), $CLASS ); is( $self->diag, $diag, 'no error message' ); is( $self->name, '', 'empty test name' ); is( $self->options, $DEFAULT, 'default options applied' ); }; subtest 'options omitted, test name supplied' => sub { plan( 4 ); ( $diag, %options ) = ( [] ); my $self = $CLASS->_init; isa_ok( $self->$METHOD( [ 'title' ], $DEFAULT ), $CLASS ); is( $self->diag, $diag, 'no error message' ); is( $self->name, 'title', 'test name detected' ); is( $self->options, $DEFAULT, 'default options applied' ); }; subtest 'options supplied' => sub { plan( 3 ); ( $diag, %options ) = ( [ 'ERROR' ] ); my $self = $CLASS->_init; isa_ok( $self->$METHOD( [ { X => 0 } ], $DEFAULT ), $CLASS ); is( $self->diag, $diag, 'invalid option detected' ); subtest "'SIZE_ONLY' and test name supplied" => sub { plan( 4 ); ( $diag, %options ) = ( [], SIZE_ONLY => 1 ); my $self = $CLASS->_init; isa_ok( $self->$METHOD( [ \%options, 'title' ], $DEFAULT ), $CLASS ); is( $self->diag, $diag, 'no error message' ); is( $self->name, 'title', 'test name detected' ); is( $self->options, { %$DEFAULT, %options }, 'options updated' ); }; }; subtest 'filter and title supplied, options updated' => sub { plan( 4 ); $diag = []; my $filter = sub {}; my $self = $CLASS->_init; isa_ok( $self->$METHOD( [ $filter, 'title' ], $DEFAULT ), $CLASS ); is( $self->diag, $diag, 'no error message' ); is( $self->name, 'title', 'test name detected' ); is( $self->options, { %$DEFAULT, FILTER => $filter }, 'options updated' ); }; my $expected = sprintf( $FMT_INVALID_ARGUMENT, '.+', 'hash reference / code reference / string', '3rd' ); my $self = $CLASS->_init; isa_ok( $self->$METHOD( [ [] ], $DEFAULT ), $CLASS ); like( $self->diag, [ qr/$expected/ ], 'invalid argument type' ); Test-Files-0.26/t/Test/Files/find_ok.t0000644000175100017540000000147414570674063016521 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 {}, _show_result => sub { 1 }, _validate_args => sub { my $self = shift; $self->diag( $diag ); $sub }, ] ); path( $TEMP_DIR )->child( 'SUBDIR' )->mkdir; path( $TEMP_DIR )->child( 'BAD' )->touch; path( $TEMP_DIR )->child( 'GOOD' )->touch; plan( 2 ); $diag = []; ok( $METHOD_REF->( $TEMP_DIR, $sub ), 'valid arguments' ); $diag = [ 'ERROR' ]; ok( !$METHOD_REF->( $TEMP_DIR, $sub ), 'invalid arguments' ); Test-Files-0.26/t/Test/Files/compare_archives_ok.t0000644000175100017540000000437014572012734021102 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 2 ); subtest success => sub { plan( 3 ); my $mock_this = mock $CLASS => ( override => [ _compare_dirs => sub { pass( 'content compared' ) }, _compare_metadata => sub { pass( 'metadata compared' ); shift }, _extract => sub { shift }, _validate_trailing_args => sub { my ( $self ) = @_; $self->options( { EXTRACT => sub {}, FILTER => qr/./ } ) }, ] ); ok( $METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' ); }; subtest failure => sub { plan( 4 ); subtest 'invalid arguments' => sub { plan( 1 ); my $mock_this = mock $CLASS => ( override => [ _show_failure => sub {}, _validate_trailing_args => sub { shift->diag( [ 'ERROR' ] ) }, ] ); ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' ); }; subtest 'metadata differs or cannot be extracted' => sub { plan( 1 ); my $mock_this = mock $CLASS => ( override => [ _compare_metadata => sub { shift->diag( [ 'ERROR' ] ) }, _show_failure => sub {}, _validate_trailing_args => sub { shift }, ] ); ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' ); }; subtest 'content differs' => sub { plan( 1 ); my $mock_this = mock $CLASS => ( override => [ _compare_metadata => sub { shift }, _extract => sub { shift->diag( undef ) }, _show_failure => sub {}, _validate_trailing_args => sub { shift }, ] ); ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' ); }; subtest 'content cannot be extracted' => sub { plan( 1 ); my $mock_this = mock $CLASS => ( override => [ _compare_metadata => sub { shift }, _extract => sub { shift->diag( [ 'ERROR' ] ) }, _show_failure => sub {}, _validate_trailing_args => sub { shift }, ] ); ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' ); }; }; Test-Files-0.26/t/Test/Files/compare_filter_ok.t0000644000175100017540000000050714570404520020555 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.26/t/Test/Files/compare_ok.t0000644000175100017540000000050714570411753017216 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.26/t/Test/Files/_get_file_info.t0000644000175100017540000000601014572071541020021 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; my $self = $CLASS->_init; plan( 3 ); $expected = [ sprintf( $FMT_UNDEF, '$file', $SUB ), undef ]; is( [ $self->$METHOD( undef, '$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 =~ /^(?:MSWin32|cygwin|(?:free|open)bsd|solaris)$/ || !path( '/dev/null' )->exists; skip "$^O does not support special device files" if $UNTESTABLE_OS; subtest 'file name supplied' => sub { plan( 5 ); subtest 'file is absent' => sub { plan( 3 ); $expected = [ sprintf( $FMT_ABSENT, $FILE ), undef ]; is( [ $self->$METHOD( $FILE, '$file' ) ], $expected, 'file does not exist' ); subtest 'file is a cpecial one' => sub { plan( 2 ); $expected = [ sprintf( $FMT_ABSENT, '/dev/null' ), undef ]; $self->options( { EXISTENCE_ONLY => 0 } ); is( [ $self->$METHOD( '/dev/null', '$file' ) ], $expected, 'get content' ); $expected = [ undef, 1 ]; $self->options( { EXISTENCE_ONLY => 1 } ); is( [ $self->$METHOD( '/dev/null', '$file' ) ], $expected, 'check existence' ); }; $expected = [ sprintf( $FMT_ABSENT, $TEMP_DIR ), undef ]; $self->options( {} ); is( [ $self->$METHOD( $TEMP_DIR, '$file' ) ], $expected, 'file is a directory' ); }; $FILE->spew( $CONTENT ); $self->options( { EXISTENCE_ONLY => 1 } ); ok( [ $self->$METHOD( $FILE, '$file' ) ], 'file existence' ); $expected = [ undef, length( $CONTENT ) ]; $self->options( { SIZE_ONLY => 1 } ); is( [ $self->$METHOD( $FILE, '$file' ) ], $expected, 'file size' ); subtest 'filter omitted, reading failed' => sub { plan( 2 ); $FILE->chmod( 0 ); $self->options( {} ); my $expected = sprintf( $FMT_ABSENT_WITH_ERROR, $FILE, '.+' ); my @got = $self->$METHOD( $FILE, '$file' ); like( $got[ 0 ], qr/$expected/, 'error message' ); is ( $got[ 1 ], undef, 'file content' ); }; $FILE->chmod( 'u+r' ); $expected = [ undef, "line 0\n" ]; $self->options( { FILTER => sub { /0/ ? $_ : undef } } ); is( [ $self->$METHOD( $FILE, '$file' ) ], $expected, 'filter supplied, reading succeeded' ); }; } subtest 'scalar reference supplied' => sub { plan( 2 ); $expected = [ undef, length( $CONTENT ) ]; $self->options( { SIZE_ONLY => 1 } ); is( [ $self->$METHOD( \$CONTENT, '$expected' ) ], $expected, 'content size' ); $expected = [ undef, $CONTENT ]; $self->options( {} ); is( [ $self->$METHOD( \$CONTENT, '$expected' ) ], $expected, 'content returned' ); }; Test-Files-0.26/t/Test/Files/file_filter_ok.t0000644000175100017540000000051714570674063020062 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 { shift } ] ); plan( 1 ); isa_ok( $METHOD_REF->( 'file', 'string', sub {} ), $CLASS ); Test-Files-0.26/t/Test/Files/_get_caller_sub.t0000644000175100017540000000123214561716476020216 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.26/t/Test/Files/_extract.t0000644000175100017540000000335114571433767016722 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( $FMT_CANNOT_CREATE_DIR $FMT_CANNOT_EXTRACT ); plan( 3 ); subtest 'cannot create working directory' => sub { plan( 2 ); my $mock_Path_Tiny = mock 'Path::Tiny' => ( override => [ mkdir => sub { die } ] ); my $mock_this = mock $CLASS => ( override => [ diag => sub { my ( $self, $messages ) = @_; my $expected = sprintf( $FMT_CANNOT_CREATE_DIR, '.*got_archive', '.*' ); like( $messages->[ 0 ], qr/$expected/, 'exception raised' ); return $self; } ] ); my $self = $CLASS->_init->got( 'got_archive' )->expected( 'expected_archive' )->options( { EXTRACT => sub {} } ); isa_ok( $self->$METHOD, $CLASS ); }; subtest 'cannot extract archive content' => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ diag => sub { my ( $self, $messages ) = @_; my $expected = sprintf( $FMT_CANNOT_EXTRACT, 'got_archive', '.*got_archive', '.*' ); like( $messages->[ 0 ], qr/$expected/, 'exception raised' ); return $self; } ] ); my $self = $CLASS->_init->got( 'got_archive' )->expected( 'expected_archive' )->options( { EXTRACT => sub { die } } ); isa_ok( $self->$METHOD, $CLASS ); }; subtest success => sub { plan( 3 ); my $self = $CLASS->_init->got( 'got_archive' )->expected( 'expected_archive' ) ->options( { EXTRACT => sub { path( 'content' )->touch } } ); isa_ok( $self->$METHOD, $CLASS ); ok( $self->base->child( $_, 'content' )->exists, "extracted from '$_'" ) foreach qw( got_archive expected_archive ); }; Test-Files-0.26/t/Test/Files/_get_two_files_info.t0000644000175100017540000000237414570674063021114 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 ); subtest 'first file reading failed' => sub { plan( 2 ); @result = ( [ $ERROR, undef ], [ undef, $CONTENT ] ); my $expected = [ undef, $CONTENT ]; my $self = $CLASS->_init; is( [ $self->$METHOD( 'first_file', 'second_file', 'first_name', 'second_name' ) ], $expected, 'result value' ); $expected = [ $ERROR ]; is( $self->diag, $expected, 'error message' ); }; subtest 'second file reading failed' => sub { plan( 2 ); @result = ( [ undef, $CONTENT ], [ $ERROR, undef ] ); my $expected = [ $CONTENT, undef ]; my $self = $CLASS->_init; is( [ $self->$METHOD( 'first_file', 'second_file', 'first_name', 'second_name' ) ], $expected, 'result value' ); $expected = [ $ERROR ]; is( $self->diag, $expected, 'error message' ); }; Test-Files-0.26/t/Test/Files/_show_result.t0000644000175100017540000000101414572025322017601 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_test_builder = mock 'Test::Builder' => ( override => [ ok => sub { 1 } ] ); my $mock_this = mock $CLASS => ( override => [ _show_failure => sub {} ] ); my $self = $CLASS->_init; plan( 2 ); ok( !$self->diag( [ 'message' ] )->$METHOD, 'failure' ); ok( $self->diag( [] ) ->$METHOD, 'success' ); Test-Files-0.26/t/Test/Files/_dir_contains_ok.t0000644000175100017540000001004714572631207020403 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'; const my $SPECIAL_FILE => 'special_file'; const my $UNTESTABLE_OS => $^O =~ /^(?:MacOS|MSWin32|darwin|solaris)$/ || !path( '/dev/null' )->exists; const my @EXISTING_FILES => qw( file0 file1 subdir/file2 subdir/file3 ); plan( 4 ); subtest 'invalid arguments' => sub { plan( 2 ); my $expected = [ 'ERROR' ]; my $mockThis = mock $CLASS => ( override => [ _validate_args => sub { shift->diag( $expected ) } ] ); my $self = $CLASS->_init; is( $self->$METHOD( $TEMP_DIR, [] ), [], 'empty result' ); is( $self->diag, $expected, 'error message' ); }; 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; } SKIP: { skip "$^O does not support special device files" if $UNTESTABLE_OS; symlink( '/dev/null', path( $TEMP_DIR )->child( $SPECIAL_FILE ) ); subtest 'special file' => sub { plan( 2 ); subtest 'check existence only, name pattern omitted' => sub { plan( 2 ); my $expected = [ sprintf( $FMT_FAILED_TO_SEE, path( $TEMP_DIR )->child( $MISSING_FILE ) ) ]; my $self = $CLASS->_init; like( $self->$METHOD( $TEMP_DIR, [ @EXISTING_FILES, $MISSING_FILE ], { EXISTENCE_ONLY => 1, RECURSIVE => 1 } ), [ map { my $e = path( $_ ); qr/\b$e$/ } @EXISTING_FILES ], 'list of existing files returned' ); is( $self->diag, $expected, 'error message' ); }; subtest 'check something but existence, specify name pattern' => sub { plan( 2 ); my $expected = [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $SPECIAL_FILE ) ) ]; my $self = $CLASS->_init; like( $self->$METHOD( $TEMP_DIR, \@EXISTING_FILES, { NAME_PATTERN => '[01]', RECURSIVE => 1 } ), [ map { if ( /[01]/ ) { my $e = path( $_ ); qr/\b$e$/ } else { () } } @EXISTING_FILES ], 'list of existing files returned' ); is( $self->diag, $expected, 'error message' ); }; }; } 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; } ); subtest 'supefluous file in symmetric approach, name pattern omitted' => sub { plan( $UNTESTABLE_OS ? 1 : 2 ); my $expected = [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $UNACCESSIBLE_FILE ) ), sprintf( $FMT_UNEXPECTED, path( $TEMP_DIR )->child( $UNEXPECTED_FILE ) ), ]; my $self = $CLASS->_init; like( $self->$METHOD( $TEMP_DIR, \@EXISTING_FILES, { EXISTENCE_ONLY => 1, RECURSIVE => 1, SYMMETRIC => 1 } ), [ map { my $e = path( $_ ); qr/\b$e$/ } @EXISTING_FILES ], 'list of existing files returned' ); is( $self->diag, $expected, 'error message' ) unless $UNTESTABLE_OS; }; subtest 'unaccessible file, name pattern omitted' => sub { plan( $UNTESTABLE_OS ? 1 : 2 ); path( $TEMP_DIR )->child( $_ )->touch foreach $UNACCESSIBLE_FILE, $UNEXPECTED_FILE; my $expected = [ sprintf( $FMT_ABSENT, path( $TEMP_DIR )->child( $UNACCESSIBLE_FILE ) ) ]; my $self = $CLASS->_init; like( $self->$METHOD( $TEMP_DIR, \@EXISTING_FILES, { EXISTENCE_ONLY => 1, RECURSIVE => 1 } ), [ map { my $e = path( $_ ); qr/\b$e$/ } @EXISTING_FILES ], 'list of existing files returned' ); is( $self->diag, $expected, 'error message' ) unless $UNTESTABLE_OS; }; Test-Files-0.26/t/Test/Files/file_ok.t0000644000175100017540000000050714570674063016514 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 { shift } ] ); plan( 1 ); isa_ok( $METHOD_REF->( 'file', 'string' ), $CLASS ); Test-Files-0.26/t/Test/Files/_validate_options.t0000644000175100017540000000504514570674063020611 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, $self ); plan( 2 ); subtest failure => sub { plan( 3 ); const my $DEFAULT => $DIRECTORY_OPTIONS; subtest 'invalid option' => sub { plan( 2 ); isa_ok( $self = $CLASS->_init->options( { X => 0 } )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' ); $expected = sprintf( $FMT_INVALID_OPTIONS, 'X' ); is( $self->diag, [ $expected ], 'detected' ); }; subtest 'filter is not a code reference' => sub { plan( 2 ); isa_ok( $self = $CLASS->_init->options( { FILTER => 0 } )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' ); $expected = sprintf( $FMT_FILTER_ISNT_CODEREF, '.+' ) =~ s/([()])/\\$1/gr; like( $self->diag, [ qr/$expected/ ], 'detected' ); }; subtest 'invalid name pattern' => sub { plan( 2 ); isa_ok( $self = $CLASS->_init->options( { NAME_PATTERN => '[' } )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' ); $expected = sprintf( $FMT_INVALID_NAME_PATTER, '\[', '.+', '.+' ); like( $self->diag, [ qr/$expected/ ], 'detected' ); }; }; subtest success => sub { plan( 2 ); subtest 'both filter and name pattern supplied' => sub { plan( 3 ); const my $DEFAULT => $DIRECTORY_OPTIONS; my $filter = sub {}; isa_ok( $self = $CLASS->_init->options( { FILTER => $filter, NAME_PATTERN => '..' } )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' ); is( $self->diag, [], 'no errors' ); is( $self->options, { %$DEFAULT, FILTER => $filter, NAME_PATTERN => '..' }, 'arguments determined' ); }; subtest 'both filter and name pattern omitted' => sub { plan( 3 ); const my $DEFAULT => $FILE_OPTIONS; isa_ok( $self = $CLASS->_init->options( {} )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' ); is( $self->diag, [], 'no errors' ); is( $self->options, $DEFAULT, 'arguments determined' ); }; }; Test-Files-0.26/t/Test/Files/_compare_ok.t0000644000175100017540000000353614570674063017367 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, $diff, $info_valid ); my $mock_this = mock $CLASS => ( override => [ _compare_files => sub { my ( $self ) = @_; $self->diag( $diff ); $self }, _get_two_files_info => sub { shift->diag( $info_valid ? [] : [ 'INFO ERROR' ] ) }, _show_failure => sub {}, _show_result => sub { !@{ shift->diag } }, _validate_trailing_args => sub { shift->diag( $args_valid ? [] : [ 'ARGS ERROR' ] ) }, ] ); plan( 4 ); subtest 'invalid optional arguments' => sub { plan( 2 ); my $self = $CLASS->_init; ( $args_valid, $diff, $info_valid ) = ( 0, [], 1 ); ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' ); is( $self->diag, [ 'ARGS ERROR' ], 'failure reported' ); }; subtest 'file info cannot be gathered' => sub { plan( 2 ); my $self = $CLASS->_init; ( $args_valid, $diff, $info_valid ) = ( 1, [], 0 ); ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' ); is( $self->diag, [ 'INFO ERROR' ], 'failure reported' ); }; subtest 'expected file passed, differences detected' => sub { plan( 2 ); my $self = $CLASS->_init; ( $args_valid, $diff, $info_valid ) = ( 1, [ 'DIFF' ], 1 ); ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' ); is( $self->diag, [ 'DIFF' ], 'differences reported' ); }; subtest 'expected content passed, differences detected' => sub { plan( 2 ); my $self = $CLASS->_init; ( $args_valid, $diff, $info_valid ) = ( 1, [ 'DIFF' ], 1 ); ok( !$self->$METHOD( 'got_file', \'expected_file' ), 'failed' ); is( $self->diag, [ 'DIFF' ], 'differences reported' ); }; Test-Files-0.26/t/Test/Files/_compare_files.t0000644000175100017540000000344714570674063020061 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; my $self = $CLASS->_init; subtest 'compare existence only' => sub { plan( 3 ); $self->options( { EXISTENCE_ONLY => 1 } ); $expected = [ sprintf( $FMT_FIRST_FILE_ABSENT, $FIRST_FILE, $SECOND_FILE ) ]; is( $self->diag( [] )->$METHOD( 0, 1, $FIRST_FILE, $SECOND_FILE )->diag, $expected, 'second file missing' ); $expected = [ sprintf( $FMT_SECOND_FILE_ABSENT, $FIRST_FILE, $SECOND_FILE ) ]; is( $self->diag( [] )->$METHOD( 1, 0, $FIRST_FILE, $SECOND_FILE )->diag, $expected, 'first file missing' ); $expected = []; is( $self->diag( [] )->$METHOD( 1, 1, $FIRST_FILE, $SECOND_FILE )->diag, $expected, 'both files exist' ); }; subtest 'compare size' => sub { plan( 2 ); $self->options( { SIZE_ONLY => 1 } ); $expected = [ sprintf( $FMT_DIFFERENT_SIZE, $FIRST_FILE, $SECOND_FILE, 1, 0 ) ]; is( $self->diag( [] )->$METHOD( 1, 0, $FIRST_FILE, $SECOND_FILE )->diag, $expected, 'different size' ); $expected = []; is( $self->diag( [] )->$METHOD( 1, 1, $FIRST_FILE, $SECOND_FILE )->diag, $expected, 'equal size' ); }; subtest 'compare content' => sub { plan( 2 ); $self->options( { CONTEXT => 2, STYLE => 'OldStyle'} ); isnt( $self->diag( [] )->$METHOD( '1', '0', $FIRST_FILE, $SECOND_FILE )->diag, [], 'different content' ); is ( $self->diag( [] )->$METHOD( '1', '1', $FIRST_FILE, $SECOND_FILE )->diag, [], 'identical content' ); }; Test-Files-0.26/t/Test/Files/_compare_metadata.t0000644000175100017540000000373414571431515020530 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( $FMT_CANNOT_GET_METADATA ); plan( 4 ); subtest 'got metadata cannot be acquired' => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ diag => sub { my ( $self, $messages ) = @_; my $expected = sprintf( $FMT_CANNOT_GET_METADATA, 'got_archive', '.*' ); like( $messages->[ 0 ], qr/$expected/, 'exception raised' ); return $self; } ] ); my $self = $CLASS->_init->got( 'got_archive')->expected( 'reference_archive' ) ->options( { META_DATA => sub { die} } ); isa_ok( $self->$METHOD, $CLASS ); }; subtest 'expected metadata cannot be acquired' => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ diag => sub { my ( $self, $messages ) = @_; my $expected = sprintf( $FMT_CANNOT_GET_METADATA, 'reference_archive', '.*' ); like( $messages->[ 0 ], qr/$expected/, 'exception raised' ); return $self; } ] ); my $self = $CLASS->_init->got( 'got_archive')->expected( 'reference_archive' ) ->options( { META_DATA => sub { die if shift eq 'reference_archive' } } ); isa_ok( $self->$METHOD, $CLASS ); }; subtest 'identical metadata' => sub { plan( 2 ); my $self = $CLASS->_init->got( 'got_archive')->expected( 'reference_archive' )->options( { META_DATA => sub {} } ); isa_ok( $self->$METHOD, $CLASS ); is( $self->diag, [], 'no errors detected' ); }; subtest 'different metadata' => sub { plan( 3 ); my $mock_this = mock $CLASS => ( override => [ is => sub ( $$;$@ ) { pass( 'differences displayed' ) } ] ); my $self = $CLASS->_init->got( 'got_archive')->expected( 'reference_archive' ) ->options( { META_DATA => sub { shift } } ); isa_ok( $self->$METHOD, $CLASS ); is( $self->diag, undef, 'special handling provided' ); }; Test-Files-0.26/t/Test/Files/compare_dirs_ok.t0000644000175100017540000000143014572012052020222 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 2 ); subtest success => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ _compare_dirs => sub { pass( 'compared' ) }, _validate_trailing_args => sub { shift }, ] ); lives_ok { $METHOD_REF->( 'first_dir', 'second_dir' ) } 'executed'; }; subtest failure => sub { plan( 2 ); my $mock_this = mock $CLASS => ( override => [ _show_failure => sub { pass( 'error detected' ) }, _validate_trailing_args => sub { shift->diag( [ 'ERROR' ] ) }, ] ); lives_ok { $METHOD_REF->( 'first_dir', 'second_dir' ) } 'executed'; }; Test-Files-0.26/t/Test/Files/dir_only_contains_ok.t0000644000175100017540000000115414570674063021311 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $mockThis = mock $CLASS => ( override => [ _dir_contains_ok => sub {}, _show_failure => sub {}, _show_result => sub { 1 }, _validate_trailing_args => sub { shift }, ], ); plan( 2 ); ok( $METHOD_REF->( 'dir', [ 'file' ] ), 'comparison performed' ); $mockThis->override( diag => sub { [ 'ERROR' ] } ); ok( !$METHOD_REF->( 'dir', [ 'file' ] ), 'invalid arguments, comparison rejected' ); Test-Files-0.26/t/Test/Files/_relative.t0000644000175100017540000000076314571353667017067 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempfile => {}; plan( 2 ); is( $CLASS->_init-> $METHOD( $TEMP_FILE ), $TEMP_FILE, 'base directory undefined' ); my $base = path( $TEMP_FILE )->dirname; is( $CLASS->_init->base( $base )->$METHOD( $TEMP_FILE ), path( $TEMP_FILE )->relative( $base ), 'base directory defined' ); Test-Files-0.26/t/Test/Files/_compare_dirs.t0000644000175100017540000000311514570674063017710 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_UNDEF ); my ( $error, $expected, $file_list ); my $mock_this = mock $CLASS => ( override => [ _compare_files => sub { [] }, _dir_contains_ok => sub { $file_list }, _get_two_files_info => sub { shift->diag( $error ) }, _show_failure => sub { shift; my $err = sprintf( $FMT_UNDEF, $expected, '.+' ); like( shift, qr/$err/, 'failure reported' ); return 0; }, _show_result => sub { is( !!@{ shift->diag }, !!@$error, 'result reported' ) }, ] ); plan( 4 ); subtest 'first directory undefined' => sub { plan( 2 ); $expected = '\$expected_dir'; ok( !$CLASS->_init->$METHOD, 'comparison failed' ); }; subtest 'second directory undefined' => sub { plan( 2 ); $expected = '\$got_dir'; ok( !$CLASS->_init->expected( 'x' )->$METHOD, 'comparison failed' ); }; path( $TEMP_DIR )->child( 'SUBDIR' )->mkdir; path( $TEMP_DIR )->child( 'PLAIN_FILE' )->touch; ( $error, $expected, $file_list ) = ( [], undef, [ 'file' ] ); subtest 'directories identical' => sub { plan( 2 ); is( $CLASS->_init->got( 'FIRST_DIR' )->expected( $TEMP_DIR )->$METHOD, 1, 'comparison performed' ); }; ( $error, $expected, $file_list ) = ( [ 'ERROR' ], undef, [ 'file' ] ); subtest 'differences detected' => sub { plan( 2 ); is( $CLASS->_init->got( 'FIRST_DIR' )->expected( $TEMP_DIR )->$METHOD, 1, 'comparison performed' ); }; Test-Files-0.26/t/.proverc-cover0000644000175100017540000000003214457161713015521 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.26/t/.proverc0000644000175100017540000000003214457161677014416 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.26/t/.perlcriticrc0000644000175100017540000002321114572631474015422 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.26/xt/0000755000175100017540000000000014572631707013124 5ustar jurijjurijTest-Files-0.26/xt/Test/0000755000175100017540000000000014572631707014043 5ustar jurijjurijTest-Files-0.26/xt/Test/Files/0000755000175100017540000000000014572631707015105 5ustar jurijjurijTest-Files-0.26/xt/Test/Files/compare_ok.t0000644000175100017540000000166414571134321017405 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 $mock_this = mock $CLASS => ( override => [ _show_failure => sub {}, _show_result => sub { !@{ shift->diag } }, ] ); const my $EXPECTED_FILE => path( $TEMP_DIR )->child( 'expected_file' ); const my $GOT_FILE => path( $TEMP_DIR )->child( 'got_file' ); plan( 4 ); ok( !$METHOD_REF->( $GOT_FILE, $EXPECTED_FILE, [] ), 'invalid optional arguments' ); ok( !$METHOD_REF->( $GOT_FILE, $EXPECTED_FILE ), 'file info cannot be gathered' ); $EXPECTED_FILE->spew( 'expected_content' ); $GOT_FILE ->spew( 'got_content' ); ok( !$METHOD_REF->( $GOT_FILE, $EXPECTED_FILE ), 'expected file passed, differences detected' ); ok( !$METHOD_REF->( $GOT_FILE, \'expected_content' ), 'expected content passed, differences detected' ); Test-Files-0.26/xt/Test/Files/synopsis.t0000644000175100017540000002231014572073514017153 0ustar jurijjurij# This implements all test cases mentioned in SYNOPSIS. # To make it runnable, the following changes have been done: # - Test::Expander used instead of Path::Tiny (this includes both Path::Tiny and Test2::V0). # - $PATH referring to a temporary directory used instead of path( 'path' ). # - The necessary directory structure and test files creation implemented. use 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; use Archive::Zip qw( :ERROR_CODES ); use File::Copy::Recursive qw( dircopy ); const my $PATH => path( $TEMP_DIR ); my $got_file = $PATH->child( qw( got file ) ); my $reference_file = $PATH->child( qw( reference file ) ); my $got_dir = $PATH->child( qw( got dir ) ); my $reference_dir = $PATH->child( qw( reference dir with some stuff ) ); my @file_list = qw( expected file ); my ( $content_check, $expected, $filter, $options ); plan( 24 ); # Simply compares file contents to a string: $expected = "contents\nof file"; $got_file->parent->mkdir; $got_file->spew( $expected ); file_ok( $got_file, $expected, 'got file has expected contents' ); # Two identical variants comparing file contests to a string ignoring differences in time stamps: $expected = "filtered contents\nof file\ncreated at 00:00:00"; $got_file->spew( $expected =~ s/00:00:00/12:34:56/r ); $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: $reference_file->parent->mkdir; $got_file->copy( $reference_file ); compare_ok( $got_file, $reference_file, 'files are the same' ); # Two identical variants comparing contents of two files ignoring differences in time stamps: $got_file->spew( $expected ); $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 ) ]; $got_dir->child( 'subdir' )->mkdir; $got_dir->child( $_ )->touch foreach @$expected, 'additional_file'; $got_dir->child( 'subdir' )->child( 'file_in_subdir' )->touch; 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 }; $got_dir->child( 'additional_file' )->remove; 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 }; $expected = [ @$expected, 'subdir/file_in_subdir' ]; 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 }; $got_dir->child( 'must' )->remove; 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!): dircopy( $got_dir, $reference_dir ); $reference_dir->child( 'subdir' )->remove_tree; 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: dircopy( $got_dir, $reference_dir ); $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: $got_dir ->child( 'contain' )->spew( 'abc' ); $reference_dir->child( 'contain' )->spew( 'xyz' ); $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: $reference_dir->child( 'contain' )->spew( 'some longer text' ); $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: $got_dir ->child( 'contain' )->remove; $got_dir ->child( 'A.txt' )->touch; $reference_dir->child( 'A.txt' )->touch; $reference_dir->child( qw( subdir A.txt ) )->touch; $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: $got_dir->child( qw( subdir A.txt ) )->touch; $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 version 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: dircopy( $reference_dir, $got_dir ); $expected = "filtered contents\nof file\ncreated at 00:00:00"; $got_dir ->child( 'A.txt' )->spew( $expected =~ s/00:00:00/12:34:56/r ); $reference_dir->child( 'A.txt' )->spew( $expected =~ s/00:00:00/21:43:05/r ); $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!): $got_dir->visit( sub { $_->spew( 'This is a good plain file!' ) unless $_->is_dir }, { recurse => 1 } ); $content_check = sub { my ( $file ) = @_; not -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'" ); # Compares PKZIP archives considering both global and file comments. # Both archives contain the same members in different order: my @fileNos = ( 0, 1 ); foreach my $archive ( $got_file, $reference_file ) { my $zip = Archive::Zip->new(); $zip->zipfileComment( 'Global comment' ); $zip->addString( "This is file No. $_", "file_$_" )->fileComment( "Some comment to file No. $_" ) foreach @fileNos; bail_out( "Cannot create '$archive.zip'" ) if $zip->writeToFileNamed( "$archive.zip" ) != AZ_OK; @fileNos = reverse( @fileNos ); } my $extract = sub { my ( $file ) = @_; my $zip = Archive::Zip->new(); die( "Cannot read '$file'" ) if $zip->read( $file ) != AZ_OK; die( "Cannot extract from '$file'" ) if $zip->extractTree != AZ_OK; }; my $meta_data = sub { my ( $file ) = @_; my $zip = Archive::Zip->new(); die( "Cannot read '$file'" ) if $zip->read( $file ) != AZ_OK; my %meta_data = ( '' => $zip->zipfileComment ); $meta_data{ $_->fileName } = $_->fileComment foreach $zip->members; return \%meta_data; }; my $got_compressed_content = path( "$got_file.zip" )->slurp; my $reference_compressed_content = path( "$reference_file.zip" )->slurp; ok( $got_compressed_content ne $reference_compressed_content, "'$got_file.zip' and '$reference_file.zip' are physically different, but" ); compare_archives_ok( "$got_file.zip", "$reference_file.zip", { EXTRACT => $extract, META_DATA => $meta_data }, "'$got_file.zip' and '$reference_file.zip' are logically identical" ); Test-Files-0.26/xt/Test/Files/find_ok.t0000644000175100017540000000131514571135123016671 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 $mockThis = mock $CLASS => ( override => [ _show_failure => sub {}, _show_result => sub { !@{ shift->diag } }, ] ); my $sub = sub { path( shift )->basename eq 'GOOD' }; path( $TEMP_DIR )->child( 'SUBDIR' )->mkdir; path( $TEMP_DIR )->child( 'BAD' )->touch; path( $TEMP_DIR )->child( 'GOOD' )->touch; plan( 2 ); ok( $METHOD_REF->( $TEMP_DIR, $sub ), 'valid arguments' ); ok( !$METHOD_REF->( $TEMP_DIR, '' ), 'invalid arguments' ); Test-Files-0.26/xt/Test/Files/compare_dirs_ok.t0000644000175100017540000000563114570703636020436 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_FAILED_TO_SEE ); const my $TEMP_PATH => path( $TEMP_DIR ); const my $TEMP_PATH1 => $TEMP_PATH->child( 'DIR1' ); const my $TEMP_PATH2 => $TEMP_PATH->child( 'DIR2' ); my $expected; my $mock_this = mock $CLASS => ( override => [ _show_result => sub { my ( undef, @messages ) = @_; if ( ref( $expected->[ 0 ] ) ne 'Regexp' ) { is( \@messages, $expected, 'result reported' ); } else { while ( my ( $index, $got ) = each( @messages ) ) { like( $got, $expected->[ $index ], "result line $index reported" ); } } } ] ); foreach my $dir_num ( 1 .. 2 ) { $TEMP_PATH->child( "DIR$dir_num", 'SUBDIR' )->mkdir; foreach my $sub_dir ( [], [ 'SUBDIR' ] ) { $TEMP_PATH->child( "DIR$dir_num", @$sub_dir, 'SAME_CONTENT' )->spew( "CONTENT1\n" ); $TEMP_PATH->child( "DIR$dir_num", @$sub_dir, 'DIFF_CONTENT' )->spew( "CONTENT2 $dir_num\n" ); $TEMP_PATH->child( "DIR$dir_num", @$sub_dir, 'DIFF_SIZE' )->spew( '.' x $dir_num . "\n" ); } $TEMP_PATH->child( "DIR$dir_num", @$_, "SOLE_FILE$dir_num" )->touch foreach [], [ 'SUBDIR' ]; } plan( 4 ); subtest 'backward compatibility (compare_dirs_ok)' => sub { plan( 4 ); my @expected = ( join( '.+' , map { $TEMP_PATH->child( "DIR$_", 'DIFF_CONTENT' ) } 1 .. 2 ), join( '.+' , map { $TEMP_PATH->child( "DIR$_", 'DIFF_SIZE' ) } 1 .. 2 ), $TEMP_PATH1->child( qw( SOLE_FILE2 ) )->stringify, ); $expected = [ map { qr/$_/s } @expected ]; lives_ok { $METHOD_REF->( "$TEMP_PATH1", "$TEMP_PATH2" ) } 'executed'; }; subtest 'backward compatibility (compare_dirs_filter_ok)' => sub { plan( 3 ); my @expected = ( join( '.+' , map { $TEMP_PATH->child( "DIR$_", 'DIFF_SIZE' ) } 1 .. 2 ), $TEMP_PATH1->child( qw( SOLE_FILE2 ) )->stringify, ); $expected = [ map { qr/$_/s } @expected ]; lives_ok { $METHOD_REF->( "$TEMP_PATH1", "$TEMP_PATH2", { FILTER => sub { s/\s\d//r } } ) } 'executed'; }; subtest 'compare existence recursively' => sub { plan( 2 ); $expected = [ sort map { sprintf( $FMT_FAILED_TO_SEE, $TEMP_PATH1->child( @$_, 'SOLE_FILE2' ) ) } [], [ 'SUBDIR' ] ]; lives_ok { $METHOD_REF->( $TEMP_PATH1, $TEMP_PATH2, { EXISTENCE_ONLY => 1, RECURSIVE => 1 } ) } 'executed'; }; subtest 'compare size recursively' => sub { plan( 5 ); my @expected = ( join( '.+' , map { $TEMP_PATH->child( "DIR$_", 'DIFF_SIZE' ) } 1 .. 2 ), join( '.+' , map { $TEMP_PATH->child( "DIR$_", 'SUBDIR', 'DIFF_SIZE' ) } 1 .. 2 ), map { $TEMP_PATH1->child( @$_, 'SOLE_FILE2' )->stringify } [], [ 'SUBDIR' ], ); $expected = [ map { qr/$_/ } @expected ]; lives_ok { $METHOD_REF->( $TEMP_PATH1, $TEMP_PATH2, { SIZE_ONLY => 1, RECURSIVE => 1 } ) } 'executed'; }; Test-Files-0.26/xt/Test/Files/dir_contains_ok.t0000644000175100017540000000113714571135170020431 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 $mockThis = mock $CLASS => ( override => [ _show_failure => sub {}, _show_result => sub { !@{ shift->diag } }, ] ); const my @FILE_LIST => ( qw( file0 file1 ) ); path( $TEMP_DIR )->child( $_ )->touch foreach @FILE_LIST; plan( 2 ); ok( $METHOD_REF->( $TEMP_DIR, \@FILE_LIST ), 'comparison performed' ); ok( !$METHOD_REF->( $TEMP_DIR, {} ), 'invalid arguments, comparison rejected' ); Test-Files-0.26/xt/.proverc0000644000175100017540000000003214457161677014606 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.26/xt/.perlcriticrc0000644000175100017540000002317714570704335015620 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 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.26/xt/.proverc-cover0000644000175100017540000000003214457161713015711 0ustar jurijjurij--lib --recurse --shuffle Test-Files-0.26/LICENSE0000644000175100017540000004376214561714354013510 0ustar jurijjurijThis software is copyright (c) 2003-2007 by Phil Crow and 2020-2024 by Jurij Fajnberg. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is copyright (c) 2003-2007 by Phil Crow and 2020-2024 by Jurij Fajnberg. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2021-2022 by Jurij Fajnberg. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Test-Files-0.26/TODO0000644000175100017540000000500414561717554013163 0ustar jurijjurijA user pointed out an error (in his opinion): compare_dirs_ok does not work properly on second level directories I have not verified that this error occurs compare_dirs_ok does not make sure that the first dir has all the files that appear in the second. It should call dir_contains_only_ok. The same user said that once compare_dirs_ok is fixed, there should be an option like --exclude in the standard diff. (implemented in 0.16) #----------------------------------------------------- Functions Schwern suggested which are not implemented yet: #----------------------------------------------------- dir_ok( "some/dir", { "foo" => "some/dir/foo would contain this", "bar" => "some/dir/bar would contain this", "baz/biff" => "some/dir/baz/biff would contain this" }); # I suggested using undef for the values here to request a check of structure # only, that is only file names would be examined, not contents. Yet, # Schwern had already suggested dir_contains_ok, which is probably more # directly intelligiable. #----------------------------------------------------- find_ok( "some/dir", sub { which will be run against all files in some/dir and returns true if they pass } ); (implemented in 0.16) #----------------------------------------------------- I suggested: dirs_agree("dir1", "dir2") Schwern suggested a new name for dirs_agree: compare_dirs_ok instead of dirs_agree (implemented in 0.03) (I'm extrapolating, he didn't make a direct suggestion, but his earlier suggestions point to something like this.) #----------------------------------------------------- After trying compare_dirs_ok I immediately wanted to be able to exclude some lines from the comparison. Namely, in my example, dates were the only differences. So, I still wanted the files to count as the same, even though the dates differed. That led to: compare_dirs_filter_ok($dir1, $dir2, \&filter, $name) (implemented in 0.04) filter is called for all lines of input, it must return the line with any needed changes. If the line should be omitted, it should return "". (implemented in 0.04) #----------------------------------------------------- I want compare_filer_ok($file1, $file2, $filter) to work like compare_dirs_filter but one file at a time (implemented in 0.06) #----------------------------------------------------- The version 0.15 causes a lot of warning being processed by Perl::Critic so that some style changes may improve further maintainability. (implemented in 0.16) Test-Files-0.26/lib/0000755000175100017540000000000014572631707013237 5ustar jurijjurijTest-Files-0.26/lib/.perlcriticrc0000644000175100017540000002654014570704227015730 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.26/lib/Test/0000755000175100017540000000000014572631707014156 5ustar jurijjurijTest-Files-0.26/lib/Test/Files.pm0000644000175100017540000004041114572631527015556 0ustar jurijjurijpackage Test::Files; our $VERSION = '0.26'; ## no critic (RequireUseStrict, RequireUseWarnings) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline portable recursion ); use Class::XSAccessor accessors => [ qw( base diag expected got name options ) ], chained => 1; use Cwd qw( abs_path ); use Data::Compare qw( Compare ); use Exporter qw( import ); use Fcntl qw( :mode ); use File::chdir; use Path::Tiny qw( path ); use Test::Builder; use Test2::Tools::Compare qw( is ); use Text::Diff qw( diff ); use Test::Files::Constants qw( $ARCHIVE_OPTIONS $DIRECTORY_OPTIONS $EXPECTED_CONTENT $FMT_ABSENT $FMT_ABSENT_WITH_ERROR $FMT_CANNOT_CREATE_DIR $FMT_CANNOT_EXTRACT $FMT_CANNOT_GET_METADATA $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_archives_ok 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_archives_ok { my ( $got_archive, $expected_archive, @rest ) = @_; my $self = __PACKAGE__->_init->got( $got_archive )->expected( $expected_archive ) ->_validate_trailing_args( \@rest, $ARCHIVE_OPTIONS ); return $self->_show_failure if @{ $self->diag } || @{ $self->_compare_metadata->diag }; $self->_extract->diag; return 0 unless defined( $self->diag ); # Special handling of metadata difference return $self->_show_failure if @{ $self->diag }; map { delete( $self->options->{ $_ } ) unless exists( $DIRECTORY_OPTIONS->{ $_ } ) } keys( %{ $self->options } ); return $self->_compare_dirs; } sub compare_dirs_filter_ok { my ( $got_dir, $expected_dir, $filter, $name ) = @_; my $self = __PACKAGE__->_init->got( $got_dir )->expected( $expected_dir )->name( $name )->options( { FILTER => $filter } ) ->_validate_options( $DIRECTORY_OPTIONS ); return @{ $self->diag } ? $self->_show_failure : $self->_compare_dirs; } sub compare_dirs_ok { my ( $got_dir, $expected_dir, @rest ) = @_; my $self = __PACKAGE__->_init->got( $got_dir )->expected( $expected_dir ) ->_validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return @{ $self->diag } ? $self->_show_failure : $self->_compare_dirs; } sub compare_filter_ok { my ( $got_file, $expected_file, $filter, $name ) = @_; ## no critic (ProtectPrivateSubs) return __PACKAGE__->_init->_compare_ok( $got_file, $expected_file, { FILTER => $filter }, $name ); } ## no critic (ProtectPrivateSubs) sub compare_ok { return __PACKAGE__->_init->_compare_ok( @_ ) } sub dir_contains_ok { my ( $dir, $file_list, @rest ) = @_; ## no critic (ProtectPrivateSubs) my $self = __PACKAGE__->_init->_validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return $self->_show_failure if @{ $self->diag }; $self->_dir_contains_ok( $dir, $file_list, { %{ $self->options }, EXISTENCE_ONLY => 1 }, $self->name ); return $self->_show_result( @{ $self->diag } ); } sub dir_only_contains_ok { my ( $dir, $file_list, @rest ) = @_; ## no critic (ProtectPrivateSubs) my $self = __PACKAGE__->_init->_validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return $self->_show_failure if @{ $self->diag }; $self->_dir_contains_ok( $dir, $file_list, { %{ $self->options }, EXISTENCE_ONLY => 1, SYMMETRIC => 1 }, $self->name ); return $self->_show_result( @{ $self->diag } ); } sub file_filter_ok { my ( $file, $expected_string, $filter, $name ) = @_; ## no critic (ProtectPrivateSubs) return __PACKAGE__->_init->_compare_ok( $file, \$expected_string, { %$FILE_OPTIONS, FILTER => $filter }, $name ); } sub file_ok { my ( $file, $expected_string, @rest ) = @_; ## no critic (ProtectPrivateSubs) return __PACKAGE__->_init->_compare_ok( $file, \$expected_string, @rest ); } sub find_ok { my ( $dir, @rest ) = @_; my $self = __PACKAGE__->_init->got( path( $dir ) ); my ( $sub ) = $self->_validate_args( 'CODE', @_ ); return $self->_show_failure if @{ $self->diag }; my @diag; my $match = sub { push( @diag, $_ ) if $_->is_file && !$sub->( "$_" ) }; $self->got->visit( $match, { recurse => $self->options->{ RECURSIVE } } ); return $self->_show_result( sprintf( $FMT_SUB_FAILED, join( "', ", sort @{ $self->diag } ) ) ); } sub _compare_dirs { my ( $self ) = @_; my $expected_dir = $self->expected; return $self->_show_failure( sprintf( $FMT_UNDEF, '$expected_dir', _get_caller_sub() ) ) unless defined( $expected_dir ); my $got_dir = $self->got; return $self->_show_failure( sprintf( $FMT_UNDEF, '$got_dir', _get_caller_sub() ) ) unless defined( $got_dir ); my $options = $self->options; 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 = $self->_dir_contains_ok( $got_dir, $expected_file_list, $options, $self->name ); my @diag = @{ $self->diag }; $got_dir = path( $got_dir ); $expected_dir = path( $expected_dir ); foreach my $file ( @$file_list ) { $self->diag( [] ); my $got_file = $got_dir ->child( $file ); my $expected_file = $expected_dir->child( $file ); my ( $got_info, $expected_info ) = $self->_get_two_files_info( $got_file, $expected_file ); $self->_compare_files( $got_info, $expected_info, $self->_relative( $got_file ), $self->_relative( $expected_file ) ) unless @{ $self->diag }; push( @diag, @{ $self->diag } ); } $self->diag( \@diag ); return $self->_show_result( sort @{ $self->diag } ); } sub _compare_files { my ( $self, $got_data, $expected_data, $got_file, $expected_file ) = @_; my $options = $self->options; if ( $options->{ EXISTENCE_ONLY } ) { $self->diag( [ sprintf( $got_data ? $FMT_SECOND_FILE_ABSENT : $FMT_FIRST_FILE_ABSENT, $got_file, $expected_file ) ] ) unless $got_data && $expected_data; return $self; } if ( $options->{ SIZE_ONLY } ) { $self->diag( [ sprintf( $FMT_DIFFERENT_SIZE, $got_file, $expected_file, $got_data, $expected_data ) ] ) unless $got_data == $expected_data; return $self; } 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 } ) ); $self->diag( [ $diff ] ) if $diff ne ''; return $self; } sub _compare_metadata { my ( $self ) = @_; my $got_metadata = eval { $self->options->{ META_DATA }->( $self->got ) }; return $self->diag( [ sprintf( $FMT_CANNOT_GET_METADATA, $self->got, $@ ) ] ) if $@; my $expected_metadata = eval { $self->options->{ META_DATA }->( $self->expected ) }; return $self->diag( [ sprintf( $FMT_CANNOT_GET_METADATA, $self->expected, $@ ) ] ) if $@; return $self if Compare( $got_metadata, $expected_metadata ); is( $got_metadata, $expected_metadata, $self->name ); return $self->diag( undef ); } sub _compare_ok { my ( $self, $got_file, $expected_file, @rest ) = @_; $self->_validate_trailing_args( \@rest, $FILE_OPTIONS ); return $self->_show_failure if @{ $self->diag }; my ( $got, $expected ) = $self->_get_two_files_info( $got_file, $expected_file, qw( $got_file $expected_file ) ); return $self->_show_failure if @{ $self->diag }; return $self->_compare_files( $got, $expected, $got_file, ref( $expected_file ) ? $EXPECTED_CONTENT : $expected_file ) ->_show_result( @{ $self->diag } ); } # 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 reference to sorted array of files found in the directory and matching all requirements. sub _dir_contains_ok { my $self = shift; my $file_list = $self->_validate_args( 'ARRAY', @_ ); return [] if @{ $self->diag }; my $options = $self->options; my $name_pattern = $options->{ NAME_PATTERN }; $name_pattern = qr/$name_pattern/; my ( $existence_only, $symmetric ) = @$options{ qw( EXISTENCE_ONLY SYMMETRIC ) }; my $detected = []; my $diag = []; my $dir = $self->got; my %file_list = map { $_ => 1 } @$file_list; my $matches = sub { my ( $file ) = @_; my $file_stat = eval { $file->stat }; return push( @$diag, sprintf( $FMT_ABSENT, $self->_relative( $file ) ) ) unless $file_stat; return if S_ISDIR( $file_stat->mode ); return push( @$diag, sprintf( $FMT_ABSENT, $self->_relative( $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, $self->_relative( $file ) ) ) if $symmetric; return; }; path( abs_path( $self->got ) )->visit( $matches, { recurse => $options->{ RECURSIVE } } ); push( @$diag, sprintf( $FMT_FAILED_TO_SEE, $self->_relative( $dir->child( $_ ) ) ) ) foreach grep { /$name_pattern/ } keys( %file_list ); $self->diag( [ sort @$diag ] ); return [ sort @$detected ]; } sub _extract { my ( $self ) = @_; $self->base( Path::Tiny->tempdir ); foreach my $archive ( $self->got, $self->expected ) { my $base = $self->base; my $targetPath = eval { $base->child( $archive )->mkdir }; return $self->diag( [ sprintf( $FMT_CANNOT_CREATE_DIR, $base->child( $archive ), $@ ) ] ) if $@; local $CWD = $targetPath; ## no critic (ProhibitLocalVars) eval { $self->options->{ EXTRACT }->( $archive ) }; return $self->diag( [ sprintf( $FMT_CANNOT_EXTRACT, $archive, $base->child( $archive ), $@ ) ] ) if $@; } $self->$_( $self->base->child( $self->$_ ) ) foreach qw( got expected ); return $self; } 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 ( $self, $file, $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; my $options = $self->options; 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 ( $self, $got_file, $expected_file, $got_name, $expected_name ) = @_; my ( $got_diag, $got_data ) = $self->_get_file_info( $got_file, $got_name ); my ( $expected_diag, $expected_data ) = $self->_get_file_info( $expected_file, $expected_name ); push( @{ $self->diag }, defined( $got_diag ) ? $got_diag : (), defined( $expected_diag ) ? $expected_diag : () ); return ( $got_data, $expected_data ); } sub _init { my ( $class ) = @_; return bless( { diag => [], name => '', options => {} }, $class ); } sub _relative { my ( $self, $file ) = @_; return defined( $self->base ) ? path( $file )->relative( $self->base ) : $file ; } sub _show_failure { my ( $self, @message ) = @_; @message = @{ $self->diag } unless @message; $Test->ok( 0, $self->name ); $Test->diag( join( "\n", @message, '' ) ); return 0; } sub _show_result { my ( $self, @message ) = @_; return @{ $self->diag } ? $self->_show_failure( @message ) : $Test->ok( 1, $self->name ); } sub _validate_args { my ( $self, $expected_type, $dir, $file_list_or_sub, @rest ) = @_; $self->_validate_trailing_args( \@rest, $DIRECTORY_OPTIONS ); return if @{ $self->diag }; unless ( defined( $dir ) ) { $self->diag( [ sprintf( $FMT_UNDEF, '$dir', _get_caller_sub() ) ] ); return; } $self->got( path( $dir ) ); unless ( $self->got->is_dir ) { $self->diag( [ sprintf( $FMT_INVALID_DIR, $dir ) ] ); return; } if ( ref( $file_list_or_sub ) ne $expected_type ) { $self->diag( [ sprintf( $FMT_INVALID_ARGUMENT, _get_caller_sub(), ( $expected_type eq 'ARRAY' ? 'array' : 'code' ) . ' reference', '2nd' ) ] ); return; } return $file_list_or_sub; } sub _validate_options { my ( $self, $default ) = @_; my $options = $self->options; my @invalid_options = grep { !exists( $default->{ $_ } ) } keys( %$options ); return $self->diag( [ sprintf( $FMT_INVALID_OPTIONS, join( "', '", @invalid_options ) ) ] ) if @invalid_options; if ( defined( $options->{ FILTER } ) ) { return $self->diag( [ 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 $self->diag( [ sprintf( $FMT_INVALID_NAME_PATTER, $options->{ NAME_PATTERN }, _get_caller_sub(), $error ) ] ) if $error; } else { $options->{ NAME_PATTERN } = $default->{ NAME_PATTERN }; } } return $self->options( { %$default, %$options } ); } sub _validate_trailing_args { my ( $self, $args, $default ) = @_; unless ( @$args ) { # 1st trailing arg omitted: use default options, no title $self->options( $default ); return $self; } my ( $first_arg, $second_arg ) = @$args; my $first_arg_type = ref( $first_arg ); unless ( $first_arg_type ) { # Scalar: use default options and 3rd param as title $self->name( $first_arg )->options( $default ); return $self; } if ( $first_arg_type eq 'HASH' ) { # Hash reference: forward both options and title $self->options( $first_arg )->_validate_options( $default ); $self->name( $second_arg )->options( { %$default, %{ $self->options } } ) unless @{ $self->diag }; return $self; } if ( $first_arg_type eq 'CODE' ) { # Code reference: forward filter as option and title $self->name( $second_arg )->options( { %$default, FILTER => $first_arg } ); return $self; } # Invalid type $self->diag( [ sprintf( $FMT_INVALID_ARGUMENT, _get_caller_sub(), 'hash reference / code reference / string', '3rd' ) ] ); return $self; } 1; Test-Files-0.26/lib/Test/Files/0000755000175100017540000000000014572631707015220 5ustar jurijjurijTest-Files-0.26/lib/Test/Files/Constants.pm0000644000175100017540000000526414572631546017542 0ustar jurijjurijpackage Test::Files::Constants; our $VERSION = '0.26'; ## no critic (RequireUseStrict, RequireUseWarnings) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline portable recursion ); use Const::Fast qw( const ); use Exporter qw( import ); use PadWalker qw( peek_our ); const our $DIRECTORY_OPTIONS => { EXISTENCE_ONLY => 0, FILTER => undef, NAME_PATTERN => '.', RECURSIVE => 0, SIZE_ONLY => 0, SYMMETRIC => 0, }; const our $ARCHIVE_OPTIONS => { %$DIRECTORY_OPTIONS, EXTRACT => sub {}, META_DATA => sub {}, }; const our $FILE_OPTIONS => { EXISTENCE_ONLY => 0, FILTER => undef, SIZE_ONLY => 0, }; const our $EXPECTED_CONTENT => ''; const our $FMT_ABSENT => "'%s' is absent, or is a directory, or is a special file"; const our $FMT_ABSENT_WITH_ERROR => "'%s' is absent, error: %s"; const our $FMT_CANNOT_CREATE_DIR => "Cannot create directory '%s': %s"; const our $FMT_CANNOT_EXTRACT => "Cannot extract from '%s' to directory '%s': %s"; const our $FMT_CANNOT_GET_METADATA => "Cannot get metadata from '%s': %s"; const our $FMT_DIFFERENT_SIZE => "'%s' and '%s' have different sizes: %d and %d bytes, correspondingly"; const our $FMT_FAILED_TO_SEE => "Failed to see '%s'"; const our $FMT_FILTER_ISNT_CODEREF => "Filter supplied to '%s' must be a code reference (or undef)"; const our $FMT_FIRST_FILE_ABSENT => "'%s' is present but '%s' is absent"; const our $FMT_INVALID_ARGUMENT => "'%s' requires %s as %s argument"; const our $FMT_INVALID_DIR => "'%s' is not a valid directory"; const our $FMT_INVALID_NAME_PATTER => "Name pattern '%s' supplied to '%s' is invalid: %s"; const our $FMT_INVALID_OPTIONS => "Invalid options detected: '%s'"; const our $FMT_SECOND_FILE_ABSENT => "'%s' is absent but '%s' is present"; const our $FMT_SUB_FAILED => "Passed subroutine failed for '%s'"; const our $FMT_UNDEF => "Argument '%s' of '%s' must be a string or a Path::Tiny object"; const our $FMT_UNEXPECTED => "Unexpectedly saw: '%s'"; const our $UNKNOWN => ''; const our %DIFF_OPTIONS => ( CONTEXT => 3, # change this one later if needed FILENAME_A => 'Got', FILENAME_B => 'Expected', INDEX_LABEL => 'Ln', KEYGEN => undef, KEYGEN_ARGS => undef, MTIME_A => undef, MTIME_B => undef, OFFSET_A => 1, OFFSET_B => 1, OUTPUT => undef, STYLE => 'Unified', ); push( our @EXPORT_OK, keys( %{ peek_our( 0 ) } ) ); 1; Test-Files-0.26/lib/Test/Files.pod0000644000175100017540000005414114572077615015733 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. =item If the archive (container) being tested is logically identical to the the reference archive (container). If necessary, some members of archives, as well as some parts of their contents, as well as some metadata can be excluded from the comparison. =back =head1 SYNOPSIS All examples listed below can be found and executed using B located on L. 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( 24 ); # 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'" ); # Compares PKZIP archives considering both global and file comments. # Both archives contain the same members in different order: my $extract = sub { my ( $file ) = @_; my $zip = Archive::Zip->new(); die( "Cannot read '$file'" ) if $zip->read( $file ) != AZ_OK; die( "Cannot extract from '$file'" ) if $zip->extractTree != AZ_OK; }; my $meta_data = sub { my ( $file ) = @_; my $zip = Archive::Zip->new(); die( "Cannot read '$file'" ) if $zip->read( $file ) != AZ_OK; my %meta_data = ( '' => $zip->zipfileComment ); $meta_data{ $_->fileName } = $_->fileComment foreach $zip->members; return \%meta_data; }; my $got_compressed_content = path( "$got_file.zip" )->slurp; my $reference_compressed_content = path( "$reference_file.zip" )->slurp; ok( $got_compressed_content ne $reference_compressed_content, "'$got_file.zip' and '$reference_file.zip' are physically different, but" ); compare_archives_ok( "$got_file.zip", "$reference_file.zip", { EXTRACT => $extract, META_DATA => $meta_data }, "'$got_file.zip' and '$reference_file.zip' are logically identical" ); =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