(I should have put "Solved" in quotes)

There appears to be a huge amount of disagreement at 
http://perlmonks.org/?node_id=574085 regarding how to approach synchronizing 
STDERR and STDOUT.  While many offer useful suggestions, the suggestions tend 
to be rather complicated, might require non-core modules or don't guarantee 
that STDERR and STDOUT be in synch.  I'm looking at a bewildering array of 
stuff and I can't test these suggestions easily since I don't have access to 
multiple operating systems or Perl versions.  However, I thought of the 
following trick.

When TAPx::Parser runs a Perl test script, it first fetches the switches.  
There are two basic switches, those defined in the test script and those the 
user defines.  However, I just added a third:

    my @switches = (
         $self->switches,
         qw(-MTest::Builder -MTAPX::Parser::Builder),
    );
    # get switches from test script

In adding those two, I first load Test::Builder and then I load my tiny little 
override:
 
    package TAPx::Parser::Builder;

    use strict;

    {
        local $^W;

        my $overridden;

        sub Test::Builder::failure_output {
            my ( $self, $fh ) = @_;

            if ( defined $fh ) {
                $self->{Fail_FH} = $self->_new_fh($fh);
                $overridden = 1;
            }
            return $overridden ? $self->{Fail_FH} : $self->output;
        }
    }    

    1;

$self->output is where the non-diag output goes.  So for any test code which 
doesn't try to redirect failure output, I can parse all results flawlessly.  
For test code which does try to redirect failure output, I probably won't get 
the comments but everything else will parse just fine.

Now I have guaranteed cross-platform behavior, STDERR and STDOUT are guaranteed 
to be in synch, this doesn't cause any problems for Test::Harness, I don't need 
to fork Test::Builder and I override one method which has not changed since May 
2005.  Unfortunately, I'll have to alter the above to handle versions of 
Test-Simple prior to 0.60 and that sucks, but it also *seems* to work 
flawlessly.

I'm sure folks may not be happy about this, but it works.  Thoughts?  It makes 
me squirm, but I am not in a position to test the other alternatives and I have 
no desire to even try and write code I can't test.


Cheers,
Ovid

-- 
Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/



Reply via email to