1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
use 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 );
};
|