MooX::...:Tester(3pm)
π NAME π
MooX::Cmd::Tester β it's the tester bestie for your MooX cli app commands, fr fr π§
β¨ SYNOPSIS β¨
use MooX::Cmd::Tester;
use Test::More;
use MyFoo;
# basic tests as instance check, initialization check etc. is done there
my $rv = test_cmd( MyFoo => [ command(s) option(s) ] );
like( $rv->stdout, qr/operation successful/, "Command performed" );
like( $rv->stderr, qr/patient dead/, "Deal with expected command error" );
is_deeply( $rv->execute_rv, \@expected_return_values, "got what I deserve?" );
cmp_ok( $rv->exit_code, "==", 0, "Command successful" );
π¦ DESCRIPTION π¦
okay so real talk: the test coverage of most CLI apps is somewhere between poor and wretched π like genuinely embarrassing levels of un-tested. and bestie, we are NOT doing that.
using the exact same approach as App::Cmd::Tester, here comes MooX::Cmd::Tester to make writing tests for CLI apps actually... easy? cute? doable? all of the above β¨
πΈ FUNCTIONS πΈ
π test_cmd
my $rv = test_cmd( MyApp => \@argv );
test_cmd invokes the app with the given argv as if it would be invoked from command line β and it captures the output, the return values and the exit code. no cap, it just does all of it for you π«Ά
Some minor tests are done to prove whether class matches, execute succeeds, command_name and command_chain are not totally scrambled. (vibe check on your internals, basically β¨)
It returns an object with the following attributes/accessors:
appβ Name of package of Appcmdβ Name of executed (1st level) commandstdoutβ Content ofstdoutstderrβ Content ofstderroutputβ Content of mergedstdoutandstderrerrorβ the exception thrown by running the application (if any) πexecute_rvβ return values fromexecuteexit_codeβ0on success,$!when error occurred and$!available,-1otherwise
π test_cmd_ok
my $rv = test_cmd_ok( MyApp => \@argv );
Runs test_cmd and expects it being successful β command_name must be in command_commands, etc. π
Returns the same object test_cmd returns.
If an error occurred, no additional test is done (behavior as test_cmd). so like, it's not gonna pile on you when things go wrong π
β result_class
Builder for result class to use. Returns MooX::Cmd::Tester::Result by default. slay.
π ACKNOWLEDGEMENTS π
MooX::Cmd::Tester is inspired by App::Cmd::Tester from Ricardo Signes. In fact, I reused the entire design and adopt it to the requirements of MooX::Cmd. iconic behavior, honestly π
π LICENSE AND COPYRIGHT π
Copyright 2013-2017 Jens Rehsack.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See <http://dev.perl.org/licenses/> for more information.
and that's the whole page bestie, we ate and left no crumbs π β¨
this has been a User Contributed Perl Documentation moment β page generated by perl v5.36.0 on 2022-11-19, mwah π
π¦ where this page comes from
- debian bookworm: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libmoox-cmd-perl 0.017-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms