Subject: | MooX::Cmd::Tester: incorrect execute_return if execute_from_new => undef |
If execute_from_new is undef, the execute_rv value returned from test_cmd's returned object isn't correct.
Here's the test code:
------------------------------------------
package MyApp;
use Moo;
use MooX::Cmd;
sub execute { __PACKAGE__ };
package MyAppNoExec;
use Moo;
use MooX::Cmd execute_from_new => undef;
sub execute { __PACKAGE__ };
package main;
use Test::More;
use Moo;
use MooX::Cmd::Tester;
use Data::Dumper;
print Dumper test_cmd( 'MyApp', [] )->execute_rv;
print Dumper test_cmd( 'MyAppNoExec', [] )->execute_rv;
done_testing;
------------------------------------------
And here are the results:
------------------------------------------
% perl test.pl
ok 1 - got a 'MyApp' from new_with_cmd
ok 2 - $\#argv vs. command chain length testing MyApp => [ ]
$VAR1 = [
'MyApp'
];
ok 3 - got a 'MyAppNoExec' from new_with_cmd
ok 4 - $\#argv vs. command chain length testing MyAppNoExec => [ ]
$VAR1 = [];
1..4
------------------------------------------
The problem seems to be in MooX::Cmd::Tester::_run_with_capture
97 $cmd->command_execute_from_new
98 or $cmd->can( $cmd->command_execute_method_name )->($cmd);
99 my @execute_return = @{ $cmd->can($cmd->command_execute_return_method_name)->($cmd) };
$cmd->can( $cmd->command_execute_method_name) returns MyApp::execute directly, so there's no wrapper to catch the return value and thus populate the execute_return slot in $cmd