summaryrefslogtreecommitdiff
path: root/cli/tests/unit/process_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/process_test.ts')
-rw-r--r--cli/tests/unit/process_test.ts67
1 files changed, 29 insertions, 38 deletions
diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts
index c6503b2e0..cf512eea5 100644
--- a/cli/tests/unit/process_test.ts
+++ b/cli/tests/unit/process_test.ts
@@ -5,20 +5,11 @@ import {
assertStringContains,
unitTest,
} from "./test_util.ts";
-const {
- kill,
- run,
- readFile,
- open,
- makeTempDir,
- writeFile,
- writeFileSync,
-} = Deno;
unitTest(function runPermissions(): void {
let caughtError = false;
try {
- run({ cmd: ["python", "-c", "print('hello world')"] });
+ Deno.run({ cmd: ["python", "-c", "print('hello world')"] });
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
@@ -27,7 +18,7 @@ unitTest(function runPermissions(): void {
});
unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "print('hello world')"],
stdout: "piped",
stderr: "null",
@@ -43,7 +34,7 @@ unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
unitTest(
{ perms: { run: true } },
async function runCommandFailedWithCode(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"],
});
const status = await p.status();
@@ -61,7 +52,7 @@ unitTest(
perms: { run: true },
},
async function runCommandFailedWithSignal(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"],
});
const status = await p.status();
@@ -75,7 +66,7 @@ unitTest(
unitTest({ perms: { run: true } }, function runNotFound(): void {
let error;
try {
- run({ cmd: ["this file hopefully doesn't exist"] });
+ Deno.run({ cmd: ["this file hopefully doesn't exist"] });
} catch (e) {
error = e;
}
@@ -87,7 +78,7 @@ unitTest(
{ perms: { write: true, run: true } },
async function runWithCwdIsAsync(): Promise<void> {
const enc = new TextEncoder();
- const cwd = await makeTempDir({ prefix: "deno_command_test" });
+ const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
const exitCodeFile = "deno_was_here";
const pyProgramFile = "poll_exit.py";
@@ -107,8 +98,8 @@ while True:
pass
`;
- writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
- const p = run({
+ Deno.writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
+ const p = Deno.run({
cwd,
cmd: ["python", `${pyProgramFile}.py`],
});
@@ -116,7 +107,7 @@ while True:
// Write the expected exit code *after* starting python.
// This is how we verify that `run()` is actually asynchronous.
const code = 84;
- writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
+ Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
const status = await p.status();
assertEquals(status.success, false);
@@ -129,7 +120,7 @@ while True:
unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: "piped",
});
@@ -153,7 +144,7 @@ unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped",
});
@@ -182,7 +173,7 @@ unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stderr.write('hello')"],
stderr: "piped",
});
@@ -209,7 +200,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
});
unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped",
});
@@ -222,7 +213,7 @@ unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stderr.write('error')"],
stderr: "piped",
});
@@ -235,14 +226,14 @@ unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdoutStderr(): Promise<void> {
- const tempDir = await makeTempDir();
+ const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
- const file = await open(fileName, {
+ const file = await Deno.open(fileName, {
create: true,
write: true,
});
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -256,7 +247,7 @@ unitTest(
p.close();
file.close();
- const fileContents = await readFile(fileName);
+ const fileContents = await Deno.readFile(fileName);
const decoder = new TextDecoder();
const text = decoder.decode(fileContents);
@@ -268,13 +259,13 @@ unitTest(
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdin(): Promise<void> {
- const tempDir = await makeTempDir();
+ const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const encoder = new TextEncoder();
- await writeFile(fileName, encoder.encode("hello"));
- const file = await open(fileName);
+ await Deno.writeFile(fileName, encoder.encode("hello"));
+ const file = await Deno.open(fileName);
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: file.rid,
});
@@ -287,7 +278,7 @@ unitTest(
);
unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -306,7 +297,7 @@ unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
});
unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -340,7 +331,7 @@ unitTest(function killPermissions(): void {
// subprocess we can safely kill. Instead we send SIGCONT to the current
// process - assuming that Deno does not have a special handler set for it
// and will just continue even if a signal is erroneously sent.
- kill(Deno.pid, Deno.Signal.SIGCONT);
+ Deno.kill(Deno.pid, Deno.Signal.SIGCONT);
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
@@ -349,12 +340,12 @@ unitTest(function killPermissions(): void {
});
unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assertEquals(Deno.Signal.SIGINT, 2);
- kill(p.pid, Deno.Signal.SIGINT);
+ Deno.kill(p.pid, Deno.Signal.SIGINT);
const status = await p.status();
assertEquals(status.success, false);
@@ -371,7 +362,7 @@ unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> {
});
unitTest({ perms: { run: true } }, function killFailed(): void {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assert(!p.stdin);
@@ -379,7 +370,7 @@ unitTest({ perms: { run: true } }, function killFailed(): void {
let err;
try {
- kill(p.pid, 12345);
+ Deno.kill(p.pid, 12345);
} catch (e) {
err = e;
}