2 # $Id: piconv.t,v 0.2 2009/07/13 00:50:52 dankogai Exp $
9 use IPC::Open3 qw(open3);
13 my $nofork = ! $Config{d_fork};
16 eval { require IPC::Run; IPC::Run->VERSION(0.83); 1; } or
17 plan skip_all => 'Without fork(), we require IPC::Run 0.83 to complete this test';
24 File::Spec->catdir( $FindBin::RealBin, File::Spec->updir, 'blib' ) );
25 my $script = File::Spec->catdir($blib, 'script', 'piconv');
26 my @base_cmd = ( $^X, ($ENV{PERL_CORE} ? () : "-Mblib=$blib"), $script );
31 my ( $st, $out, $err ) = run_cmd;
32 is( $st, 0, 'status for usage call' );
33 is( $out, $nofork ? undef : '' );
34 like( $err, qr{^piconv}, 'usage' );
38 my($st, $out, $err) = run_cmd [qw(-S foobar -f utf-8 -t ascii), $script];
39 like($err, qr{unknown scheme.*fallback}i, 'warning for unknown scheme');
43 my ( $st, $out, $err ) = run_cmd [qw(-f utf-8 -t ascii ./non-existing/file)];
44 like( $err, qr{can't open}i );
48 my ( $args, $in ) = @_;
50 my $out = "x" x 10_000;
52 my $err = "x" x 10_000;
56 IPC::Run->import(qw(run timeout));
59 @cmd = (@base_cmd, @$args);
63 run(\@cmd, \$in, \$out, \$err, timeout(10));
65 $out = undef if ($out eq '');
69 my ( $in_fh, $out_fh, $err_fh );
72 gensym; # sigh... otherwise stderr gets just to $out_fh, not to $err_fh
73 my $pid = open3( $in_fh, $out_fh, $err_fh, @base_cmd, @$args )
74 or die "Can't run @base_cmd @$args: $!";
76 my $sel = IO::Select->new( $out_fh, $err_fh );
78 while ( my @ready = $sel->can_read ) {
82 last if !$sel->handles;
84 elsif ( $out_fh == $fh ) {
88 elsif ( $err_fh == $fh ) {