Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to Test Output from the Standard Output

by GrandFather (Saint)
on Jun 10, 2010 at 03:28 UTC ( #843963=note: print w/replies, xml ) Need Help??


in reply to How to Test Output from the Standard Output

One way is to redirect stdout to a file. For this purpose it helps if the file is actually a Perl variable. Consider:

package Test_Package; use strict; sub testing { print "okay."; }; 1; use strict; use Test::More tests => 1; my $log; open my $logFile, '>', \$log; my $oldStdOut = select $logFile; Test_Package->testing(); select $oldStdOut; close $logFile; is($log, 'okay', 'Testing okay');

Prints:

1..1 not ok 1 - Testing okay # Failed test 'Testing okay' # at ...\noname.pl line 25. # got: 'okay.' # expected: 'okay' # Looks like you failed 1 test of 1.

The error is deliberate btw.

True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://843963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-01-29 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?