Test::Perinci::CmdLine - Common test suite for Perinci::CmdLine::{Lite,Classic,Inline}
This document describes version 1.484 of Test::Perinci::CmdLine (from Perl distribution Test-Perinci-CmdLine), released on 2023-10-30.
Usage:
pericmd_run_ok(%args) -> [$status_code, $reason, $payload, \%result_meta]
Run a single test of a Perinci::CmdLine script.
This function is exported by default.
Arguments ('*' denotes required arguments):
argv => array (default: [])
Command-line arguments that will be passed to generated CLI script.
class* => str
Which Perinci::CmdLine class are we testing.
classic_gen_args => hash
Additional arguments to be passed to `Perinci::CmdLine::Gen::gen_pericmd_script()`.
Keys from this argument will be added to gen_args and will only be used when class is Perinci::CmdLine::Classic.
gen_args
class
Perinci::CmdLine::Classic
comp_answer => array[str]
Test completion answer of generated CLI script.
comp_line0 => str
Set COMP_LINE environment for generated CLI script.
Can contain ^ (caret) character which will be stripped from the final COMP_LINE and the position of the character will be used to determine COMP_POINT.
^
COMP_LINE
COMP_POINT
env => hash
Set environment variables for generated CLI script.
exit_code => int (default: 0)
Expected script's exit code.
exit_code_like => re (default: 0)
Expected script's exit code (as regex pattern).
gen_args* => hash
Arguments to be passed to `Perinci::CmdLine::Gen::gen_pericmd_script()`.
gen_status => int (default: 200)
Expected generate result status.
inline_allow => array[perl::modname]
Modules to allow to be loaded when testing generated Perinci::CmdLine::Inline script.
By default, when running the generated Perinci::CmdLine::Inline script, this perl option will be used (see lib::filter for more details):
-Mlib::filter=allow_noncore,0
This means the script will only be able to load core modules. But if the script is allowed to load additional modules, you can set this inline_allow parameter to, e.g. ["Foo::Bar","Baz"] and the above perl option will become:
inline_allow
["Foo::Bar","Baz"]
-Mlib::filter=allow_noncore,0,allow,Foo::Bar;Baz
To skip using this option, set inline_run_filter to false.
inline_run_filter
inline_gen_args => hash
Keys from this argument will be added to gen_args and will only be used when class is Perinci::CmdLine::Inline.
Perinci::CmdLine::Inline
inline_run_filter => bool (default: 1)
Whether to use -Mfilter when running generated Perinci::CmdLine::Inline script.
-Mlib::filter=allow_noncore,0,...
This is to test that the script does not require non-core modules. To skip using this option (e.g. when using pack_deps gen option set to false), set this option to false.
pack_deps
lite_gen_args => hash
Keys from this argument will be added to gen_args and will only be used when class is Perinci::CmdLine::Lite.
Perinci::CmdLine::Lite
name => str
Test name.
If not specified, a nice default will be picked (e.g. from argv).
argv
posttest => code
Additional tests.
For example you can do is() or ok() or other Test::More tests.
is()
ok()
stderr_like => re
Test error output of generated CLI script.
stderr_unlike => re
stdin => str
Supply stdin content to generated CLI script.
stdout_like => re
Test output of generated CLI script.
stdout_unlike => re
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
pericmd_run_suite_ok(%args) -> [$status_code, $reason, $payload, \%result_meta]
Common test suite for Perinci::CmdLine::{Lite,Classic,Inline}.
pericmd_run_test_groups_ok(%args) -> [$status_code, $reason, $payload, \%result_meta]
Run groups of Perinci::CmdLine tests.
cleanup_tempdir => bool
(No description)
exclude_tags => array[str]
groups* => array
include_tags => array[str]
tempdir => str
If not specified, will create temporary directory with File::Temp's tempdir().
File::Temp
tempdir()
pericmd_run_tests_ok(%args) -> [$status_code, $reason, $payload, \%result_meta]
Run a group of tests of a Perinci::CmdLine script.
tests* => array[hash]
If set to 1, then temporary files (e.g. generated scripts for testing) will not be cleaned up, so you can inspect them.
To set default for pericmd_ok()'s exclude_tags argument.
pericmd_ok()
exclude_tags
To set default for pericmd_ok()'s include_tags argument.
include_tags
Please visit the project's homepage at https://metacpan.org/release/Test-Perinci-CmdLine.
Source repository is at https://github.com/perlancar/perl-Test-Perinci-CmdLine.
Supported Perinci::CmdLine backends: Perinci::CmdLine::Inline, Perinci::CmdLine::Lite, Perinci::CmdLine::Classic.
perlancar <perlancar@cpan.org>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2017, 2016, 2015 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Perinci-CmdLine
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install Test::Perinci::CmdLine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Perinci::CmdLine
CPAN shell
perl -MCPAN -e shell install Test::Perinci::CmdLine
For more information on module installation, please visit the detailed CPAN module installation guide.