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.331
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

METHODS

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

AUTHOR

67       Ricardo Signes <rjbs@cpan.org>
68
70       This software is copyright (c) 2016 by Ricardo Signes.
71
72       This is free software; you can redistribute it and/or modify it under
73       the same terms as the Perl 5 programming language system itself.
74
75
76
77perl v5.30.1                      2020-01-29               App::Cmd::Tester(3)
Impressum