summaryrefslogtreecommitdiff
path: root/js/process_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/process_test.ts')
-rw-r--r--js/process_test.ts72
1 files changed, 69 insertions, 3 deletions
diff --git a/js/process_test.ts b/js/process_test.ts
index 6eb4dfd89..6e5fe7947 100644
--- a/js/process_test.ts
+++ b/js/process_test.ts
@@ -1,6 +1,21 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { test, testPerm, assert, assertEquals } from "./test_util.ts";
-const { kill, run, DenoError, ErrorKind } = Deno;
+import {
+ test,
+ testPerm,
+ assert,
+ assertEquals,
+ assertStrContains
+} from "./test_util.ts";
+const {
+ kill,
+ run,
+ DenoError,
+ ErrorKind,
+ readFile,
+ open,
+ makeTempDir,
+ writeFile
+} = Deno;
test(function runPermissions(): void {
let caughtError = false;
@@ -71,7 +86,7 @@ testPerm(
{ write: true, run: true },
async function runWithCwdIsAsync(): Promise<void> {
const enc = new TextEncoder();
- const cwd = Deno.makeTempDirSync({ prefix: "deno_command_test" });
+ const cwd = await makeTempDir({ prefix: "deno_command_test" });
const exitCodeFile = "deno_was_here";
const pyProgramFile = "poll_exit.py";
@@ -205,6 +220,57 @@ testPerm({ run: true }, async function runStderrOutput(): Promise<void> {
p.close();
});
+testPerm(
+ { run: true, write: true, read: true },
+ async function runRedirectStdoutStderr(): Promise<void> {
+ const tempDir = await makeTempDir();
+ const fileName = tempDir + "/redirected_stdio.txt";
+ const file = await open(fileName, "w");
+
+ const p = run({
+ args: [
+ "python",
+ "-c",
+ "import sys; sys.stderr.write('error\\n'); sys.stdout.write('output\\n');"
+ ],
+ stdout: file.rid,
+ stderr: file.rid
+ });
+
+ await p.status();
+ p.close();
+ file.close();
+
+ const fileContents = await readFile(fileName);
+ const decoder = new TextDecoder();
+ const text = decoder.decode(fileContents);
+
+ assertStrContains(text, "error");
+ assertStrContains(text, "output");
+ }
+);
+
+testPerm(
+ { run: true, write: true, read: true },
+ async function runRedirectStdin(): Promise<void> {
+ const tempDir = await makeTempDir();
+ const fileName = tempDir + "/redirected_stdio.txt";
+ const encoder = new TextEncoder();
+ await writeFile(fileName, encoder.encode("hello"));
+ const file = await open(fileName, "r");
+
+ const p = run({
+ args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
+ stdin: file.rid
+ });
+
+ const status = await p.status();
+ assertEquals(status.code, 0);
+ p.close();
+ file.close();
+ }
+);
+
testPerm({ run: true }, async function runEnv(): Promise<void> {
const p = run({
args: [