develooper Front page | perl.qa | Postings from October 2004

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

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
October 16, 2004 13:06
Subject:
Re: Test::Harness with modules that output to STDOUT
Message ID:
313c1d13041016130679337011@mail.gmail.com
On Tue, 24 Aug 2004 17:47:42 -0700 (PDT), Ovid
<publiustemp-perlqa@yahoo.com> wrote:
> --- Peter Kay <peterkayatwork@yahoo.com> 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About