Skip to content

Commit 48bfeb3

Browse files
committed
replace nqp::openpipe by nqp::shell in tests
1 parent 61aba0b commit 48bfeb3

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

t/nqp/86-pipes.t

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#! nqp
22

3-
# Testing nqp::openpipe.
3+
# Testing nqp::shell wrt capturing output.
44

5-
plan(16);
5+
plan(11);
66

77
my $read_out := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_OUT + nqp::const::PIPE_INHERIT_ERR;
88
my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_OUT + nqp::const::PIPE_CAPTURE_ERR;
99

1010
{
11-
my $in := nqp::syncpipe();
11+
my $in := nqp::null();
1212
my $out := nqp::syncpipe();
13-
my $err := nqp::syncpipe();
14-
my $pid := nqp::openpipe('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
15-
ok( $pid, 'nqp::openpipe' );
13+
my $err := nqp::null();
14+
nqp::setinputlinesep($out, "\n");
15+
nqp::setencoding($out, 'utf8');
16+
nqp::shell('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
1617

1718
my $pstr := nqp::readallfh($out);
1819
ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
@@ -23,11 +24,14 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
2324
}
2425

2526
{
26-
my $in := nqp::syncpipe();
27+
my $in := nqp::null();
2728
my $out := nqp::syncpipe();
2829
my $err := nqp::syncpipe();
29-
my $pid := nqp::openpipe('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
30-
ok( $pid, 'nqp::openpipe nonexistent cmd');
30+
nqp::setinputlinesep($out, "\n");
31+
nqp::setinputlinesep($err, "\n");
32+
nqp::setencoding($out, 'utf8');
33+
nqp::setencoding($err, 'utf8');
34+
nqp::shell('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
3135

3236
my $str_out := nqp::readallfh($out);
3337
my $str_err := nqp::readallfh($err);
@@ -41,11 +45,12 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
4145

4246
# same tests but do nqp::closefh_i instead of nqp::closefh
4347
{
44-
my $in := nqp::syncpipe();
48+
my $in := nqp::null();
4549
my $out := nqp::syncpipe();
46-
my $err := nqp::syncpipe();
47-
my $pid := nqp::openpipe('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
48-
ok( $pid, 'nqp::openpipe' );
50+
my $err := nqp::null();
51+
nqp::setinputlinesep($out, "\n");
52+
nqp::setencoding($out, 'utf8');
53+
nqp::shell('echo aardvarks', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out);
4954

5055
my $str := nqp::readallfh($out);
5156
ok( $str ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
@@ -55,19 +60,20 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
5560
}
5661

5762
{
58-
my $in := nqp::syncpipe();
63+
my $in := nqp::null();
5964
my $out := nqp::syncpipe();
6065
my $err := nqp::syncpipe();
61-
my $pid := nqp::openpipe('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
62-
ok( $pid, 'nqp::openpipe nonexistent cmd');
66+
nqp::setinputlinesep($out, "\n");
67+
nqp::setinputlinesep($err, "\n");
68+
nqp::setencoding($out, 'utf8');
69+
nqp::setencoding($err, 'utf8');
70+
nqp::shell('doesnotexist', nqp::cwd(), nqp::getenvhash(), $in, $out, $err, $read_out_and_err);
6371

6472
my $str_out := nqp::readallfh($out);
6573
my $str_err := nqp::readallfh($err);
6674
nqp::getcomp('nqp').backend.name eq 'parrot' ??
6775
ok( $str_out ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command') !!
6876
ok( $str_out eq '' && $str_err ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command');
6977

70-
# Only the first call to closefh_i returns the exit code.
7178
ok( nqp::closefh_i($out) != 0, 'nqp::closefh_i with a pipe nonexistent command');
72-
ok( nqp::closefh_i($err) == 0, 'nqp::closefh_i with a pipe nonexistent command');
7379
}

0 commit comments

Comments
 (0)