MooX-Cmd
view release on metacpan or search on metacpan
lib/MooX/Cmd/Tester.pm view on Meta::CPAN
8687888990919293949596979899100101102103104105106sub
_run_with_capture
{
my
(
$app
,
$argv
) =
@_
;
my
(
$execute_rv
,
$cmd
,
$cmd_name
,
$error
);
my
(
$stdout
,
$stderr
,
$merged
,
$ok
) = _capture_merged
{
eval
{
local
$TEST_IN_PROGRESS
= 1;
local
@ARGV
=
@$argv
;
my
$tb
=
$CLASS
->builder();
$cmd
=
ref
$app
?
$app
:
$app
->new_with_cmd;
ref
$app
and
$app
=
ref
$app
;
my
$test_ident
=
"$app => [ "
.
join
(
" "
,
@$argv
) .
" ]"
;
ok(
$cmd
->isa(
$app
),
"got a '$app' from new_with_cmd"
);
@$argv
and
defined
(
$cmd_name
=
$cmd
->command_name)
and ok((
grep
{
index
(
$cmd_name
,
$_
) != -1 }
@$argv
),
"proper cmd name from $test_ident"
);
t/03-params.t view on Meta::CPAN
789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112use
MooX::Cmd::Tester;
use
FirstTestApp;
use
SecondTestApp;
use
ThirdTestApp;
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_execute_method_name
=>
"run"
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"'
);
}
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_base
=>
"SecondTestApp::Cmd"
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"'
);
}
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_creation_chain_methods
=>
"new"
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_creation_chain_methods => "new") => []"'
);
}
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_commands
=> {
ifc
=>
"SecondTestApp::Cmd::ifc"
,
cwo
=>
"SecondTestApp::Cmd::cwo"
}
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_commands => {ifc => "SecondTestApp::Cmd::ifc", cwo => "SecondTestApp::Cmd::cwo"}) => []"'
);
}
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_base
=>
"SecondTestApp::Cmd"
,
command_creation_chain_methods
=>
"new"
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"'
);
}
{
local
@ARGV
=
qw(foo)
;
my
$cmd
= ThirdTestApp->new_with_cmd(
command_execute_from_new
=>
undef
);
my
$rv
= test_cmd_ok(
$cmd
, [
qw(foo)
]);
is(
$rv
->execute_rv,
undef
,
'Checking result of "ThirdTestApp(command_execute_from_new => undef) => []"'
);
}
{
local
@ARGV
=
qw(foo)
;
my
$cmd
= ThirdTestApp->new_with_cmd(
command_execute_from_new
=> 0);
my
$rv
= test_cmd_ok(
$cmd
, [
qw(foo)
]);
is_deeply(
$rv
->execute_rv,
undef
,
'Checking result of "ThirdTestApp(command_execute_from_new => 0) => []"'
);
}
{
local
@ARGV
;
my
$cmd
= SecondTestApp->new_with_cmd(
command_execute_return_method_name
=>
"was_haste"
);
my
$rv
= test_cmd_ok(
$cmd
, []);
my
@execute_return
= @{
$rv
->execute_rv};
is_deeply(\
@execute_return
, [
$cmd
],
'Checking result of "SecondTestApp(command_execute_return_method_name => "was_haste") => []"'
);
}
{
local
@ARGV
;
eval
{
my
$cmd
= SecondTestApp->new_with_cmd(
command_creation_chain_methods
=>
"search_me"
); };
like(
$@,
qr/Can't find a creation method on/
,
'Load fails for SecondTestApp(command_creation_chain_methods => "search_me") => []'
);
}
SKIP:
{
eval
"use MooX::Options 4.100; use OptionTestApp"
;
$@ and skip(
"MooX::Options required 4.100 $@"
, 1);
local
@ARGV
=
qw(oops)
;
my
$cmd
=
eval
{ OptionTestApp->new_with_cmd(
command_creation_chain_methods
=>
"new_with_options"
); };
like(
$@,
qr/Can't find a creation method on/
,
'Load fails for OptionTestApp(command_creation_chain_methods => "new_with_options") => []'
);
}
done_testing;
( run in 0.522 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )