1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use MooX::Cmd::Tester;
use FindBin qw($Bin);
use lib "$Bin/lib";
use FirstTestApp;
use SecondTestApp;
use ThirdTestApp;
use FailTestApp;
my @tests = (
['test', ["FirstTestApp::Cmd::Test", [], ["FirstTestApp"]]],
['test test', ["FirstTestApp::Cmd::Test::Cmd::Test", [], ["FirstTestApp", "FirstTestApp::Cmd::Test"]]],
['test this', ["FirstTestApp::Cmd::Test", ["this"], ["FirstTestApp"]]],
['this test test this', ["FirstTestApp::Cmd::Test::Cmd::Test", ["this"], ["FirstTestApp", "FirstTestApp::Cmd::Test"]]],
['test this test', ["FirstTestApp::Cmd::Test::Cmd::Test", [], ["FirstTestApp", "FirstTestApp::Cmd::Test"]]],
['ifc', ["SecondTestApp::Cmd::ifc", [], ["SecondTestApp"]]],
['cwo', ["SecondTestApp::Cmd::cwo", [], ["SecondTestApp"]]],
);
for (@tests)
{
my ($args, $result) = @{$_};
ref $args or $args = [split(' ', $args)];
my $rv = test_cmd_ok($result->[2]->[0] => $args);
# my $app = FirstTestApp->new_with_cmd;
# isa_ok($app,'FirstTestApp');
#my @execute_return = @{$app->execute_return};
"ARRAY" eq ref $rv->execute_rv or diag(explain($rv));
my @execute_return = @{$rv->execute_rv};
my @moox_cmd_chain = map { ref $_ } @{$execute_return[2]};
push @{$result->[2]}, $result->[0];
my $execute_result = [ref $execute_return[0], $execute_return[1], \@moox_cmd_chain];
is_deeply($execute_result, $result, 'Checking result of "' . join(" ", @$args) . '"');
}
{
my $rv = test_cmd_ok(ThirdTestApp => [qw(foo)]);
my $nothing;
is_deeply(\$nothing, \$rv->{execute_return}, 'Checking result of "ThirdTestApp => [foo]"');
}
{
my $rv = test_cmd(FailTestApp => [qw(nothing)]);
like($rv->error, qr/need.*execute.*nothing/, "Load fails for FailTestApp => [nothing]");
}
{
my $rv = test_cmd(FailTestApp => [qw(uncreatable)]);
like($rv->error, qr/Can't find a creation method/, "Load fails for FailTestApp => [nothing]");
}
{
my $rv = test_cmd(FailTestApp => [qw(nocreatable)]);
like($rv->error, qr/Can't find a creation method/, "Load fails for FailTestApp => [nothing]");
}
done_testing;
|