develooper Front page | | Postings from October 2004

Re: Test::Harness with modules that output to STDOUT

Thread Previous | Thread Next
Michael G Schwern
October 16, 2004 13:06
Re: Test::Harness with modules that output to STDOUT
Message ID:
On Tue, 24 Aug 2004 17:47:42 -0700 (PDT), Ovid
<> wrote:
> --- Peter Kay <> wrote:
> > Ok, what's the elegent way to ignore/dispose of the output the tested
> > module produces?
> What I do whenever this happens is to move the printing code to a subroutine or method and
> override that to capture the output.  So if I have something like this:
>   sub Foo::_print {
>     print shift;
>   }

The danger here is you're altering the code before you test it.  And
its a potentially wide-spread and invasive change, hunting down all
the prints to STDOUT.  And its a glassbox test, you're making
assumptions about the internal implementation.  Tying avoids all this
and you can still capture the output.

I'm not saying having your own print subroutine is a bad idea.  In
fact I often wind up doing this to guard against stray bits of magic.

    sub _print {
        local($\, $,);
        print @_;

But I do that after the code is tested.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About