App-Sqitch
view release on metacpan or search on metacpan
t/command.t view on Meta::CPAN
"# This that\n# and the other\n",
'comment should work';
$sqitch->{verbosity} = 0;
is capture_stdout { $sqitch->comment('This ', "that\n", 'and the other') },
"# This that\n# and the other\n",
'comment should work with verbosity 0';
# Comment literal.
$sqitch->{verbosity} = 1;
is capture_stdout { $cmd->comment_literal('This ', "that\n", 'and the other') },
"# This that\n# and the other",
'comment_literal should work';
$sqitch->{verbosity} = 0;
is capture_stdout { $sqitch->comment_literal('This ', "that\n", 'and the other') },
"# This that\n# and the other",
'comment_literal should work with verbosity 0';
# Emit.
is capture_stdout { $cmd->emit('This ', "that\n", 'and the other') },
"This that\nand the other\n",
'emit should work';
$sqitch->{verbosity} = 0;
is capture_stdout { $cmd->emit('This ', "that\n", 'and the other') },
"This that\nand the other\n",
'emit should work even with verbosity 0';
# Emit literal.
is capture_stdout { $cmd->emit_literal('This ', "that\n", 'and the other') },
"This that\nand the other",
'emit_literal should work';
$sqitch->{verbosity} = 0;
is capture_stdout { $cmd->emit_literal('This ', "that\n", 'and the other') },
"This that\nand the other",
'emit_literal should work even with verbosity 0';
# Warn.
is capture_stderr { $cmd->warn('This ', "that\n", 'and the other') },
"warning: This that\nwarning: and the other\n",
'warn should work';
# Warn literal.
is capture_stderr { $cmd->warn_literal('This ', "that\n", 'and the other') },
"warning: This that\nwarning: and the other",
'warn_literal should work';
# Usage.
$catch_exit = 1;
like capture_stderr {
throws_ok { $cmd->usage('Invalid whozit') } qr/EXITED: 2/
}, qr/Invalid whozit/, 'usage should work';
like capture_stderr {
throws_ok { $cmd->usage('Invalid whozit') } qr/EXITED: 2/
}, qr/\Qsqitch <command> [options] [command-options] [args]/,
'usage should prefer sqitch-$command-usage';
##############################################################################
# Test _mkpath.
require MockOutput;
my $path = dir 'delete.me';
dir_not_exists_ok $path, "Path $path should not exist";
END { remove_tree $path->stringify if -e $path }
ok $cmd->_mkpath($path), "Create $path";
dir_exists_ok $path, "Path $path should now exist";
is_deeply +MockOutput->get_debug, [[' ', __x 'Created {file}', file => $path]],
'The mkdir info should have been output';
# Create it again.
ok $cmd->_mkpath($path), "Create $path again";
dir_exists_ok $path, "Path $path should still exist";
is_deeply +MockOutput->get_debug, [], 'Nothing should have been emitted';
# Handle errors.
FSERR: {
# Make mkpath to insert an error.
my $mock = Test::MockModule->new('File::Path');
$mock->mock( mkpath => sub {
my ($file, $p) = @_;
${ $p->{error} } = [{ $file => 'Permission denied yo'}];
return;
});
throws_ok { $cmd->_mkpath('foo') } 'App::Sqitch::X',
'Should fail on permission issue';
is $@->ident, 'good', 'Permission error should have ident "good"';
is $@->message, __x(
'Error creating {path}: {error}',
path => 'foo',
error => 'Permission denied yo',
), 'The permission error should be formatted properly';
# Try an error with no path.
throws_ok { $cmd->_mkpath('') } 'App::Sqitch::X',
'Should fail on nonexistent file';
is $@->ident, 'good', 'Nonexistant path error should have ident "good"';
is $@->message, 'Permission denied yo',
'Nonexistant path error should be the message';
}
( run in 0.587 second using v1.01-cache-2.11-cpan-39bf76dae61 )