Test-Script-1.29000755001750001750 014047241414 13574 5ustar00ollisgollisg000000000000README100644001750001750 2340514047241414 14561 0ustar00ollisgollisg000000000000Test-Script-1.29NAME Test::Script - Basic cross-platform tests for scripts VERSION version 1.29 SYNOPSIS use Test2::V0; use Test::Script; script_compiles('script/myscript.pl'); script_runs(['script/myscript.pl', '--my-argument']); program_runs(['ls', '/dev']); done_testing; DESCRIPTION The intent of this module is to provide a series of basic tests for 80% of the testing you will need to do for scripts in the script (or bin as is also commonly used) paths of your Perl distribution. It also provides similar functions for testing programs that are not Perl scripts. Further, it aims to provide this functionality with perfect platform-compatibility, and in a way that is as unobtrusive as possible. That is, if the program works on a platform, then Test::Script should always work on that platform as well. Anything less than 100% is considered unacceptable. In doing so, it is hoped that Test::Script can become a module that you can safely make a dependency of all your modules, without risking that your module won't on some platform because of the dependency. Where a clash exists between wanting more functionality and maintaining platform safety, this module will err on the side of platform safety. FUNCTIONS script_compiles [version 1.05] script_compiles( $script, $test_name ); The "script_compiles" test calls the script with "perl -c script.pl", and checks that it returns without error. The path it should be passed is a relative Unix-format script name. This will be localised when running perl -c and if the test fails the local name used will be shown in the diagnostic output. Note also that the test will be run with the same perl interpreter that is running the test script (and not with the default system perl). This will also be shown in the diagnostic output on failure. script_runs [version 1.05] script_runs( $script, $test_name ); script_runs( \@script_and_arguments, $test_name ); script_runs( $script, \%options, $test_name ); script_runs( \@script_and_arguments, \%options, $test_name ); The "script_runs" test executes the script with "perl script.pl" and checks that it returns success. The path it should be passed is a relative unix-format script name. This will be localised when running perl -c and if the test fails the local name used will be shown in the diagnostic output. The test will be run with the same perl interpreter that is running the test script (and not with the default system perl). This will also be shown in the diagnostic output on failure. [version 1.09] You may pass in options as a hash as the second argument (as of version 1.09). exit The expected exit value. The default is to use whatever indicates success on your platform (usually 0). interpreter_options [version 1.25] Array reference of Perl options to be passed to the interpreter. Things like -w or -x can be passed this way. This may be either a single string or an array reference. signal The expected signal. The default is 0. Use with care! This may not be portable, and is known not to work on Windows. stdin The input to be passed into the script via stdin. The value may be one of simple scalar Is considered to be a filename. scalar reference In which case the input will be drawn from the data contained in the referenced scalar. The behavior for any other types is undefined (the current implementation uses Capture::Tiny). Any already opened stdin will be closed. stdout Where to send the standard output to. If you use this option, then the the behavior of the script_stdout_ functions below are undefined. The value may be one of simple scalar Is considered to be a filename. scalar reference In which case the standard output will be places into the referenced scalar The behavior for any other types is undefined (the current implementation uses Capture::Tiny). stderr Same as stdout above, except for stderr. script_fails [ version 1.28 ] script_fails $script, { exit => $expected_exit }, $test_name ); script_fails $script, \%options, $test_name; "script_runs" may be invoked as "script_fails". The exit option is mandatory when used this way. Since Perl 5.12, die usually returns 255, but does not promise to do so. Fatal errors like divide by 0 also return 255 often so it is not the best error code for a trapped exception. script_runs needs an exit code it considers success, use warn; exit; instead of die. script_stdout_is [version 1.09] script_stdout_is $expected_stdout, $test_name; Tests if the output to stdout from the previous "script_runs" matches the expected value exactly. script_stdout_isnt [version 1.09] script_stdout_is $expected_stdout, $test_name; Tests if the output to stdout from the previous "script_runs" does NOT match the expected value exactly. script_stdout_like [version 1.09] script_stdout_like $regex, $test_name; Tests if the output to stdout from the previous "script_runs" matches the regular expression. script_stdout_unlike [version 1.09] script_stdout_unlike $regex, $test_name; Tests if the output to stdout from the previous "script_runs" does NOT match the regular expression. script_stderr_is [version 1.09] script_stderr_is $expected_stderr, $test_name; Tests if the output to stderr from the previous "script_runs" matches the expected value exactly. script_stderr_isnt [version 1.09] script_stderr_is $expected_stderr, $test_name; Tests if the output to stderr from the previous "script_runs" does NOT match the expected value exactly. script_stderr_like [version 1.09] script_stderr_like $regex, $test_name; Tests if the output to stderr from the previous "script_runs" matches the regular expression. script_stderr_unlike [version 1.09] script_stderr_unlike $regex, $test_name; Tests if the output to stderr from the previous "script_runs" does NOT match the regular expression. program_runs [version 1.26] program_runs( $program, $test_name ); program_runs( \@program_and_arguments, $test_name ); program_runs( $program, \%options, $test_name ); program_runs( \@program_and_arguments, \%options, $test_name ); The "program_runs" test executes the given program and checks that it returns success. This function works like "script_runs" except: * The path $program or @program_and_arguments is passed as-is to system() . This means program_runs can test any program, not just Perl scripts. * The %options do not support the interpreter_options key. See File::Spec or Path::Class for routines useful in building pathnames in a cross-platform way. program_fails [ version 1.28 ] program_fails $program, { exit => $expected_exit }, $test_name; program_fails $program, \%options, $test_name; "program_runs" may be invoked as "program_fails". "program_fails" needs to know the expected exit value, so exit becomes a required option. program_stdout_is [version 1.26] program_stdout_is $expected_stdout, $test_name; Tests if the output to stdout from the previous "program_runs" matches the expected value exactly. program_stdout_isnt [version 1.26] program_stdout_is $expected_stdout, $test_name; Tests if the output to stdout from the previous "program_runs" does NOT match the expected value exactly. program_stdout_like [version 1.26] program_stdout_like $regex, $test_name; Tests if the output to stdout from the previous "program_runs" matches the regular expression. program_stdout_unlike [version 1.26] program_stdout_unlike $regex, $test_name; Tests if the output to stdout from the previous "program_runs" does NOT match the regular expression. program_stderr_is [version 1.26] program_stderr_is $expected_stderr, $test_name; Tests if the output to stderr from the previous "program_runs" matches the expected value exactly. program_stderr_isnt [version 1.26] program_stderr_is $expected_stderr, $test_name; Tests if the output to stderr from the previous "program_runs" does NOT match the expected value exactly. program_stderr_like [version 1.26] program_stderr_like $regex, $test_name; Tests if the output to stderr from the previous "program_runs" matches the regular expression. program_stderr_unlike [version 1.26] program_stderr_unlike $regex, $test_name; Tests if the output to stderr from the previous "program_runs" does NOT match the regular expression. CAVEATS This module is fully supported back to Perl 5.8.1. The STDIN handle will be closed when using script_runs with the stdin option. An older version used IPC::Run3, which attempted to save STDIN, but apparently this cannot be done consistently or portably. We now use Capture::Tiny instead and explicitly do not support saving STDIN handles. SEE ALSO Test::Script::Run, Test2::Suite AUTHOR Original author: Adam Kennedy Current maintainer: Graham Ollis Contributors: Brendan Byrd Chris White John Karr (BRAINBUZ) COPYRIGHT AND LICENSE This software is copyright (c) 2006-2021 by Adam Kennedy. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100644001750001750 1306014047241414 15170 0ustar00ollisgollisg000000000000Test-Script-1.29Revision history for Perl extension Test-Script 1.29 2021-05-13 09:17:30 -0600 - Production release identical to 1.28_01 release. 1.28_01 2021-05-10 10:12:22 -0600 - Added script_fails and program_fails functions (brainbuz++ gh#34, gh#38) 1.27 2021-02-17 13:15:57 -0700 - Documentation improvements (RRWO++ gh#31, gh#30) 1.26 2019-10-25 21:22:03 -0700 - Add program_runs and related functions for testing programs that do not run under Perl (gh#26, gh#27) 1.25 2018-09-27 15:33:19 -0400 - Production release identical to 1.24_01 release. 1.24_01 2018-09-24 12:38:07 -0400 - Add interpreter_options to script_runs options 1.23 2017-07-18 03:12:24 -0400 - Production release identical to 1.22_01 release. 1.22_01 2017-07-14 07:21:00 -0400 - Fix testing failures on Windows introduced in 1.21_01 1.21_01 2017-07-13 13:37:09 -0400 - Migrate to using Test2::V0 internally 1.20 2017-07-13 11:17:42 -0400 - Production release identical to 1.19_08 release. 1.19_08 2017-07-12 08:22:41 -0400 - Diagnostic release 1.19_07 2017-07-12 07:53:55 -0400 - Diagnostic release 1.19_06 2017-07-11 05:34:30 -0400 - Diagnostic release 1.19_05 2017-07-09 11:35:59 -0400 - Diagnostic release 1.19_04 2017-07-07 16:26:41 -0400 - Add support for stdin option that was lost in the Capture::Tiny migration - Officially drop support for Perl 5.6 (support for 5.6 was already implicitly dropped when we migrated to Capture::Tiny). - A near term future version will also drop support for the old pre-Test2 Test::Builder. 1.19_03 2017-07-07 10:14:25 -0400 - Use Test2::V0 instead of Test2::Bundle::Extended for Test2 tests 1.19_02 2017-06-21 17:06:47 -0400 - Identical to 1.19_01 1.19_01 2017-05-01 06:12:01 -0400 - Use Capture::Tiny instead of IPC::Run3 (Paul Cochrane/PTC++ gh#4, gh#15) - Minor documentation fixes (Paul Cochrane/PTC++) 1.18 2017-04-12 07:01:14 -0400 - Production release identical to 1.17_02 release. 1.17_02 2017-04-10 08:39:46 -0400 - Use three argument open 1.17_01 2017-04-10 06:51:38 -0400 - Handle scripts with -T taint mode (gh#13) 1.16 2017-03-04 12:16:10 -0500 - Stricter useage of plans. 1.15 2017-02-14 07:08:51 +1100 - Fix bug where list reference arguments to script_compiles and script_runs are modified (gh#9) 1.14 2016-10-13 11:04:48 -0400 - Fix a regex in a test that fails on recent versions of Test2 on Windows (possibly others) (gh#8) - One of the tests was unreasonably slow, so it does not get run for users, but will be used for development only - Remove warning condition that happens with at least some older versions of Perl when using quotemeta without parentheses (gh#7 Thanks Brendan Byrd) 1.12 2016-05-02 11:18:01 -0400 - Production release identical to 1.11_03 release. 1.11_03 2016-04-28 06:45:52 -0400 - Check for IO errors on temporary .pm file 1.11_02 2016-04-27 13:15:35 -0400 - One possible fix for gh#5 (see https://github.com/plicease/Test-Script/issues/5) 1.11_01 2016-04-27 12:28:33 -0400 - Including some optional Test2 based tests that should only be run with a merged Test2 / Test::Builder (currently a dev release as Test::Simple on CPAN) 1.10 2015-05-12 05:15:41 -0400 - Work around for buggy IPC::Run3 0.048 on MSWin32 On Windows we probe for and mitigate a bug in IPC::Run3 (see https://github.com/plicease/Test-Script/issues/1 for details) with the intention of removing the workaround if/when IPC::Run3 is fixed. 1.09 2015-05-07 16:44:26 -0400 - If IPC::Run3::run3 throws an exception it will now fail the test (with a helpful diagnostic) rather than crashing the test script. - A script that is killed with a singnal is now considered a failure as well. - Use alternate expected exit and signal values with options as the second argument to script_runs. - Ability to pass input via stdin to the script with script_runs. - Ability to capture stdout and stderr from script with script_runs. - Functions to test stdout and stderr: script_stdout_is script_stdout_isnt script_stdout_like script_stdout_unlike script_stderr_is script_stderr_isnt script_stderr_like script_stderr_unlike 1.08 2015-05-06 05:09:13 -0400 - Now works with or without blib (rt81222, rt102743) - Compatability with older versions of Test::Builder::Tester (rt81335) - Requires Perl 5.6.0 - Migrate to Dist::Zilla 1.07 Tue 24 Nov 2009 - Second attempt at fixing the "Using" bug 1.06 Wed 16 Sep 2009 - Update test to allow different die() return values - Move Test::More to runtime dependency 1.05 Mon 14 Sep 2009 - Changed script_compiles_ok to script_compiles - Added script_runs 1.04_03 Thu 18 Dec 2008 - Another attempt to support 5.6 properly 1.04_02 Wed 17 Dec 2008 - Test tweak to support 5.6 properly 1.04_01 Tue 16 Dec 2008 - Updated to Module::Install 0.77 - Adding dependency on Probe::Perl - Full fidelity failure testing 1.03 Fri 29 Feb 2008 - Updated to Module::Install 0.68 - Incremental release to get updated author tests 1.02 Sun 15 Oct 2006 - Adding diagnostics to failing cases - Add -Mblib to the call to perl 1.01 Sun 1 Oct 2006 - Making the Makefile.PL NOT executable 1.00 Sun 3 Sep 2006 - Converted the test scripts to full blown Test::Builder::Tester tests - Made the tests more comprehensive - The 0.01 version was returning false positive test results - Force warnings on in test scripts 0.01 Tue 18 Jul 2006 - Created the initial implementation LICENSE100644001750001750 4367414047241414 14720 0ustar00ollisgollisg000000000000Test-Script-1.29This software is copyright (c) 2006-2021 by Adam Kennedy. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2006-2021 by Adam Kennedy. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2006-2021 by Adam Kennedy. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644001750001750 432414047241414 14711 0ustar00ollisgollisg000000000000Test-Script-1.29This is the Perl distribution Test-Script. Installing Test-Script is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Test::Script If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Test::Script ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation Test-Script documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc Test::Script For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html dist.ini100644001750001750 213314047241414 15320 0ustar00ollisgollisg000000000000Test-Script-1.29name = Test-Script author = Graham Ollis author = Adam Kennedy license = Perl_5 copyright_holder = Adam Kennedy copyright_year = 2006-2021 version = 1.29 [@Author::Plicease] :version = 2.61 release_tests = 1 test2_v0 = 1 github_user = uperl workflow = linux workflow = macos workflow = windows workflow = cygwin workflow = msys2-mingw [RemovePrereqs] remove = strict remove = warnings remove = base remove = vars remove = Carp remove = Exporter remove = File::Spec::Unix remove = File::Spec::Functions remove = File::Temp remove = File::Path remove = Data::Dumper [Prereqs] File::Spec = 0.80 Probe::Perl = 0.01 Capture::Tiny = 0 ;[Prereqs / TestPrereqs] ;-phase = test [MetaProvides::Package] [Author::Plicease::Upload] cpan = 1 [Author::Plicease::Thanks] current = Graham Ollis original = Adam Kennedy contributor = Brendan Byrd contributor = Chris White contributor = John Karr (BRAINBUZ) [PruneFiles] filename = xt/release/changes.t filename = xt/author/strict.t META.yml100644001750001750 226414047241414 15132 0ustar00ollisgollisg000000000000Test-Script-1.29--- abstract: 'Basic cross-platform tests for scripts' author: - 'Graham Ollis ' - 'Adam Kennedy' build_requires: Test2::V0: '0.000060' perl: '5.008001' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.008001' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Script provides: Test::Script: file: lib/Test/Script.pm version: '1.29' requires: Capture::Tiny: '0' File::Spec: '0.80' IO::Handle: '0' Probe::Perl: '0.01' Test2::API: '1.302015' Text::ParseWords: '0' perl: '5.008001' resources: bugtracker: https://github.com/uperl/Test-Script/issues homepage: https://metacpan.org/pod/Test::Script repository: git://github.com/uperl/Test-Script.git version: '1.29' x_contributors: - 'Adam Kennedy' - 'Graham Ollis ' - 'Brendan Byrd' - 'Chris White ' - 'John Karr (BRAINBUZ)' x_generated_by_perl: v5.33.9 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' x_use_unsafe_inc: 0 MANIFEST100644001750001750 152114047241414 15005 0ustar00ollisgollisg000000000000Test-Script-1.29# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.017. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README author.yml dist.ini lib/Test/Script.pm t/00_diag.t t/01_use.t t/bin/bad.pl t/bin/four.pl t/bin/good.pl t/bin/liveordie.pl t/bin/print.pl t/bin/signal.pl t/bin/stdin.pl t/bin/stdin.txt t/bin/taint.pl t/bin/warnon.pl t/bug_gh9.t t/test_script__exports.t t/test_script__fails.t t/test_script__import.t t/test_script__program_runs.t t/test_script__program_stderr.t t/test_script__program_stdout.t t/test_script__script_compiles.t t/test_script__script_runs.t t/test_script__script_stderr.t t/test_script__script_stdout.t xt/author/eol.t xt/author/no_tabs.t xt/author/pod.t xt/author/pod_coverage.t xt/author/pod_spelling_common.t xt/author/pod_spelling_system.t xt/author/version.t xt/release/fixme.t META.json100644001750001750 447514047241414 15310 0ustar00ollisgollisg000000000000Test-Script-1.29{ "abstract" : "Basic cross-platform tests for scripts", "author" : [ "Graham Ollis ", "Adam Kennedy" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-Script", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.008001" } }, "develop" : { "requires" : { "FindBin" : "0", "Test::EOL" : "0", "Test::Fixme" : "0.07", "Test::More" : "0.98", "Test::NoTabs" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0", "YAML" : "0" } }, "runtime" : { "requires" : { "Capture::Tiny" : "0", "File::Spec" : "0.80", "IO::Handle" : "0", "Probe::Perl" : "0.01", "Test2::API" : "1.302015", "Text::ParseWords" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "Test2::V0" : "0.000060", "perl" : "5.008001" } } }, "provides" : { "Test::Script" : { "file" : "lib/Test/Script.pm", "version" : "1.29" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/uperl/Test-Script/issues" }, "homepage" : "https://metacpan.org/pod/Test::Script", "repository" : { "type" : "git", "url" : "git://github.com/uperl/Test-Script.git", "web" : "https://github.com/uperl/Test-Script" } }, "version" : "1.29", "x_contributors" : [ "Adam Kennedy", "Graham Ollis ", "Brendan Byrd", "Chris White ", "John Karr (BRAINBUZ)" ], "x_generated_by_perl" : "v5.33.9", "x_serialization_backend" : "Cpanel::JSON::XS version 4.26", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later", "x_use_unsafe_inc" : 0 } author.yml100644001750001750 100514047241414 15676 0ustar00ollisgollisg000000000000Test-Script-1.29--- pod_spelling_system: skip: 0 # list of words that are spelled correctly # (regardless of what spell check thinks) stopwords: # australian spelling. - localised - BRAINBUZ - Karr pod_coverage: skip: 0 # format is "Class#method" or "Class", regex allowed # for either Class or method. private: # private - Test::Script#path - Test::Script#perl # old interface - Test::Script#script_compiles_ok unused_vars: skip: 0 global: ignore_vars: [] module: {} t000755001750001750 014047241414 13760 5ustar00ollisgollisg000000000000Test-Script-1.2901_use.t100644001750001750 74114047241414 15363 0ustar00ollisgollisg000000000000Test-Script-1.29/tuse Test2::V0 -no_srand => 1; sub require_ok ($); require_ok('Test::Script'); done_testing; sub require_ok ($) { # special case of when I really do want require_ok. # I just want a test that checks that the modules # will compile okay. I won't be trying to use them. my($mod) = @_; my $ctx = context(); eval qq{ require $mod }; my $error = $@; my $ok = !$error; $ctx->ok($ok, "require $mod"); $ctx->diag("error: $error") if $error ne ''; $ctx->release; } 00_diag.t100644001750001750 252514047241414 15514 0ustar00ollisgollisg000000000000Test-Script-1.29/tuse Test2::V0 -no_srand => 1; use Config; eval { require 'Test/More.pm' }; # This .t file is generated. # make changes instead to dist.ini my %modules; my $post_diag; $modules{$_} = $_ for qw( Capture::Tiny ExtUtils::MakeMaker File::Spec IO::Handle Probe::Perl Test2::API Test2::V0 Text::ParseWords ); my @modules = sort keys %modules; sub spacer () { diag ''; diag ''; diag ''; } pass 'okay'; my $max = 1; $max = $_ > $max ? $_ : $max for map { length $_ } @modules; our $format = "%-${max}s %s"; spacer; my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV; if(@keys > 0) { diag "$_=$ENV{$_}" for @keys; if($ENV{PERL5LIB}) { spacer; diag "PERL5LIB path"; diag $_ for split $Config{path_sep}, $ENV{PERL5LIB}; } elsif($ENV{PERLLIB}) { spacer; diag "PERLLIB path"; diag $_ for split $Config{path_sep}, $ENV{PERLLIB}; } spacer; } diag sprintf $format, 'perl', "$] $^O $Config{archname}"; foreach my $module (sort @modules) { my $pm = "$module.pm"; $pm =~ s{::}{/}g; if(eval { require $pm; 1 }) { my $ver = eval { $module->VERSION }; $ver = 'undef' unless defined $ver; diag sprintf $format, $module, $ver; } else { diag sprintf $format, $module, '-'; } } if($post_diag) { spacer; $post_diag->(); } spacer; done_testing; bug_gh9.t100644001750001750 54114047241414 15611 0ustar00ollisgollisg000000000000Test-Script-1.29/tuse Test2::V0 -no_srand => 1; use Test::Script; subtest 'non-distructive' => sub { my @foo = qw( foo bar baz ); my $bar = Test::Script::_script \@foo; is( $bar, [qw( foo bar baz )], 'comes out the right' ), my $command = shift @$bar; is( \@foo, [qw( foo bar baz )], '@foo is unchanged', ); }; done_testing; Makefile.PL100644001750001750 324614047241414 15634 0ustar00ollisgollisg000000000000Test-Script-1.29BEGIN { use strict; use warnings; unless(eval q{ use 5.008001; 1}) { print "Perl 5.008001 or better required\n"; exit; } } # This file was automatically generated by Dist::Zilla::Plugin::Author::Plicease::MakeMaker v2.63. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Basic cross-platform tests for scripts", "AUTHOR" => "Graham Ollis , Adam Kennedy", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Test-Script", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008001", "NAME" => "Test::Script", "PM" => { "lib/Test/Script.pm" => "\$(INST_LIB)/Test/Script.pm" }, "PREREQ_PM" => { "Capture::Tiny" => 0, "File::Spec" => "0.80", "IO::Handle" => 0, "Probe::Perl" => "0.01", "Test2::API" => "1.302015", "Text::ParseWords" => 0 }, "TEST_REQUIRES" => { "Test2::V0" => "0.000060" }, "VERSION" => "1.29", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Capture::Tiny" => 0, "File::Spec" => "0.80", "IO::Handle" => 0, "Probe::Perl" => "0.01", "Test2::API" => "1.302015", "Test2::V0" => "0.000060", "Text::ParseWords" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs);bin000755001750001750 014047241414 14530 5ustar00ollisgollisg000000000000Test-Script-1.29/tbad.pl100644001750001750 3714047241414 15713 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl BEGIN { die "Bad"; } four.pl100644001750001750 10014047241414 16147 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl use strict; print STDERR "Standard Error\n"; exit(4); good.pl100644001750001750 3014047241414 16106 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl use strict; 1; taint.pl100644001750001750 2414047241414 16300 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl -wT exit 0; stdin.pl100644001750001750 10214047241414 16317 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl use strict; while() { s/oo/bb/g; print; } 1; print.pl100644001750001750 23414047241414 16340 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl use strict; print STDOUT "Standard Out\n"; print STDOUT "second line\n"; print STDERR "Standard Error\n"; print STDERR "another line\n"; exit(0); stdin.txt100644001750001750 714047241414 16467 0ustar00ollisgollisg000000000000Test-Script-1.29/t/binfoobaz signal.pl100644001750001750 6014047241414 16436 0ustar00ollisgollisg000000000000Test-Script-1.29/t/binuse strict; use warnings; BEGIN { kill 9, $$ }; warnon.pl100644001750001750 4314047241414 16466 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bindie "warnings are off" unless $^W; author000755001750001750 014047241414 15452 5ustar00ollisgollisg000000000000Test-Script-1.29/xteol.t100644001750001750 51014047241414 16532 0ustar00ollisgollisg000000000000Test-Script-1.29/xt/authoruse strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::EOL' unless eval q{ use Test::EOL; 1 }; }; use Test::EOL; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_perl_files_ok(grep { -e $_ } qw( bin lib t Makefile.PL )); pod.t100644001750001750 47214047241414 16544 0ustar00ollisgollisg000000000000Test-Script-1.29/xt/authoruse strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Pod' unless eval q{ use Test::Pod; 1 }; }; use Test::Pod; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_pod_files_ok( grep { -e $_ } qw( bin lib )); liveordie.pl100644001750001750 35614047241414 17173 0ustar00ollisgollisg000000000000Test-Script-1.29/t/bin#!perl use strict; my ( $dothis, $code ) = @ARGV; if ( $dothis eq 'die' ) { die 'Instructed to DIE!'; } elsif ( $dothis eq 'fail' ) { print STDERR "Exit: $code\n"; exit( $code ); } else { print STDOUT "I lived\n"; exit(0); } Test000755001750001750 014047241414 15202 5ustar00ollisgollisg000000000000Test-Script-1.29/libScript.pm100644001750001750 5106714047241414 17175 0ustar00ollisgollisg000000000000Test-Script-1.29/lib/Testpackage Test::Script; # ABSTRACT: Basic cross-platform tests for scripts our $VERSION = '1.29'; # VERSION use 5.008001; use strict; use warnings; use Carp qw( croak ); use Exporter; use File::Spec; use File::Spec::Unix; use Probe::Perl; use Capture::Tiny qw( capture ); use Test2::API qw( context ); use File::Temp qw( tempdir ); use IO::Handle; our @ISA = 'Exporter'; our @EXPORT = qw{ script_compiles script_compiles_ok script_fails script_runs script_stdout_is script_stdout_isnt script_stdout_like script_stdout_unlike script_stderr_is script_stderr_isnt script_stderr_like script_stderr_unlike program_fails program_runs program_stdout_is program_stdout_isnt program_stdout_like program_stdout_unlike program_stderr_is program_stderr_isnt program_stderr_like program_stderr_unlike }; sub import { my $self = shift; my $pack = caller; if(defined $_[0] && $_[0] =~ /^(?:no_plan|skip_all|tests)$/) { # icky back compat. # do not use. my $ctx = context(); if($_[0] eq 'tests') { $ctx->plan($_[1]); } elsif($_[0] eq 'skip_all') { $ctx->plan(0, 'SKIP', $_[1]); } else { $ctx->hub->plan('NO PLAN'); } $ctx->release; } foreach ( @EXPORT ) { $self->export_to_level(1, $self, $_); } } my $perl = undef; sub perl () { $perl or $perl = Probe::Perl->find_perl_interpreter; } sub path ($) { my $path = shift; unless ( defined $path ) { croak("Did not provide a script name"); } if ( File::Spec::Unix->file_name_is_absolute($path) ) { croak("Script name must be relative"); } File::Spec->catfile( File::Spec->curdir, split /\//, $path ); } ##################################################################### # Test Functions for Scripts sub script_compiles { my $args = _script(shift); my $unix = shift @$args; my $path = path( $unix ); my $pargs = _perl_args($path); my $dir = _preload_module(); my $cmd = [ perl, @$pargs, "-I$dir", '-M__TEST_SCRIPT__', '-c', $path, @$args ]; my ($stdout, $stderr) = capture { system(@$cmd) }; my $error = $@; my $exit = $? ? ($? >> 8) : 0; my $signal = $? ? ($? & 127) : 0; my $ok = !! ( $error eq '' and $exit == 0 and $signal == 0 and $stderr =~ /syntax OK\s+\z/si ); my $ctx = context(); $ctx->ok( $ok, $_[0] || "Script $unix compiles" ); $ctx->diag( "$exit - $stderr" ) unless $ok; $ctx->diag( "exception: $error" ) if $error; $ctx->diag( "signal: $signal" ) if $signal; $ctx->release; return $ok; } # this is noticeably slower for long @INC lists (sometimes present in cpantesters # boxes) than the previous implementation, which added a -I for every element in # @INC. (also slower for more reasonable @INCs, but not noticeably). But it is # safer as very long argument lists can break calls to system sub _preload_module { my @opts = ( '.test-script-XXXXXXXX', CLEANUP => 1); if(-w File::Spec->curdir) { push @opts, DIR => File::Spec->curdir } else { push @opts, DIR => File::Spec->tmpdir } my $dir = tempdir(@opts); $dir = File::Spec->rel2abs($dir); # this is hopefully a pm file that nobody would use my $filename = File::Spec->catfile($dir, '__TEST_SCRIPT__.pm'); my $fh; open($fh, '>', $filename) || die "unable to open $filename: $!"; print($fh 'unshift @INC, ', join ',', # quotemeta is overkill, but it will make sure that characters # like " are quoted map { '"' . quotemeta($_) . '"' } grep { ! ref } @INC) || die "unable to write $filename: $!"; close($fh) || die "unable to close $filename: $!";; $dir; } my $stdout; my $stderr; sub script_runs { my $args = _script(shift); my $opt = _options(\$stdout, \$stderr, 1, \@_); my $unix = shift @$args; my $path = path( $unix ); my $pargs = [ @{ _perl_args($path) }, @{ $opt->{interpreter_options} } ]; my $dir = _preload_module(); my $cmd = [ perl, @$pargs, "-I$dir", '-M__TEST_SCRIPT__', $path, @$args ]; $stdout = ''; $stderr = ''; unshift @_, "Script $unix runs" unless $_[0]; unshift @_, $cmd, $opt; goto &_run; } sub script_fails { my $args = _script(shift); my ( $opt, $testname ) = @_; $testname = "Script $args->[0] fails" unless defined $testname; die "exit is a mandatory option for script_fails" unless eval{ defined $opt->{exit} }; my $ctx = context(); return release $ctx, script_runs( $args, $opt, $testname ); } # Run a script or program and provide test events corresponding to the results. # Call as _run(\@cmd, \%opt, "Test description") sub _run { my ($cmd, $opt, $description) = @_; if($opt->{stdin}) { my $filename; if(ref($opt->{stdin}) eq 'SCALAR') { $filename = File::Spec->catfile( tempdir(CLEANUP => 1), 'stdin.txt', ); my $tmp; open($tmp, '>', $filename) || die "unable to write to $filename"; print $tmp ${ $opt->{stdin} }; close $tmp; } elsif(ref($opt->{stdin}) eq '') { $filename = $opt->{stdin}; } else { croak("stdin MUST be either a scalar reference or a string filename"); } my $fh; open($fh, '<', $filename) || die "unable to open $filename $!"; STDIN->fdopen( $fh, 'r' ) or die "unable to reopen stdin to $filename $!"; } (${$opt->{stdout}}, ${$opt->{stderr}}) = capture { system(@$cmd) }; my $error = $@; my $exit = $? ? ($? >> 8) : 0; my $signal = $? ? ($? & 127) : 0; my $ok = !! ( $error eq '' and $exit == $opt->{exit} and $signal == $opt->{signal} ); my $ctx = context(); $ctx->ok( $ok, $description ); $ctx->diag( "$exit - " . ${$opt->{stderr}} ) unless $ok; $ctx->diag( "exception: $error" ) if $error; $ctx->diag( "signal: $signal" ) unless $signal == $opt->{signal}; $ctx->release; return $ok; } sub _like { my($text, $pattern, $regex, $not, $name) = @_; my $ok = $regex ? $text =~ $pattern : $text eq $pattern; $ok = !$ok if $not; my $ctx = context; $ctx->ok( $ok, $name ); unless($ok) { $ctx->diag( "The output" ); $ctx->diag( " $_") for split /\n/, $text; $ctx->diag( $not ? "does match" : "does not match" ); if($regex) { $ctx->diag( " $pattern" ); } else { $ctx->diag( " $_" ) for split /\n/, $pattern; } } $ctx->release; $ok; } sub script_stdout_is { my($pattern, $name) = @_; @_ = ($stdout, $pattern, 0, 0, $name || 'stdout matches' ); goto &_like; } sub script_stdout_isnt { my($pattern, $name) = @_; @_ = ($stdout, $pattern, 0, 1, $name || 'stdout does not match' ); goto &_like; } sub script_stdout_like { my($pattern, $name) = @_; @_ = ($stdout, $pattern, 1, 0, $name || 'stdout matches' ); goto &_like; } sub script_stdout_unlike { my($pattern, $name) = @_; @_ = ($stdout, $pattern, 1, 1, $name || 'stdout does not match' ); goto &_like; } sub script_stderr_is { my($pattern, $name) = @_; @_ = ($stderr, $pattern, 0, 0, $name || 'stderr matches' ); goto &_like; } sub script_stderr_isnt { my($pattern, $name) = @_; @_ = ($stderr, $pattern, 0, 1, $name || 'stderr does not match' ); goto &_like; } sub script_stderr_like { my($pattern, $name) = @_; @_ = ($stderr, $pattern, 1, 0, $name || 'stderr matches' ); goto &_like; } sub script_stderr_unlike { my($pattern, $name) = @_; @_ = ($stderr, $pattern, 1, 1, $name || 'stderr does not match' ); goto &_like; } ##################################################################### # Test Functions for Programs my $program_stdout; my $program_stderr; sub program_runs { my $cmd = _script(shift); my $opt = _options(\$program_stdout, \$program_stderr, 0, \@_); $program_stdout = ''; $program_stderr = ''; unshift @_, "Program $$cmd[0] runs" unless $_[0]; unshift @_, $cmd, $opt; goto &_run; } sub program_fails { my $cmd = _script(shift); my ( $opt, $testname ) = @_; $testname = 'program_fails' unless defined $testname; die "exit is a mandatory option for program_fails" unless eval{ defined $opt->{exit} }; my $ctx = context(); return release $ctx, program_runs( $cmd, $opt, $testname ); } sub program_stdout_is { my($pattern, $name) = @_; @_ = ($program_stdout, $pattern, 0, 0, $name || 'stdout matches' ); goto &_like; } sub program_stdout_isnt { my($pattern, $name) = @_; @_ = ($program_stdout, $pattern, 0, 1, $name || 'stdout does not match' ); goto &_like; } sub program_stdout_like { my($pattern, $name) = @_; @_ = ($program_stdout, $pattern, 1, 0, $name || 'stdout matches' ); goto &_like; } sub program_stdout_unlike { my($pattern, $name) = @_; @_ = ($program_stdout, $pattern, 1, 1, $name || 'stdout does not match' ); goto &_like; } sub program_stderr_is { my($pattern, $name) = @_; @_ = ($program_stderr, $pattern, 0, 0, $name || 'stderr matches' ); goto &_like; } sub program_stderr_isnt { my($pattern, $name) = @_; @_ = ($program_stderr, $pattern, 0, 1, $name || 'stderr does not match' ); goto &_like; } sub program_stderr_like { my($pattern, $name) = @_; @_ = ($program_stderr, $pattern, 1, 0, $name || 'stderr matches' ); goto &_like; } sub program_stderr_unlike { my($pattern, $name) = @_; @_ = ($program_stderr, $pattern, 1, 1, $name || 'stderr does not match' ); goto &_like; } ###################################################################### # Support Functions # Script params must be either a simple non-null string with the script # name, or an array reference with one or more non-null strings. sub _script { my $in = shift; if ( defined _STRING($in) ) { return [ $in ]; } if ( _ARRAY($in) ) { unless ( scalar grep { not defined _STRING($_) } @$in ) { return [ @$in ]; } } croak("Invalid command parameter"); } # Determine any extra arguments that need to be passed into Perl. # ATM this is just -T. sub _perl_args { my($script) = @_; my $fh; my $first_line = ''; if(open($fh, '<', $script)) { $first_line = <$fh>; close $fh; } (grep /^-.*T/, split /\s+/, $first_line) ? ['-T'] : []; } # Inline some basic Params::Util functions sub _options { my $ref_stdout = shift; my $ref_stderr = shift; my $permit_interpreter_options = shift; my %options = ref($_[0]->[0]) eq 'HASH' ? %{ shift @{ $_[0] } }: (); $options{exit} = 0 unless defined $options{exit}; $options{signal} = 0 unless defined $options{signal}; my $stdin = ''; #$options{stdin} = \$stdin unless defined $options{stdin}; $options{stdout} = $ref_stdout unless defined $options{stdout}; $options{stderr} = $ref_stderr unless defined $options{stderr}; if(defined $options{interpreter_options}) { die "interpreter_options not supported" unless $permit_interpreter_options; unless(ref $options{interpreter_options} eq 'ARRAY') { require Text::ParseWords; $options{interpreter_options} = [ Text::ParseWords::shellwords($options{interpreter_options}) ]; } } else { $options{interpreter_options} = []; } \%options; } sub _ARRAY ($) { (ref $_[0] eq 'ARRAY' and @{$_[0]}) ? $_[0] : undef; } sub _STRING ($) { (defined $_[0] and ! ref $_[0] and length($_[0])) ? $_[0] : undef; } BEGIN { # Alias to old name *script_compiles_ok = *script_compiles; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Test::Script - Basic cross-platform tests for scripts =head1 VERSION version 1.29 =head1 SYNOPSIS use Test2::V0; use Test::Script; script_compiles('script/myscript.pl'); script_runs(['script/myscript.pl', '--my-argument']); program_runs(['ls', '/dev']); done_testing; =head1 DESCRIPTION The intent of this module is to provide a series of basic tests for 80% of the testing you will need to do for scripts in the F