2 # $Id: piconv.t,v 0.3 2009/11/16 14:08:13 dankogai Exp $
6 if ( $ENV{'PERL_CORE'} && $] >= 5.011) {
7 print "1..0 # Skip: Don't know how to test this within perl's core\n";
15 use IPC::Open3 qw(open3);
19 my $WIN = $^O eq 'MSWin32';
22 eval { require IPC::Run; IPC::Run->VERSION(0.83); 1; } or
23 plan skip_all => 'Win32 environments require IPC::Run 0.83 to complete this test';
30 File::Spec->catdir( $FindBin::RealBin, File::Spec->updir, 'blib' ) );
31 my $script = File::Spec->catdir($blib, 'script', 'piconv');
32 my @base_cmd = ( $^X, "-Mblib=$blib", $script );
37 my ( $st, $out, $err ) = run_cmd;
38 is( $st, 0, 'status for usage call' );
39 is( $out, $WIN ? undef : '' );
40 like( $err, qr{^piconv}, 'usage' );
44 my($st, $out, $err) = run_cmd [qw(-S foobar -f utf-8 -t ascii), $script];
45 like($err, qr{unknown scheme.*fallback}i, 'warning for unknown scheme');
49 my ( $st, $out, $err ) = run_cmd [qw(-f utf-8 -t ascii ./non-existing/file)];
50 like( $err, qr{can't open}i );
54 my ( $args, $in ) = @_;
56 my $out = "x" x 10_000;
58 my $err = "x" x 10_000;
62 IPC::Run->import(qw(run timeout));
65 @cmd = (@base_cmd, @$args);
69 run(\@cmd, \$in, \$out, \$err, timeout(10));
71 $out = undef if ($out eq '');
75 my ( $in_fh, $out_fh, $err_fh );
78 gensym; # sigh... otherwise stderr gets just to $out_fh, not to $err_fh
79 my $pid = open3( $in_fh, $out_fh, $err_fh, @base_cmd, @$args )
80 or die "Can't run @base_cmd @$args: $!";
82 my $sel = IO::Select->new( $out_fh, $err_fh );
84 while ( my @ready = $sel->can_read ) {
88 last if !$sel->handles;
90 elsif ( $out_fh == $fh ) {
94 elsif ( $err_fh == $fh ) {