dagolden / Capture-Tiny

(Perl) Capture STDOUT and STDERR from Perl, XS or external programs
http://search.cpan.org/dist/Capture-Tiny/
39 stars 19 forks source link

Capture::Tiny + Carp + Debugger fails to capture STDERR [rt.cpan.org #83915] #9

Open dagolden opened 11 years ago

dagolden commented 11 years ago

https://rt.cpan.org/Ticket/Display.html?id=83915

This is the smallest test case I can replicate:

    #!/usr/bin/env perl

    use Capture::Tiny 'capture';
    use Carp;

    my ( $in, $err, @results ) = capture {
        print "STDIN";
        carp("STDERR");
        return ( 1, 2 );
    };

As expected, that prints no output. However, if you run under the 
debugger, STDERR is written to my terminal and $err contains the empty 
string. If you prefer a test:

    use Capture::Tiny 'capture';
    use Test::More;
    use Carp;

    my ( $in, $err, @results ) = capture {
        print "STDIN";
        carp("STDERR");
        return ( 1, 2 );
    };
    is $in,    'STDIN',     '$in ok';
    like $out, qr/^STDERR/, '$out ok';
    is_deeply \@results, [ 1, 2 ], '@results ok';

    done_testing;

However, I can only force that test to fail under the debugger, making 
it somewhat less useful.

This is Capture::Tiny version 0.21

This is Carp version 1.25

This is perl 5, version 12, subversion 2 (v5.12.2) built for x86_64-
linux

$ uname -a
Linux ovid-desktop 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:18:21 
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Cheers,
Ovid