Skip to content

Commit 59b2b38

Browse files
committed
map op syncpipe and adjusts tests for latest openpipe
1 parent 6da0dea commit 59b2b38

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

src/vm/moar/QAST/QASTOperationsMAST.nqp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,16 @@ my %const_map := nqp::hash(
18941894
'STAT_PLATFORM_BLOCKSIZE', -6,
18951895
'STAT_PLATFORM_BLOCKS', -7,
18961896

1897+
'PIPE_INHERIT_IN', 1,
1898+
'PIPE_IGNORE_IN', 2,
1899+
'PIPE_CAPTURE_IN', 4,
1900+
'PIPE_INHERIT_OUT', 8,
1901+
'PIPE_IGNORE_OUT', 16,
1902+
'PIPE_CAPTURE_OUT', 32,
1903+
'PIPE_INHERIT_ERR', 64,
1904+
'PIPE_IGNORE_ERR', 128,
1905+
'PIPE_CAPTURE_ERR', 256,
1906+
18971907
'SIG_HUP', 1,
18981908
'SIG_INT', 2,
18991909
'SIG_QUIT', 3,
@@ -2696,6 +2706,7 @@ QAST::MASTOperations.add_core_moarop_mapping('shell', 'shell');
26962706
QAST::MASTOperations.add_core_moarop_mapping('spawn', 'spawn');
26972707
QAST::MASTOperations.add_core_moarop_mapping('gethostname', 'gethostname');
26982708
QAST::MASTOperations.add_core_moarop_mapping('openpipe', 'openpipe');
2709+
QAST::MASTOperations.add_core_moarop_mapping('syncpipe', 'syncpipe');
26992710
QAST::MASTOperations.add_core_moarop_mapping('rand_i', 'rand_i');
27002711
QAST::MASTOperations.add_core_moarop_mapping('rand_n', 'randscale_n');
27012712
QAST::MASTOperations.add_core_moarop_mapping('srand', 'srand', 0);

t/nqp/86-pipes.t

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,73 @@
11
#! nqp
22

3-
# Testing nqp::openpipe on JVM.
3+
# Testing nqp::openpipe.
44

5-
plan(14);
5+
plan(16);
6+
7+
my $read_out := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_OUT + nqp::const::PIPE_INHERIT_ERR;
8+
my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_OUT + nqp::const::PIPE_CAPTURE_ERR;
69

710
{
8-
my $p := nqp::openpipe('echo aardvarks', nqp::cwd(), nqp::getenvhash(), '');
9-
ok( nqp::defined($p) == 1, 'nqp::openpipe' );
11+
my $in := nqp::syncpipe();
12+
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' );
1016

11-
my $pstr := nqp::readallfh($p);
17+
my $pstr := nqp::readallfh($out);
1218
ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
1319

1420
# What should the return value of nqp::close be? MoarVM and JVM always return 1.
15-
nqp::closefh($p); ok( 1, 'nqp::closefh with a pipe');
16-
nqp::closefh($p); ok( 1, 'nqp::closefh with a pipe already closed');
21+
nqp::closefh($out); ok( 1, 'nqp::closefh with a pipe');
22+
nqp::closefh($out); ok( 1, 'nqp::closefh with a pipe already closed');
23+
}
1724

18-
my $q := nqp::openpipe('doesnotexist', nqp::cwd(), nqp::getenvhash(), '');
19-
ok( nqp::defined($q) == 1, 'nqp::openpipe nonexistent cmd');
25+
{
26+
my $in := nqp::syncpipe();
27+
my $out := nqp::syncpipe();
28+
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');
2031

21-
my $qstr := nqp::readallfh($q);
32+
my $str_out := nqp::readallfh($out);
33+
my $str_err := nqp::readallfh($err);
2234
nqp::getcomp('nqp').backend.name eq 'parrot' ??
23-
ok( $qstr ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command') !!
24-
ok( $qstr eq '', 'nqp::readallfh with a pipe nonexistent command');
35+
ok( $str_out ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command') !!
36+
ok( $str_out eq '' && $str_err ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command');
2537

26-
nqp::closefh($q); ok( 1, 'nqp::closefh with a pipe nonexistent command');
38+
nqp::closefh($out); ok( 1, 'nqp::closefh with a pipe nonexistent command');
39+
nqp::closefh($err); ok( 1, 'nqp::closefh with a pipe nonexistent command');
2740
}
2841

2942
# same tests but do nqp::closefh_i instead of nqp::closefh
3043
{
31-
my $p := nqp::openpipe('echo aardvarks', nqp::cwd(), nqp::getenvhash(), '');
32-
ok( nqp::defined($p) == 1, 'nqp::openpipe' );
44+
my $in := nqp::syncpipe();
45+
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' );
3349

34-
my $pstr := nqp::readallfh($p);
35-
ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
50+
my $str := nqp::readallfh($out);
51+
ok( $str ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
3652

37-
ok( nqp::closefh_i($p) == 0, 'nqp::closefh_i with a pipe');
38-
ok( nqp::closefh_i($p) == 0, 'nqp::closefh_i with a pipe already closed');
53+
ok( nqp::closefh_i($out) == 0, 'nqp::closefh_i with a pipe');
54+
ok( nqp::closefh_i($out) == 0, 'nqp::closefh_i with a pipe already closed');
55+
}
3956

40-
my $q := nqp::openpipe('doesnotexist', nqp::cwd(), nqp::getenvhash(), '');
41-
ok( nqp::defined($q) == 1, 'nqp::openpipe nonexistent cmd');
57+
{
58+
my $in := nqp::syncpipe();
59+
my $out := nqp::syncpipe();
60+
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');
4263

43-
my $qstr := nqp::readallfh($q);
64+
my $str_out := nqp::readallfh($out);
65+
my $str_err := nqp::readallfh($err);
4466
nqp::getcomp('nqp').backend.name eq 'parrot' ??
45-
ok( $qstr ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command') !!
46-
ok( $qstr eq '', 'nqp::readallfh with a pipe nonexistent command');
67+
ok( $str_out ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command') !!
68+
ok( $str_out eq '' && $str_err ~~ / 'doesnotexist' /, 'nqp::readallfh with a pipe nonexistent command');
4769

48-
ok( nqp::closefh_i($q) != 0, 'nqp::closefh_i with a pipe nonexistent command');
70+
# Only the first call to closefh_i returns the exit code.
71+
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');
4973
}

0 commit comments

Comments
 (0)