.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Test::Output 3pm" .TH Test::Output 3pm "2014-01-03" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::Output \- Utilities to test STDOUT and STDERR messages. .SH "VERSION" .IX Header "VERSION" Version 0.16 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Test::More tests => 4; \& use Test::Output; \& \& sub writer { \& print "Write out.\en"; \& print STDERR "Error out.\en"; \& } \& \& stdout_is(\e&writer,"Write out.\en",\*(AqTest STDOUT\*(Aq); \& \& stderr_isnt(\e&writer,"No error out.\en",\*(AqTest STDERR\*(Aq); \& \& combined_is( \& \e&writer, \& "Write out.\enError out.\en", \& \*(AqTest STDOUT & STDERR combined\*(Aq \& ); \& \& output_is( \& \e&writer, \& "Write out.\en", \& "Error out.\en", \& \*(AqTest STDOUT & STDERR\*(Aq \& ); \& \& # Use bare blocks. \& \& stdout_is { print "test" } "test", "Test STDOUT"; \& stderr_isnt { print "bad test" } "test", "Test STDERR"; \& output_is { print \*(AqSTDOUT\*(Aq; print STDERR \*(AqSTDERR\*(Aq } \& "STDOUT", "STDERR", "Test output"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Test::Output provides a simple interface for testing output sent to \s-1STDOUT\s0 or \s-1STDERR. A\s0 number of different utilities are included to try and be as flexible as possible to the tester. .PP Originally this module was designed not to have external requirements, however, the features provided by Sub::Exporter over what Exporter provides is just to great to pass up. .PP Likewise, Capture::Tiny provides a much more robust capture mechanism without than the original Test::Output::Tie. .SH "TESTS" .IX Header "TESTS" .SS "\s-1STDOUT\s0" .IX Subsection "STDOUT" .IP "\fBstdout_is\fR" 4 .IX Item "stdout_is" .PD 0 .IP "\fBstdout_isnt\fR" 4 .IX Item "stdout_isnt" .PD .Vb 4 \& stdout_is ( $coderef, $expected, \*(Aqdescription\*(Aq ); \& stdout_is { ... } $expected, \*(Aqdescription\*(Aq; \& stdout_isnt( $coderef, $expected, \*(Aqdescription\*(Aq ); \& stdout_isnt { ... } $expected, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIstdout_is()\fR captures output sent to \s-1STDOUT\s0 from \f(CW$coderef\fR and compares it against \f(CW$expected\fR. The test passes if equal. .Sp \&\fIstdout_isnt()\fR passes if \s-1STDOUT\s0 is not equal to \f(CW$expected\fR. .IP "\fBstdout_like\fR" 4 .IX Item "stdout_like" .PD 0 .IP "\fBstdout_unlike\fR" 4 .IX Item "stdout_unlike" .PD .Vb 4 \& stdout_like ( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& stdout_like { ... } qr/$expected/, \*(Aqdescription\*(Aq; \& stdout_unlike( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& stdout_unlike { ... } qr/$expected/, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIstdout_like()\fR captures the output sent to \s-1STDOUT\s0 from \f(CW$coderef\fR and compares it to the regex in \f(CW$expected\fR. The test passes if the regex matches. .Sp \&\fIstdout_unlike()\fR passes if \s-1STDOUT\s0 does not match the regex. .SS "\s-1STDERR\s0" .IX Subsection "STDERR" .IP "\fBstderr_is\fR" 4 .IX Item "stderr_is" .PD 0 .IP "\fBstderr_isnt\fR" 4 .IX Item "stderr_isnt" .PD .Vb 2 \& stderr_is ( $coderef, $expected, \*(Aqdescription\*(Aq ); \& stderr_is {... } $expected, \*(Aqdescription\*(Aq; \& \& stderr_isnt( $coderef, $expected, \*(Aqdescription\*(Aq ); \& stderr_isnt {... } $expected, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIstderr_is()\fR is similar to stdout_is, except that it captures \s-1STDERR.\s0 The test passes if \s-1STDERR\s0 from \f(CW$coderef\fR equals \f(CW$expected\fR. .Sp \&\fIstderr_isnt()\fR passes if \s-1STDERR\s0 is not equal to \f(CW$expected\fR. .IP "\fBstderr_like\fR" 4 .IX Item "stderr_like" .PD 0 .IP "\fBstderr_unlike\fR" 4 .IX Item "stderr_unlike" .PD .Vb 4 \& stderr_like ( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& stderr_like { ...} qr/$expected/, \*(Aqdescription\*(Aq; \& stderr_unlike( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& stderr_unlike { ...} qr/$expected/, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIstderr_like()\fR is similar to \fIstdout_like()\fR except that it compares the regex \&\f(CW$expected\fR to \s-1STDERR\s0 captured from \f(CW$codref\fR. The test passes if the regex matches. .Sp \&\fIstderr_unlike()\fR passes if \s-1STDERR\s0 does not match the regex. .SS "\s-1COMBINED OUTPUT\s0" .IX Subsection "COMBINED OUTPUT" .IP "\fBcombined_is\fR" 4 .IX Item "combined_is" .PD 0 .IP "\fBcombined_isnt\fR" 4 .IX Item "combined_isnt" .PD .Vb 4 \& combined_is ( $coderef, $expected, \*(Aqdescription\*(Aq ); \& combined_is {... } $expected, \*(Aqdescription\*(Aq; \& combined_isnt ( $coderef, $expected, \*(Aqdescription\*(Aq ); \& combined_isnt {... } $expected, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIcombined_is()\fR directs \s-1STDERR\s0 to \s-1STDOUT\s0 then captures \s-1STDOUT.\s0 This is equivalent to UNIXs 2>&1. The test passes if the combined \s-1STDOUT \s0 and \s-1STDERR\s0 from \f(CW$coderef\fR equals \f(CW$expected\fR. .Sp \&\fIcombined_isnt()\fR passes if combined \s-1STDOUT\s0 and \s-1STDERR\s0 are not equal to \f(CW$expected\fR. .IP "\fBcombined_like\fR" 4 .IX Item "combined_like" .PD 0 .IP "\fBcombined_unlike\fR" 4 .IX Item "combined_unlike" .PD .Vb 4 \& combined_like ( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& combined_like { ...} qr/$expected/, \*(Aqdescription\*(Aq; \& combined_unlike ( $coderef, qr/$expected/, \*(Aqdescription\*(Aq ); \& combined_unlike { ...} qr/$expected/, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIcombined_like()\fR is similar to \fIcombined_is()\fR except that it compares a regex ($expected) to \s-1STDOUT\s0 and \s-1STDERR\s0 captured from \f(CW$codref\fR. The test passes if the regex matches. .Sp \&\fIcombined_unlike()\fR passes if the combined \s-1STDOUT\s0 and \s-1STDERR\s0 does not match the regex. .SS "\s-1OUTPUT\s0" .IX Subsection "OUTPUT" .IP "\fBoutput_is\fR" 4 .IX Item "output_is" .PD 0 .IP "\fBoutput_isnt\fR" 4 .IX Item "output_isnt" .PD .Vb 4 \& output_is ( $coderef, $expected_stdout, $expected_stderr, \*(Aqdescription\*(Aq ); \& output_is {... } $expected_stdout, $expected_stderr, \*(Aqdescription\*(Aq; \& output_isnt( $coderef, $expected_stdout, $expected_stderr, \*(Aqdescription\*(Aq ); \& output_isnt {... } $expected_stdout, $expected_stderr, \*(Aqdescription\*(Aq; .Ve .Sp The \fIoutput_is()\fR function is a combination of the \fIstdout_is()\fR and \fIstderr_is()\fR functions. For example: .Sp .Vb 1 \& output_is(sub {print "foo"; print STDERR "bar";},\*(Aqfoo\*(Aq,\*(Aqbar\*(Aq); .Ve .Sp is functionally equivalent to .Sp .Vb 2 \& stdout_is(sub {print "foo";},\*(Aqfoo\*(Aq) \& && stderr_is(sub {print STDERR "bar";\*(Aqbar\*(Aq); .Ve .Sp except that \f(CW$coderef\fR is only executed once. .Sp Unlike, \fIstdout_is()\fR and \fIstderr_is()\fR which ignore \s-1STDERR\s0 and \s-1STDOUT\s0 respectively, \fIoutput_is()\fR requires both \s-1STDOUT\s0 and \s-1STDERR\s0 to match in order to pass. Setting either \f(CW$expected_stdout\fR or \f(CW$expected_stderr\fR to \f(CW\*(C`undef\*(C'\fR ignores \s-1STDOUT\s0 or \s-1STDERR\s0 respectively. .Sp .Vb 1 \& output_is(sub {print "foo"; print STDERR "bar";},\*(Aqfoo\*(Aq,undef); .Ve .Sp is the same as .Sp .Vb 1 \& stdout_is(sub {print "foo";},\*(Aqfoo\*(Aq) .Ve .Sp \&\fIoutput_isnt()\fR provides the opposite function of \fIoutput_is()\fR. It is a combination of \fIstdout_isnt()\fR and \fIstderr_isnt()\fR. .Sp .Vb 1 \& output_isnt(sub {print "foo"; print STDERR "bar";},\*(Aqbar\*(Aq,\*(Aqfoo\*(Aq); .Ve .Sp is functionally equivalent to .Sp .Vb 2 \& stdout_is(sub {print "foo";},\*(Aqbar\*(Aq) \& && stderr_is(sub {print STDERR "bar";\*(Aqfoo\*(Aq); .Ve .Sp As with \fIoutput_is()\fR, setting either \f(CW$expected_stdout\fR or \f(CW$expected_stderr\fR to \&\f(CW\*(C`undef\*(C'\fR ignores the output to that facility. .Sp .Vb 1 \& output_isnt(sub {print "foo"; print STDERR "bar";},undef,\*(Aqfoo\*(Aq); .Ve .Sp is the same as .Sp .Vb 1 \& stderr_is(sub {print STDERR "bar";},\*(Aqfoo\*(Aq) .Ve .IP "\fBoutput_like\fR" 4 .IX Item "output_like" .PD 0 .IP "\fBoutput_unlike\fR" 4 .IX Item "output_unlike" .PD .Vb 4 \& output_like ( $coderef, $regex_stdout, $regex_stderr, \*(Aqdescription\*(Aq ); \& output_like { ... } $regex_stdout, $regex_stderr, \*(Aqdescription\*(Aq; \& output_unlike( $coderef, $regex_stdout, $regex_stderr, \*(Aqdescription\*(Aq ); \& output_unlike { ... } $regex_stdout, $regex_stderr, \*(Aqdescription\*(Aq; .Ve .Sp \&\fIoutput_like()\fR and \fIoutput_unlike()\fR follow the same principles as \fIoutput_is()\fR and \fIoutput_isnt()\fR except they use a regular expression for matching. .Sp \&\fIoutput_like()\fR attempts to match \f(CW$regex_stdout\fR and \f(CW$regex_stderr\fR against \&\s-1STDOUT\s0 and \s-1STDERR\s0 produced by \f(CW$coderef\fR. The test passes if both match. .Sp .Vb 1 \& output_like(sub {print "foo"; print STDERR "bar";},qr/foo/,qr/bar/); .Ve .Sp The above test is successful. .Sp Like \fIoutput_is()\fR, setting either \f(CW$regex_stdout\fR or \f(CW$regex_stderr\fR to \&\f(CW\*(C`undef\*(C'\fR ignores the output to that facility. .Sp .Vb 1 \& output_like(sub {print "foo"; print STDERR "bar";},qr/foo/,undef); .Ve .Sp is the same as .Sp .Vb 1 \& stdout_like(sub {print "foo"; print STDERR "bar";},qr/foo/); .Ve .Sp \&\fIoutput_unlike()\fR test pass if output from \f(CW$coderef\fR doesn't match \&\f(CW$regex_stdout\fR and \f(CW$regex_stderr\fR. .SH "EXPORTS" .IX Header "EXPORTS" By default, all tests are exported, however with the switch to Sub::Exporter export groups are now available to better limit imports. .PP To import tests for \s-1STDOUT:\s0 .PP .Vb 1 \& use Test::Output qw(:stdout); .Ve .PP To import tests \s-1STDERR:\s0 .PP .Vb 1 \& use Test::Output qw(:stderr); .Ve .PP To import just the functions: .PP .Vb 1 \& use Test::Output qw(:functions); .Ve .PP And to import all tests: .PP .Vb 1 \& use Test::Output; .Ve .PP The following is a list of group names and which functions are exported: .IP "stdout" 4 .IX Item "stdout" stdout_is stdout_isnt stdout_like stdout_unlike .IP "stderr" 4 .IX Item "stderr" stderr_is stderr_isnt stderr_like stderr_unlike .IP "output" 4 .IX Item "output" output_is output_isnt output_like output_unlike .IP "combined" 4 .IX Item "combined" combined_is combined_isnt combined_like combined_unlike .IP "tests" 4 .IX Item "tests" All of the above, this is the default when no options are given. .PP Sub::Exporter allows for many other options, I encourage reading its documentation. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "stdout_from" .IX Subsection "stdout_from" .Vb 2 \& my $stdout = stdout_from($coderef) \& my $stdout = stdout_from { ... }; .Ve .PP \&\fIstdout_from()\fR executes \f(CW$coderef\fR and captures \s-1STDOUT.\s0 .SS "stderr_from" .IX Subsection "stderr_from" .Vb 2 \& my $stderr = stderr_from($coderef) \& my $stderr = stderr_from { ... }; .Ve .PP \&\fIstderr_from()\fR executes \f(CW$coderef\fR and captures \s-1STDERR.\s0 .SS "output_from" .IX Subsection "output_from" .Vb 2 \& my ($stdout, $stderr) = output_from($coderef) \& my ($stdout, $stderr) = output_from {...}; .Ve .PP \&\fIoutput_from()\fR executes \f(CW$coderef\fR one time capturing both \s-1STDOUT\s0 and \s-1STDERR.\s0 .SS "combined_from" .IX Subsection "combined_from" .Vb 2 \& my $combined = combined_from($coderef); \& my $combined = combined_from {...}; .Ve .PP \&\fIcombined_from()\fR executes \f(CW$coderef\fR one time combines \s-1STDOUT\s0 and \s-1STDERR,\s0 and captures them. \fIcombined_from()\fR is equivalent to using 2>&1 in \s-1UNIX.\s0 .SH "AUTHOR" .IX Header "AUTHOR" Currently maintained by brian d foy, \f(CW\*(C`bdfoy@cpan.org\*(C'\fR. .PP Shawn Sorichetti, \f(CW\*(C`\*(C'\fR .SH "SOURCE AVAILABILITY" .IX Header "SOURCE AVAILABILITY" This module is in Github: .PP .Vb 1 \& http://github.com/briandfoy/test\-output/tree/master .Ve .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-test\-output@rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to chromatic whose TieOut.pm was the basis for capturing output. .PP Also thanks to rjbs for his help cleaning the documentation, and pushing me to Sub::Exporter. .PP Thanks to David Wheeler for providing code block support and tests. .PP Thanks to Michael G Schwern for the solution to combining \s-1STDOUT\s0 and \s-1STDERR.\s0 .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2005\-2013 Shawn Sorichetti, All Rights Reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.