19 Dec 2017 16:50:35 UTC
- Distribution: MooX-Cmd
- Module version: 0.017
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Issues (0)
- Testers (1194 / 0 / 1)
- KwaliteeBus factor: 2
- 94.00% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity24 month
- Download (18.1KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- LICENSE AND COPYRIGHT
MooX::Cmd::Tester - MooX cli app commands tester
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" );
The test coverage of most CLI apps is somewhere between poor and wretched. With the same approach as App::Cmd::Tester comes MooX::Cmd::Tester to ease writing tests for CLI apps.
my $rv = test_cmd( MyApp => \@argv );
test_cmd invokes the app with given argv as if would be invoked from command line and captures the output, the return values and exit code.
Some minor tests are done to prove whether class matches, execute succeeds, command_name and command_chain are not totally scrambled.
It returns an object with following attributes/accessors:
Name of package of App
Name of executed (1st level) command
Content of stdout
Content of stderr
Content of merged stdout and stderr
the exception thrown by running the application (if any)
return values from execute
0 on success, $! when error occurred and $! available, -1 otherwise
my $rv = test_cmd_ok( MyApp => \@argv );
test_cmdand expects it being successful - command_name must be in command_commands, etc.
Returns the same object
If an error occurred, no additional test is done (behavior as
Builder for result class to use. Returns
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.
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.