On Tue, 24 Aug 2004 17:47:42 -0700 (PDT), Ovid
<[EMAIL PROTECTED]> wrote:
> --- Peter Kay <[EMAIL PROTECTED]> 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.

Reply via email to