Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add nqp::openpipe tests (JVM only)
  • Loading branch information
donaldh committed Sep 4, 2013
1 parent 66c9113 commit 9636fe9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -1920,7 +1920,7 @@ QAST::OperationsJAST.add_core_op('shell', -> $qastcomp, $op {
!! QAST::Op.new( :op('shell3'), |@operands ));
});
QAST::OperationsJAST.map_classlib_core_op('spawn', $TYPE_OPS, 'spawn', [$RT_OBJ, $RT_STR, $RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('openpipe', $TYPE_OPS, 'openpipe', [$RT_STR, $RT_STR, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('openpipe', $TYPE_OPS, 'openpipe', [$RT_STR, $RT_STR, $RT_OBJ, $RT_STR], $RT_OBJ, :tc);

QAST::OperationsJAST.map_classlib_core_op('symlink', $TYPE_OPS, 'symlink', [$RT_STR, $RT_STR], $RT_INT, :tc);

Expand Down
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/io/ProcessHandle.java
Expand Up @@ -23,7 +23,7 @@ public class ProcessHandle extends SyncHandle {
public ProcessHandle(ThreadContext tc, String cmd, String dir, Map<String, String> env) {
ProcessBuilder pb = new ProcessBuilder("sh", "-c", cmd);
pb.directory(new File(dir));
pb.redirectError(Redirect.INHERIT);
pb.redirectErrorStream(true);

// Clear the JVM inherited environment and use provided only
Map<String, String> pbEnv = pb.environment();
Expand Down
6 changes: 5 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -754,7 +754,11 @@ public static long link(String before, String after, ThreadContext tc) {
return 0;
}

public static SixModelObject openpipe(String cmd, String dir, SixModelObject envObj, ThreadContext tc) {
public static SixModelObject openpipe(String cmd, String dir,
SixModelObject envObj, String errPath, ThreadContext tc) {

// TODO: errPath NYI

Map<String, String> env = new HashMap<String, String>();
SixModelObject iter = iter(envObj, tc);
while (istrue(iter, tc) != 0) {
Expand Down
22 changes: 22 additions & 0 deletions t/jvm/02-pipes.t
@@ -0,0 +1,22 @@
#! nqp

# Testing nqp::openpipe on JVM.

plan(7);

my $p := nqp::openpipe('echo aardvarks', nqp::cwd(), nqp::getenvhash(), '');
ok( nqp::defined($p) == 1, 'nqp::openpipe' );

my $pstr := nqp::readallfh($p);
ok( $pstr ~~ / 'aardvarks' /, 'nqp::readallfh with a pipe');

ok( nqp::closefh($p), 'nqp::closefh with a pipe');
ok( nqp::closefh($p), 'nqp::closefh with a pipe already closed');

my $q := nqp::openpipe('doesnotexist', nqp::cwd(), nqp::getenvhash(), '');
ok( nqp::defined($q) == 1, 'nqp::openpipe nonexistent cmd');

my $qstr := nqp::readallfh($q);
ok( $qstr ~~ / 'command not found' /, 'nqp::readallfh with a pipe nonexistent command');

ok( nqp::closefh($q), 'nqp::closefh with a pipe nonexistent command');

0 comments on commit 9636fe9

Please sign in to comment.