IPC-Capture
view release on metacpan or search on metacpan
t/01-capture_of_stdout_and_stderr.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl IPC-Capture.t'
#########################
use warnings;
use strict;
$|=1;
use Data::Dumper;
use Test::More;
use Test::Differences;
use FindBin qw( $Bin );
use lib "$Bin/../lib";
use lib "$Bin/lib";
plan tests=> 14;
my $DEBUG = 0;
my $CHOMPALOT = 1;
my $PERL = $^X;
my $CLASS = 'IPC::Capture';
use_ok( $CLASS );
{#3
my $test_name = "Testing basic creation of object of type $CLASS";
my $obj = $CLASS->new();
my $type = ref( $obj );
is( $type, $CLASS, $test_name );
}
{#4-#8
my $test_name = q{ Testing method "run" with way "qx" };
my $test_cmd = "$PERL $Bin/bin/yammer_to_stderr_and_stdout";
my $ic = $CLASS->new({way=>'qx'});
my @filters =
( 'stdout_only',
'stderr_only',
'all_output',
'all_separated',
);
foreach my $od ( @filters ) {
$ic->set_filter( $od );
my $output = $ic->run( $test_cmd );
my $expected = expectorant( $od );
if ($CHOMPALOT) {
chompalot( \$output );
chompalot( \$expected );
}
if( not( ref( $output ) ) ) {
eq_or_diff( $output, $expected,
"$test_name with filter $od");
} elsif( ref( $output ) eq 'ARRAY' ) {
is_deeply(\$output, \$expected,
"$test_name with filter $od (whole)");
eq_or_diff( $output->[0], $expected->[0],
"$test_name with filter $od (stdout)");
eq_or_diff( $output->[1], $expected->[1],
"$test_name with filter $od (stderr)");
}
}
}
( run in 1.911 second using v1.01-cache-2.11-cpan-97f6503c9c8 )