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

3Re: Tests for 'printing' code

by jeffa (Bishop)
on Oct 19, 2003 at 15:31 UTC ( [id://300388]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Tests for 'printing' code
in thread Tests for 'printing' code

You don't. :) It's just a canned message. Why do you need to test if something was printed? That's not very helpful. Instead test what is about to be printed, before you print it. In fact, you don't need to print anything at all from your test suite (except user interaction messages like "Test this?" and your own debugging when your test has "bugs").

Now, don't get me wrong - what you originally wanted can be done, but do you really want to go there?

use IO::Scalar; use Test::More qw(no_plan); my $string; tie *STDOUT, 'IO::Scalar', \$string; ok(test_foo() eq 'bar'); ok($string eq 'foo'); $string = ''; ok(test_bar() eq 'baz'); ok($string eq 'bar'); $string = ''; sub test_foo { print 'foo'; return 'bar'; } sub test_bar { print 'bar'; return 'baz'; }
No thanks. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: 3Re: Tests for 'printing' code
by dda (Friar) on Oct 19, 2003 at 16:15 UTC
    No thanks, just ++jeffa. ;)

    --dda

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found