App-Cmd
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/Cmd/ArgProcessor.pm view on Meta::CPAN
use strict;
use warnings;
package App::Cmd::ArgProcessor 0.336;
# ABSTRACT: App::Cmd-specific wrapper for Getopt::Long::Descriptive
sub _process_args {
my ($class, $args, @params) = @_;
local @ARGV = @$args;
require Getopt::Long::Descriptive;
Getopt::Long::Descriptive->VERSION(0.084);
my ($opt, $usage) = Getopt::Long::Descriptive::describe_options(@params);
return (
$opt,
[ @ARGV ], # whatever remained
usage => $usage,
lib/App/Cmd/Tester.pm view on Meta::CPAN
#pod
#pod =method test_app
#pod
#pod B<Note>: while C<test_app> is a method, it is by default exported as a
#pod subroutine into the namespace that uses App::Cmd::Tester. In other words: you
#pod probably don't need to think about this as a method unless you want to subclass
#pod App::Cmd::Tester.
#pod
#pod my $result = test_app($app_class => \@argv_contents);
#pod
#pod This will locally set C<@ARGV> to simulate command line arguments, and will
#pod then call the C<run> method on the given application class (or application).
#pod Output to the standard output and standard error filehandles will be captured.
#pod
#pod C<$result> is an App::Cmd::Tester::Result object, which has methods to access
#pod the following data:
#pod
#pod stdout - the output sent to stdout
#pod stderr - the output sent to stderr
#pod output - the combined output of stdout and stderr
#pod error - the exception thrown by running the application, or undef
lib/App/Cmd/Tester/CaptureExternal.pm view on Meta::CPAN
#pod =cut
sub _run_with_capture {
my ($class, $app, $argv) = @_;
my $run_rv;
my ($stdout, $stderr, $ok) = capture {
eval {
local $App::Cmd::Tester::TEST_IN_PROGRESS = 1;
local @ARGV = @$argv;
$run_rv = $app->run;
1;
};
};
my $error = $ok ? undef : $@;
return {
stdout => $stdout,
stderr => $stderr,
Test::MyCmd::Command::exit
Test::MyCmd::Command::frobulate
Test::MyCmd::Command::hello
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 { $app->run };
is(
$@,
"the widget name is wname - your fat face\n",
"command died with the correct string",
);
}
{
local @ARGV = qw(justusage);
eval { $app->run };
my $error = $@;
like(
$error,
qr/^basic.t justusage/,
"default usage_desc is okay",
);
}
{
local @ARGV = qw(stock);
eval { $app->run };
like($@, qr/mandatory method/, "un-subclassed &run leads to death");
}
my $return = test_app('Test::MyCmd', [ qw(--version) ]);
like(
$return->stdout,
qr{\Abasic\.t \(Test::MyCmd\) version 0\.123 \(t[\\/]basic\.t\)\Z},
t/setup-inner.t view on Meta::CPAN
[ qw(
App::Cmd::Command::commands
App::Cmd::Command::help
App::Cmd::Command::version
Test::WSOF::Command::poot
) ],
"got correct list of registered command plugins",
);
{
local @ARGV = qw(poot);
my $return = eval { $app->run };
is($return, 'woof woof poot', "inner package commands work with Setup");
}
t/setup-nocmd.t view on Meta::CPAN
[ qw(
App::Cmd::Command::commands
App::Cmd::Command::help
App::Cmd::Command::version
Test::WSNCC::Command::blort
) ],
"got correct list of registered command plugins",
);
{
local @ARGV = qw(blort);
my $return = eval { $app->run };
is_deeply(
$return,
{},
"basically run",
);
}
App::Cmd::Command::commands
App::Cmd::Command::help
App::Cmd::Command::version
Test::WithSetup::Command::alfie
Test::WithSetup::Command::bertie
) ],
"got correct list of registered command plugins",
);
{
local @ARGV = qw(alfie);
my $return = eval { $app->run };
is_deeply(
$return,
{},
"basically run",
);
}
{
local @ARGV = qw(alfie --why);
my ($stderr, $return) = capture_stderr(sub {
eval { $app->run }
});
is_deeply(
$return,
undef,
"unknown option with overridden getopt_conf caused program to exit",
);
like(
$stderr,
qr{Unknown option: why},
"and gives the standard G::L::D missing option message",
);
}
{
local @ARGV = qw(bertie);
my $return = eval { $app->run };
is($return->[0], 'Test::XyzzyPlugin', "arg0 = plugin itself");
isa_ok($return->[1], 'Test::WithSetup::Command');
isa_ok($return->[1], 'Test::WithSetup::Command::bertie');
is_deeply(
$return->[2],
[ qw(foo bar) ],
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.538 second using v1.00-cache-2.02-grep-82fe00e-cpan-da92000dfeb )