Skip to content

Commit 71e653a

Browse files
committed
Update final test using char-level I/O.
1 parent 5d3e388 commit 71e653a

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

t/nqp/086-pipes.t

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
1111
my $in := nqp::null();
1212
my $out := nqp::syncpipe();
1313
my $err := nqp::null();
14-
nqp::setinputlinesep($out, "\n");
15-
nqp::setencoding($out, 'utf8');
14+
my $out-wrap := NQPFileHandle.new.wrap($out);
1615
nqp::shell('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
1716

18-
ok( !nqp::eoffh($out), 'nqp::eoffh on a pipe while it still has data' );
17+
ok( !$out-wrap.eof, 'eof on a pipe while it still has data' );
1918

20-
my $pstr := nqp::readallfh($out);
21-
ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
19+
my $pstr := $out-wrap.slurp;
20+
ok( $pstr ~~ / 'aardvarks' /, 'nqp::slurp with a pipe');
2221

23-
ok( nqp::eoffh($out), 'nqp::eoffh on a pipe we have read everything out of');
22+
ok( $out-wrap.eof, 'eof on a pipe we have read everything out of');
2423

2524
# What should the return value of nqp::close be? MoarVM and JVM always return 1.
2625
nqp::closefh($out); ok( 1, 'nqp::closefh with a pipe');
@@ -31,15 +30,13 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
3130
my $in := nqp::null();
3231
my $out := nqp::syncpipe();
3332
my $err := nqp::syncpipe();
34-
nqp::setinputlinesep($out, "\n");
35-
nqp::setinputlinesep($err, "\n");
36-
nqp::setencoding($out, 'utf8');
37-
nqp::setencoding($err, 'utf8');
33+
my $out-wrap := NQPFileHandle.new.wrap($out);
34+
my $err-wrap := NQPFileHandle.new.wrap($err);
3835
nqp::shell('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
3936

40-
my $str_out := nqp::readallfh($out);
41-
my $str_err := nqp::readallfh($err);
42-
is( $str_out, '' && $str_err ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command');
37+
my $str_out := $out-wrap.slurp;
38+
my $str_err := $err-wrap.slurp;
39+
is( $str_out, '' && $str_err ~~ / 'doesnotexist' /, 'nqp::slurp with a pipe nonexistent command');
4340

4441
nqp::closefh($out); ok( 1, 'nqp::closefh with a pipe nonexistent command');
4542
nqp::closefh($err); ok( 1, 'nqp::closefh with a pipe nonexistent command');
@@ -50,12 +47,11 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
5047
my $in := nqp::null();
5148
my $out := nqp::syncpipe();
5249
my $err := nqp::null();
53-
nqp::setinputlinesep($out, "\n");
54-
nqp::setencoding($out, 'utf8');
50+
my $out-wrap := NQPFileHandle.new.wrap($out);
5551
nqp::shell('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
5652

57-
my $str := nqp::readallfh($out);
58-
ok( $str ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
53+
my $str := $out-wrap.slurp;
54+
ok( $str ~~ / 'aardvarks' /, 'nqp::slurp with a pipe');
5955

6056
ok( nqp::closefh_i($out) == 0, 'nqp::closefh_i with a pipe');
6157
ok( nqp::closefh_i($out) == 0, 'nqp::closefh_i with a pipe already closed');
@@ -65,15 +61,13 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
6561
my $in := nqp::null();
6662
my $out := nqp::syncpipe();
6763
my $err := nqp::syncpipe();
68-
nqp::setinputlinesep($out, "\n");
69-
nqp::setinputlinesep($err, "\n");
70-
nqp::setencoding($out, 'utf8');
71-
nqp::setencoding($err, 'utf8');
64+
my $out-wrap := NQPFileHandle.new.wrap($out);
65+
my $err-wrap := NQPFileHandle.new.wrap($err);
7266
nqp::shell('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
7367

74-
my $str_out := nqp::readallfh($out);
75-
my $str_err := nqp::readallfh($err);
76-
is( $str_out, '' && $str_err ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command');
68+
my $str_out := $out-wrap.slurp;
69+
my $str_err := $err-wrap.slurp;
70+
is( $str_out, '' && $str_err ~~ / 'doesnotexist' /, 'nqp::slurp with a pipe nonexistent command');
7771

7872
ok( nqp::closefh_i($out) != 0, 'nqp::closefh_i with a pipe nonexistent command');
7973
}

0 commit comments

Comments
 (0)