1MooX::Cmd::Tester(3)  User Contributed Perl Documentation MooX::Cmd::Tester(3)
2
3
4

NAME

6       MooX::Cmd::Tester - MooX cli app commands tester
7

SYNOPSIS

9         use MooX::Cmd::Tester;
10         use Test::More;
11
12         use MyFoo;
13
14         # basic tests as instance check, initialization check etc. is done there
15         my $rv = test_cmd( MyFoo => [ command(s) option(s) ] );
16
17         like( $rv->stdout, qr/operation successful/, "Command performed" );
18         like( $rv->stderr, qr/patient dead/, "Deal with expected command error" );
19
20         is_deeply( $rv->execute_rv, \@expected_return_values, "got what I deserve?" );
21
22         cmp_ok( $rv->exit_code, "==", 0, "Command successful" );
23

DESCRIPTION

25       The test coverage of most CLI apps is somewhere between poor and
26       wretched.  With the same approach as App::Cmd::Tester comes
27       MooX::Cmd::Tester to ease writing tests for CLI apps.
28

FUNCTIONS

30   test_cmd
31         my $rv = test_cmd( MyApp => \@argv );
32
33       test_cmd invokes the app with given argv as if would be invoked from
34       command line and captures the output, the return values and exit code.
35
36       Some minor tests are done to prove whether class matches, execute
37       succeeds, command_name and command_chain are not totally scrambled.
38
39       It returns an object with following attributes/accessors:
40
41       app
42
43       Name of package of App
44
45       cmd
46
47       Name of executed (1st level) command
48
49       stdout
50
51       Content of stdout
52
53       stderr
54
55       Content of stderr
56
57       output
58
59       Content of merged stdout and stderr
60
61       error
62
63       the exception thrown by running the application (if any)
64
65       execute_rv
66
67       return values from execute
68
69       exit_code
70
71       0 on success, $! when error occurred and $! available, -1 otherwise
72
73   test_cmd_ok
74         my $rv = test_cmd_ok( MyApp => \@argv );
75
76       Runs "test_cmd" and expects it being successful - command_name must be
77       in command_commands, etc.
78
79       Returns the same object "test_cmd" returns.
80
81       If an error occurred, no additional test is done (behavior as
82       "test_cmd").
83
84   result_class
85       Builder for result class to use. Returns "MooX::Cmd::Tester::Result" by
86       default.
87

ACKNOWLEDGEMENTS

89       MooX::Cmd::Tester is inspired by App::Cmd::Tester from Ricardo Signes.
90       In fact, I reused the entire design and adopt it to the requirements of
91       MooX::Cmd.
92
94       Copyright 2013-2017 Jens Rehsack.
95
96       This program is free software; you can redistribute it and/or modify it
97       under the terms of either: the GNU General Public License as published
98       by the Free Software Foundation; or the Artistic License.
99
100       See <http://dev.perl.org/licenses/> for more information.
101
102
103
104perl v5.32.0                      2020-07-28              MooX::Cmd::Tester(3)
Impressum