|
1 | 1 | #! nqp
|
2 | 2 |
|
3 |
| -# Testing nqp::openpipe on JVM. |
| 3 | +# Testing nqp::openpipe. |
4 | 4 |
|
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; |
6 | 9 |
|
7 | 10 | {
|
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' ); |
10 | 16 |
|
11 |
| - my $pstr := nqp::readallfh($p); |
| 17 | + my $pstr := nqp::readallfh($out); |
12 | 18 | ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');
|
13 | 19 |
|
14 | 20 | # 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 | +} |
17 | 24 |
|
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'); |
20 | 31 |
|
21 |
| - my $qstr := nqp::readallfh($q); |
| 32 | + my $str_out := nqp::readallfh($out); |
| 33 | + my $str_err := nqp::readallfh($err); |
22 | 34 | 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'); |
25 | 37 |
|
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'); |
27 | 40 | }
|
28 | 41 |
|
29 | 42 | # same tests but do nqp::closefh_i instead of nqp::closefh
|
30 | 43 | {
|
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' ); |
33 | 49 |
|
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'); |
36 | 52 |
|
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 | +} |
39 | 56 |
|
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'); |
42 | 63 |
|
43 |
| - my $qstr := nqp::readallfh($q); |
| 64 | + my $str_out := nqp::readallfh($out); |
| 65 | + my $str_err := nqp::readallfh($err); |
44 | 66 | 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'); |
47 | 69 |
|
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'); |
49 | 73 | }
|
0 commit comments