Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add test for pipe()
  • Loading branch information
FROGGS committed Apr 17, 2015
1 parent 4c4de48 commit 2d371de
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions S32-io/pipe.t
@@ -0,0 +1,30 @@
use v6;
use Test;

plan 5;

pipes_ok '1', '', 0, 'Child succeeds but does not print anything';
pipes_ok 'say 42', '42', 0, 'Child succeeds and prints something';
pipes_ok 'exit 1', '', 1, 'Child fails and prints nothing';
pipes_ok 'exit 42', '', 42, 'Child fails and prints nothing';
pipes_ok 'say 42; exit 7', '42', 7, 'Child fails and prints something';

sub pipes_ok($code, $out, $exit, $desc) {
subtest {
my $fh = pipe("$*EXECUTABLE -e \"$code\"", :r);
ok $fh ~~ IO::Handle, 'pipe() returns an IO::Handle';
my $lines = $fh.lines.join('');
my $ps = $fh.close;
if $exit {
nok $ps, 'pipe() returns something falsish on failure';
is $ps.exit, $exit, "Proc::Status.exit is $exit";
is $lines, $out, 'got correct output';
}
else {
ok $ps, 'pipe() returns something trueish on success';
is $ps.exit, 0, 'Proc::Status.exit is zero for a successful run';
is $ps.status, 0, 'Proc::Status.status is zero for a successful run';
is $lines, $out, 'got correct output';
}
}, $desc
}

0 comments on commit 2d371de

Please sign in to comment.