MouseX-App-Cmd
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/MouseX/App/Cmd/Command.pm view on Meta::CPAN
has app => (
is => 'ro',
required => 1,
metaclass => 'NoGetopt',
isa => 'MouseX::App::Cmd',
);
override _process_args => sub {
my ( $class, $args ) = @_;
local @ARGV = @{$args};
my $config_from_file;
if ( $class->meta->does_role('MouseX::ConfigFromFile') ) {
local @ARGV = @ARGV;
my $configfile;
my $opt_parser;
{
## no critic (Modules::RequireExplicitInclusion)
$opt_parser
= Getopt::Long::Parser->new( config => ['pass_through'] );
}
$opt_parser->getoptions( 'configfile=s' => \$configfile );
if ( not defined $configfile
Test::MyCmd::Command::bark
Test::MyCmd::Command::frobulate
Test::MyCmd::Command::justusage
Test::MyCmd::Command::stock
)
],
'got correct list of registered command plugins',
);
{
local @ARGV = qw(frob --widget wname your fat face);
eval { $cmd->run };
is( $@,
"the widget name is wname - your fat face\n",
'command died with the correct string',
);
}
{
local @ARGV = qw(justusage);
eval { $cmd->run };
my $error = $@;
like( $error, qr/^basic.t justusage/, 'default usage_desc is okay' );
}
{
local @ARGV = qw(stock);
eval { $cmd->run };
like( $@, qr/mandatory method/, 'un-subclassed &run leads to death' );
}
{
local @ARGV = qw(bark);
eval { $cmd->run };
like(
$@,
qr/Mandatory parameter 'wow' missing in call to ["(]eval[)"]/,
'required option field is missing',
);
}
SKIP: {
my $have_TO = eval { require Test::Output; 1; };
print STDERR $@;
skip 'these tests require Test::Output', 5 unless $have_TO;
local @ARGV = qw(commands);
my ($output) = Test::Output::output_from( sub { $cmd->run } );
for my $name (qw(commands frobulate justusage stock bark)) {
like( $output, qr/^\s+\Q$name\E/sm, "$name plugin in listing" );
}
}
t/configfile.t view on Meta::CPAN
plan tests => 3;
}
}
use lib 't/lib';
use Test::ConfigFromFile;
my $cmd = Test::ConfigFromFile->new;
{
local @ARGV = qw(moo);
eval { $cmd->run };
like(
$@,
qr/Mandatory parameter 'moo' missing in call to ["(]eval[)"]/,
'command died with the correct string',
);
}
{
local @ARGV = qw(moo --configfile=t/lib/Test/ConfigFromFile/config.yaml);
eval { $cmd->run };
like(
$@,
qr/cows go moo1 moo2 moo3/,
'command died with the correct string',
);
}
{
local @ARGV = qw(boo);
eval { $cmd->run };
like( $@, qr/ghosts go moo1 moo2 moo3/, 'default configfile read', );
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.045 second using v1.00-cache-2.02-grep-82fe00e-cpan-c9a218a2bbc )