App-mvr
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More tests => 4;
use Capture::Tiny qw(capture);
use Test::Fatal qw(lives_ok);
use Path::Tiny;
use App::mvr;
my $wd = path( 'corpus', path(__FILE__)->basename );
END { path($wd)->remove_tree }
subtest main => sub {
plan tests => 6;
path($wd)->remove_tree;
path($wd, "$_.jpg.tar.gz.txt")->touchpath for qw( one two three d/three );
lives_ok {
mvr(
source => [map { path($wd, "$_.jpg.tar.gz.txt") } qw/ one two three /],
dest => path($wd, 'd'),
);
} "mvr call didn't die";
ok path($wd, 'd', "$_.jpg.tar.gz.txt")->exists, "corpus/d/$_.jpg.tar.gz.txt exists"
for (qw/ one two three /);
my @files = grep {
defined
and $_->basename !~ qr/^(?:one|two|three)\Q.jpg.tar.gz.txt\E$/
} path($wd, 'd')->children;
is scalar @files => 1;
like $files[0] => qr{three\Q.jpg.tar.gz\E-.{6}\.txt$};
note "found $files[0]";
};
subtest verbosity => sub {
plan tests => 4;
path($wd)->remove_tree;
path($wd, $_)->touchpath for qw( verbose d/verbose );
{
my ($out, $err) = capture {
local $App::mvr::VERBOSE = 2;
mvr(
source => path($wd, 'verbose'),
dest => path($wd, 'd', 'verbose')
);
};
is $out => '';
like $err => qr{\QFile already exists};
}
path($wd)->remove_tree;
path($wd, $_)->touchpath for qw( quiet d/quiet );
{
my ($out, $err) = capture {
local $App::mvr::VERBOSE = 0;
mvr(
source => path($wd, 'quiet'),
dest =>path($wd, 'd', 'quiet' )
);
};
is $out => '', 'no stdout';
is $err => '', 'no stderr';
( run in 1.022 second using v1.01-cache-2.11-cpan-54e63673c56 )