1Test::Command::Simple(3U)ser Contributed Perl DocumentatiToenst::Command::Simple(3)
2
3
4

NAME

6       Test::Command::Simple - Test external commands (nearly) as easily as
7       loaded modules.
8

VERSION

10       Version 0.05
11

SYNOPSIS

13           use Test::Command::Simple;
14
15           run('echo', 'has this output'); # only tests that the command can be started, not checking rc
16           is(rc,0,'Returned successfully')
17           like(stdout,qr/has this output/,'Testing stdout');
18           is(length stderr, 0,'No stderr');
19

PURPOSE

21       This test module is intended to simplify testing of external commands.
22       It does so by running the command under IPC::Open3, closing the stdin
23       immediately, and reading everything from the command's stdout and
24       stderr.  It then makes the output available to be tested.
25
26       It is not (yet?) as feature-rich as Test::Cmd, but I think the
27       interface to this is much simpler.  Tests also plug directly into the
28       Test::Builder framework, which plays nice with Test::More.
29
30       As compared to Test::Command, this module is simpler, relying on the
31       user to feed rc, stdout, and stderr to the appropriate other tests,
32       presumably in Test::More, but not necessarily.  This makes it possible,
33       for example, to test line 3 of the output:
34
35           my (undef, undef, $line) = split /\r?\n/, stdout;
36           is($line, 'This is the third line', 'Test the third line');
37
38       While this is possible to do with Test::Command's stdout_like, some
39       regex's can get very awkward, and it becomes better to do this in
40       multiple steps.
41
42       Also, Test::Command saves stdout and stderr to files.  That has an
43       advantage when you're saving a lot of text.  However, this module
44       prefers to slurp everything in using IPC::Open3, IO::Select, and
45       sysread.  Most of the time, commands being tested do not produce
46       significant amounts of output, so there becomes no reason to use
47       temporary files and involve the disk at all.
48

EXPORTS

50   run
51       Runs the given command.  It will return when the command is done.
52
53       This will also reinitialise all of the states for stdout, stderr, and
54       rc.  If you need to keep the values of a previous run() after a later
55       one, you will need to store it.  This should be mostly pretty rare.
56
57       Counts as one test: whether the IPC::Open3 call to open3 succeeded.
58       That is not returned in a meaningful way to the user, though.  To check
59       if that's the case for purposes of SKIPping, rc will be set to -1.
60
61   stdout
62       Returns the last run's stdout
63
64   stderr
65       Returns the last run's stderr
66
67   rc
68       Returns the last run's full $?, suitable for passing to POSIX's
69       :sys_wait_h macros (WIFEXITED, WEXITSTATUS, etc.)
70
71   exit_status
72       Returns the exit status of the last run
73
74   run_ok
75       Shortcut for checking that the return from a command is 0.  Will still
76       set stdout and stderr for further testing.
77
78       If the first parameter is an integer 0-255, then that is the expected
79       return code instead.  Remember: $? has both a return code (0-255) and a
80       reason for exit embedded.  This function must make the assumption that
81       you want a "normal" exit only.  If any signal is given, this will treat
82       that as a failure.
83
84       Note that this becomes three tests: one that IPC::Open3 could create
85       the subprocess with the command, the next is the test that the process
86       exited normally, and the last is the test of the rc.
87

AUTHOR

89       Darin McBride, "<dmcbride at cpan.org>"
90

BUGS

92       Please report any bugs or feature requests to "bug-test-command at
93       rt.cpan.org", or through the web interface at
94       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Command-Simple>.
95       I will be notified, and then you'll automatically be notified of
96       progress on your bug as I make changes.
97

SUPPORT

99       You can find documentation for this module with the perldoc command.
100
101           perldoc Test::Command::Simple
102
103       You can also look for information at:
104
105       •   RT: CPAN's request tracker
106
107           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Command-Simple>
108
109       •   AnnoCPAN: Annotated CPAN documentation
110
111           <http://annocpan.org/dist/Test-Command-Simple>
112
113       •   CPAN Ratings
114
115           <http://cpanratings.perl.org/d/Test-Command-Simple>
116
117       •   Search CPAN
118
119           <http://search.cpan.org/dist/Test-Command-Simple/>
120

ACKNOWLEDGEMENTS

123       Copyright 2010 Darin McBride.
124
125       This program is free software; you can redistribute it and/or modify it
126       under the terms of either: the GNU General Public License as published
127       by the Free Software Foundation; or the Artistic License.
128
129       See http://dev.perl.org/licenses/ for more information.
130
131
132
133perl v5.32.1                      2021-01-27          Test::Command::Simple(3)
Impressum