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

NAME

6       App::Cmd::Tester - for capturing the result of running an app
7

VERSION

9       version 0.334
10

SYNOPSIS

12         use Test::More tests => 4;
13         use App::Cmd::Tester;
14
15         use YourApp;
16
17         my $result = test_app(YourApp => [ qw(command --opt value) ]);
18
19         like($result->stdout, qr/expected output/, 'printed what we expected');
20
21         is($result->stderr, '', 'nothing sent to sderr');
22
23         is($result->error, undef, 'threw no exceptions');
24
25         my $result = test_app(YourApp => [ qw(command --opt value --quiet) ]);
26
27         is($result->output, '', 'absolutely no output with --quiet');
28

DESCRIPTION

30       One of the reasons that user-executed programs are so often poorly
31       tested is that they are hard to test.  App::Cmd::Tester is one of the
32       tools App-Cmd provides to help make it easy to test App::Cmd-based
33       programs.
34
35       It provides one routine: test_app.
36

PERL VERSION SUPPORT

38       This module has a long-term perl support period.  That means it will
39       not require a version of perl released fewer than five years ago.
40
41       Although it may work on older versions of perl, no guarantee is made
42       that the minimum required version will not be increased.  The version
43       may be increased for any reason, and there is no promise that patches
44       will be accepted to lower the minimum required perl.
45

METHODS

47   test_app
48       Note: while "test_app" is a method, it is by default exported as a
49       subroutine into the namespace that uses App::Cmd::Tester.  In other
50       words: you probably don't need to think about this as a method unless
51       you want to subclass App::Cmd::Tester.
52
53         my $result = test_app($app_class => \@argv_contents);
54
55       This will locally set @ARGV to simulate command line arguments, and
56       will then call the "run" method on the given application class (or
57       application).  Output to the standard output and standard error
58       filehandles  will be captured.
59
60       $result is an App::Cmd::Tester::Result object, which has methods to
61       access the following data:
62
63         stdout - the output sent to stdout
64         stderr - the output sent to stderr
65         output - the combined output of stdout and stderr
66         error  - the exception thrown by running the application, or undef
67         run_rv - the return value of the run method (generally irrelevant)
68         exit_code - the numeric exit code that would've been issued (0 is 'okay')
69
70       The output is captured using IO::TieCombine, which can ensure that the
71       ordering is preserved in the combined output, but can't capture the
72       output of external programs.  You can reverse these tradeoffs by using
73       App::Cmd::Tester::CaptureExternal instead.
74

AUTHOR

76       Ricardo Signes <rjbs@semiotic.systems>
77
79       This software is copyright (c) 2021 by Ricardo Signes.
80
81       This is free software; you can redistribute it and/or modify it under
82       the same terms as the Perl 5 programming language system itself.
83
84
85
86perl v5.34.0                      2022-01-20               App::Cmd::Tester(3)
Impressum