-
-
19 Jun 2021 02:14:59 UTC
- Distribution: App-Cmd
- Module version: 0.334
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (1878 / 0 / 58)
- Kwalitee
Bus factor: 1- 87.27% Coverage
- License: perl_5
- Perl: v5.20.0
- Activity
24 month- Tools
- Download (49KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 28 contributors-
Ricardo Signes
-
Adam Prime
-
ambs
-
Andreas Hernitscheck
-
A. Sinan Unur
-
Chris 'BinGOs' Williams
-
David Golden
-
David Steinbrunner
-
Davor Cubranic
-
Denis Ibaev
-
Diab Jerius
-
Glenn Fowler
-
Ingy dot Net
-
Jakob Voss
-
Jérôme Quelin
-
John SJ Anderson
-
Karen Etheridge
-
Kent Fredric
-
Lucas Theisen
-
Matthew Astley
-
mokko
-
Olivier Mengué
-
Ryan C. Thompson
-
Salvatore Bonaccorso
-
Sergey Romanov
-
Stephan Loyd
-
Stephen Caldwell
-
Yuval Kogman
- Dependencies
- Capture::Tiny
- Carp
- Class::Load
- Data::OptList
- File::Basename
- Getopt::Long
- Getopt::Long::Descriptive
- IO::TieCombine
- Module::Pluggable::Object
- Pod::Usage
- String::RewritePrefix
- Sub::Exporter
- Sub::Exporter::Util
- Sub::Install
- Text::Abbrev
- constant
- experimental
- parent
- strict
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
App::Cmd::Tester - for capturing the result of running an app
VERSION
version 0.334
SYNOPSIS
use Test::More tests => 4; use App::Cmd::Tester; use YourApp; my $result = test_app(YourApp => [ qw(command --opt value) ]); like($result->stdout, qr/expected output/, 'printed what we expected'); is($result->stderr, '', 'nothing sent to sderr'); is($result->error, undef, 'threw no exceptions'); my $result = test_app(YourApp => [ qw(command --opt value --quiet) ]); is($result->output, '', 'absolutely no output with --quiet');
DESCRIPTION
One of the reasons that user-executed programs are so often poorly tested is that they are hard to test. App::Cmd::Tester is one of the tools App-Cmd provides to help make it easy to test App::Cmd-based programs.
It provides one routine: test_app.
PERL VERSION SUPPORT
This module has a long-term perl support period. That means it will not require a version of perl released fewer than five years ago.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
METHODS
test_app
Note: while
test_app
is a method, it is by default exported as a subroutine into the namespace that uses App::Cmd::Tester. In other words: you probably don't need to think about this as a method unless you want to subclass App::Cmd::Tester.my $result = test_app($app_class => \@argv_contents);
This will locally set
@ARGV
to simulate command line arguments, and will then call therun
method on the given application class (or application). Output to the standard output and standard error filehandles will be captured.$result
is an App::Cmd::Tester::Result object, which has methods to access the following data:stdout - the output sent to stdout stderr - the output sent to stderr output - the combined output of stdout and stderr error - the exception thrown by running the application, or undef run_rv - the return value of the run method (generally irrelevant) exit_code - the numeric exit code that would've been issued (0 is 'okay')
The output is captured using IO::TieCombine, which can ensure that the ordering is preserved in the combined output, but can't capture the output of external programs. You can reverse these tradeoffs by using App::Cmd::Tester::CaptureExternal instead.
AUTHOR
Ricardo Signes <rjbs@semiotic.systems>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install App::Cmd, copy and paste the appropriate command in to your terminal.
cpanm App::Cmd
perl -MCPAN -e shell install App::Cmd
For more information on module installation, please visit the detailed CPAN module installation guide.