[Pdx-pm] Even more inline testing

Kris Bosland krisb at ring.org
Tue Jun 21 16:43:04 PDT 2005


On Sat, 18 Jun 2005, Michael G Schwern wrote:

> > 	Say, the wacky filehandle tying you are doing in pod2test*, does
> > that work on Win32 perl?  I would like to capture test results from the
> > inline test I am working on so I can massage them before printing.
>
> Yeah, it should have no problem.

I am having a problem trying to make this work with Test::More.  Is there
some IO redirection happening there?  I have included an example below.

BTW, should I call you 'Michal' or 'Schwern'?

Thanks.

-Kris


>cat test/catch.pl
#!/usr/$work/bin/perl -w
use strict;

package Catch;

sub TIEHANDLE {
    my($class, $var) = @_;
    return bless { var => $var }, $class;
}

sub PRINT  {
    my($self) = shift;
    no strict "refs";
    my $var = 'main::'.$self->{var};
    print STDERR "adding =>@_<= to =>$var<=\n";
    ${$var} .= join '', @_;
}

sub OPEN  {}    # XXX Hackery in case the user redirects
sub CLOSE {}    # XXX STDERR/STDOUT.  This is not the behavior we want.

sub READ {}
sub READLINE {}
sub GETC {}
sub BINMODE {}

package main;

use vars qw($_MYSTDOUT_);
$_MYSTDOUT_ = "bar\n";

my $codestring1 = "print qw{foo\n};\n";
my $codestring2 = "use Test::More qw(no_plan);\nprint qw{foofoo\n};\n";
my $codestring3 = "use File::Find;\nprint qw{foofoofoo\n};\n";

tie *STDOUT, 'Catch', '_MYSTDOUT_' or die $!;
#tie *STDERR, 'Catch', '_MYSTDERR_' or die $!;

my $result = eval $codestring1;
$result = eval $codestring2;
$result = eval $codestring3;

untie *STDOUT;
untie *STDERR;

no strict "refs";
print "got =>$_MYSTDOUT_<=\n";

__END__

>perl test/catch.pl
adding =>foo<= to =>main::_MYSTDOUT_<=
adding =>foofoofoo<= to =>main::_MYSTDOUT_<=
got =>bar
foofoofoofoo<=
>




More information about the Pdx-pm-list mailing list