2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-06-21 19:00:14 -04:00
|
|
|
import {
|
|
|
|
assert,
|
2020-06-25 12:38:19 -04:00
|
|
|
assertThrows,
|
2019-06-21 19:00:14 -04:00
|
|
|
assertEquals,
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains,
|
2020-03-28 13:03:49 -04:00
|
|
|
unitTest,
|
2019-06-21 19:00:14 -04:00
|
|
|
} from "./test_util.ts";
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function runPermissions(): void {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.run({ cmd: ["python", "-c", "print('hello world')"] });
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "print('hello world')"],
|
2020-03-03 09:51:07 -05:00
|
|
|
stdout: "piped",
|
2020-03-28 13:03:49 -04:00
|
|
|
stderr: "null",
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
|
|
|
const status = await p.status();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(status.success, true);
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
assertEquals(status.signal, undefined);
|
2020-06-09 07:18:18 -04:00
|
|
|
p.stdout.close();
|
2018-11-15 23:07:40 -05:00
|
|
|
p.close();
|
|
|
|
});
|
2020-06-25 12:38:19 -04:00
|
|
|
unitTest({ perms: { run: true } }, async function runStdinRid0(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
|
|
|
const p = Deno.run({
|
|
|
|
cmd: ["python", "-c", "print('hello world')"],
|
|
|
|
stdin: 0,
|
|
|
|
stdout: "piped",
|
|
|
|
stderr: "null",
|
|
|
|
});
|
|
|
|
const status = await p.status();
|
|
|
|
assertEquals(status.success, true);
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
assertEquals(status.signal, undefined);
|
|
|
|
p.stdout.close();
|
|
|
|
p.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest({ perms: { run: true } }, function runInvalidStdio(): void {
|
|
|
|
assertThrows(() =>
|
|
|
|
Deno.run({
|
|
|
|
cmd: ["python", "-c", "print('hello world')"],
|
|
|
|
// @ts-expect-error because Deno.run should throw on invalid stdin.
|
|
|
|
stdin: "a",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
assertThrows(() =>
|
|
|
|
Deno.run({
|
|
|
|
cmd: ["python", "-c", "print('hello world')"],
|
|
|
|
// @ts-expect-error because Deno.run should throw on invalid stdout.
|
|
|
|
stdout: "b",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
assertThrows(() =>
|
|
|
|
Deno.run({
|
|
|
|
cmd: ["python", "-c", "print('hello world')"],
|
|
|
|
// @ts-expect-error because Deno.run should throw on invalid stderr.
|
|
|
|
stderr: "c",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { run: true } },
|
|
|
|
async function runCommandFailedWithCode(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-28 13:03:49 -04:00
|
|
|
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"],
|
2020-03-04 11:31:14 -05:00
|
|
|
});
|
|
|
|
const status = await p.status();
|
|
|
|
assertEquals(status.success, false);
|
|
|
|
assertEquals(status.code, 42);
|
|
|
|
assertEquals(status.signal, undefined);
|
|
|
|
p.close();
|
|
|
|
}
|
|
|
|
);
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{
|
|
|
|
// No signals on windows.
|
2020-04-28 12:35:23 -04:00
|
|
|
ignore: Deno.build.os === "windows",
|
2020-03-28 13:03:49 -04:00
|
|
|
perms: { run: true },
|
2020-03-04 11:31:14 -05:00
|
|
|
},
|
|
|
|
async function runCommandFailedWithSignal(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-28 13:03:49 -04:00
|
|
|
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"],
|
2020-03-04 11:31:14 -05:00
|
|
|
});
|
|
|
|
const status = await p.status();
|
|
|
|
assertEquals(status.success, false);
|
2020-06-10 11:10:08 -04:00
|
|
|
assertEquals(status.code, 128 + 9);
|
2020-03-04 11:31:14 -05:00
|
|
|
assertEquals(status.signal, 9);
|
|
|
|
p.close();
|
2018-11-15 23:07:40 -05:00
|
|
|
}
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, function runNotFound(): void {
|
2018-11-15 23:07:40 -05:00
|
|
|
let error;
|
|
|
|
try {
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.run({ cmd: ["this file hopefully doesn't exist"] });
|
2018-11-15 23:07:40 -05:00
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
assert(error !== undefined);
|
2020-02-24 15:48:35 -05:00
|
|
|
assert(error instanceof Deno.errors.NotFound);
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, run: true } },
|
2019-04-21 16:40:10 -04:00
|
|
|
async function runWithCwdIsAsync(): Promise<void> {
|
|
|
|
const enc = new TextEncoder();
|
2020-06-12 15:23:38 -04:00
|
|
|
const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
const exitCodeFile = "deno_was_here";
|
|
|
|
const pyProgramFile = "poll_exit.py";
|
|
|
|
const pyProgram = `
|
2018-11-15 23:07:40 -05:00
|
|
|
from sys import exit
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
with open("${exitCodeFile}", "r") as f:
|
|
|
|
line = f.readline()
|
|
|
|
code = int(line)
|
|
|
|
exit(code)
|
|
|
|
except IOError:
|
|
|
|
# Retry if we got here before deno wrote the file.
|
|
|
|
sleep(0.01)
|
|
|
|
pass
|
|
|
|
`;
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
|
|
|
|
const p = Deno.run({
|
2019-04-21 16:40:10 -04:00
|
|
|
cwd,
|
2020-03-28 13:03:49 -04:00
|
|
|
cmd: ["python", `${pyProgramFile}.py`],
|
2019-04-21 16:40:10 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Write the expected exit code *after* starting python.
|
|
|
|
// This is how we verify that `run()` is actually asynchronous.
|
|
|
|
const code = 84;
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
|
2019-04-21 16:40:10 -04:00
|
|
|
|
|
|
|
const status = await p.status();
|
|
|
|
assertEquals(status.success, false);
|
|
|
|
assertEquals(status.code, code);
|
|
|
|
assertEquals(status.signal, undefined);
|
|
|
|
p.close();
|
|
|
|
}
|
|
|
|
);
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stdin: "piped",
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
2020-02-19 15:36:18 -05:00
|
|
|
assert(p.stdin);
|
2018-11-15 23:07:40 -05:00
|
|
|
assert(!p.stdout);
|
|
|
|
assert(!p.stderr);
|
|
|
|
|
2019-09-07 12:27:18 -04:00
|
|
|
const msg = new TextEncoder().encode("hello");
|
|
|
|
const n = await p.stdin.write(msg);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(n, msg.byteLength);
|
2018-11-15 23:07:40 -05:00
|
|
|
|
2020-06-09 07:18:18 -04:00
|
|
|
p.stdin.close();
|
2018-11-15 23:07:40 -05:00
|
|
|
|
|
|
|
const status = await p.status();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(status.success, true);
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
assertEquals(status.signal, undefined);
|
2018-11-15 23:07:40 -05:00
|
|
|
p.close();
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stdout: "piped",
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
|
|
|
assert(!p.stdin);
|
|
|
|
assert(!p.stderr);
|
|
|
|
|
|
|
|
const data = new Uint8Array(10);
|
2020-06-09 07:18:18 -04:00
|
|
|
let r = await p.stdout.read(data);
|
2020-04-28 12:40:43 -04:00
|
|
|
if (r === null) {
|
|
|
|
throw new Error("p.stdout.read(...) should not be null");
|
2019-07-06 10:16:03 -04:00
|
|
|
}
|
|
|
|
assertEquals(r, 5);
|
|
|
|
const s = new TextDecoder().decode(data.subarray(0, r));
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(s, "hello");
|
2020-06-09 07:18:18 -04:00
|
|
|
r = await p.stdout.read(data);
|
2020-04-28 12:40:43 -04:00
|
|
|
assertEquals(r, null);
|
2020-06-09 07:18:18 -04:00
|
|
|
p.stdout.close();
|
2018-11-15 23:07:40 -05:00
|
|
|
|
|
|
|
const status = await p.status();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(status.success, true);
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
assertEquals(status.signal, undefined);
|
2018-11-15 23:07:40 -05:00
|
|
|
p.close();
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; sys.stderr.write('hello')"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stderr: "piped",
|
2018-11-15 23:07:40 -05:00
|
|
|
});
|
|
|
|
assert(!p.stdin);
|
|
|
|
assert(!p.stdout);
|
|
|
|
|
|
|
|
const data = new Uint8Array(10);
|
2020-06-09 07:18:18 -04:00
|
|
|
let r = await p.stderr.read(data);
|
2020-04-28 12:40:43 -04:00
|
|
|
if (r === null) {
|
|
|
|
throw new Error("p.stderr.read should not return null here");
|
2019-07-06 10:16:03 -04:00
|
|
|
}
|
|
|
|
assertEquals(r, 5);
|
|
|
|
const s = new TextDecoder().decode(data.subarray(0, r));
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(s, "hello");
|
2020-06-09 07:18:18 -04:00
|
|
|
r = await p.stderr.read(data);
|
2020-04-28 12:40:43 -04:00
|
|
|
assertEquals(r, null);
|
2020-02-19 15:36:18 -05:00
|
|
|
p.stderr!.close();
|
2018-11-15 23:07:40 -05:00
|
|
|
|
|
|
|
const status = await p.status();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(status.success, true);
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
assertEquals(status.signal, undefined);
|
2018-11-15 23:07:40 -05:00
|
|
|
p.close();
|
|
|
|
});
|
2018-11-30 13:44:05 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stdout: "piped",
|
2018-11-30 13:44:05 -05:00
|
|
|
});
|
|
|
|
const output = await p.output();
|
|
|
|
const s = new TextDecoder().decode(output);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(s, "hello");
|
2018-11-30 13:44:05 -05:00
|
|
|
p.close();
|
|
|
|
});
|
2019-02-15 10:37:04 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; sys.stderr.write('error')"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stderr: "piped",
|
2019-03-28 16:09:46 -04:00
|
|
|
});
|
|
|
|
const error = await p.stderrOutput();
|
|
|
|
const s = new TextDecoder().decode(error);
|
|
|
|
assertEquals(s, "error");
|
|
|
|
p.close();
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { run: true, write: true, read: true } },
|
2019-06-21 19:00:14 -04:00
|
|
|
async function runRedirectStdoutStderr(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const tempDir = await Deno.makeTempDir();
|
2019-06-21 19:00:14 -04:00
|
|
|
const fileName = tempDir + "/redirected_stdio.txt";
|
2020-06-12 15:23:38 -04:00
|
|
|
const file = await Deno.open(fileName, {
|
2020-04-24 18:45:55 -04:00
|
|
|
create: true,
|
|
|
|
write: true,
|
|
|
|
});
|
2019-06-21 19:00:14 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: [
|
2019-06-21 19:00:14 -04:00
|
|
|
"python",
|
|
|
|
"-c",
|
2020-03-28 13:03:49 -04:00
|
|
|
"import sys; sys.stderr.write('error\\n'); sys.stdout.write('output\\n');",
|
2019-06-21 19:00:14 -04:00
|
|
|
],
|
|
|
|
stdout: file.rid,
|
2020-03-28 13:03:49 -04:00
|
|
|
stderr: file.rid,
|
2019-06-21 19:00:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
await p.status();
|
|
|
|
p.close();
|
|
|
|
file.close();
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
const fileContents = await Deno.readFile(fileName);
|
2019-06-21 19:00:14 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
const text = decoder.decode(fileContents);
|
|
|
|
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains(text, "error");
|
|
|
|
assertStringContains(text, "output");
|
2019-06-21 19:00:14 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { run: true, write: true, read: true } },
|
2019-06-21 19:00:14 -04:00
|
|
|
async function runRedirectStdin(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const tempDir = await Deno.makeTempDir();
|
2019-06-21 19:00:14 -04:00
|
|
|
const fileName = tempDir + "/redirected_stdio.txt";
|
|
|
|
const encoder = new TextEncoder();
|
2020-06-12 15:23:38 -04:00
|
|
|
await Deno.writeFile(fileName, encoder.encode("hello"));
|
|
|
|
const file = await Deno.open(fileName);
|
2019-06-21 19:00:14 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
|
2020-03-28 13:03:49 -04:00
|
|
|
stdin: file.rid,
|
2019-06-21 19:00:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const status = await p.status();
|
|
|
|
assertEquals(status.code, 0);
|
|
|
|
p.close();
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: [
|
2019-02-15 10:37:04 -05:00
|
|
|
"python",
|
|
|
|
"-c",
|
2020-03-28 13:03:49 -04:00
|
|
|
"import os, sys; sys.stdout.write(os.environ.get('FOO', '') + os.environ.get('BAR', ''))",
|
2019-02-15 10:37:04 -05:00
|
|
|
],
|
|
|
|
env: {
|
|
|
|
FOO: "0123",
|
2020-03-28 13:03:49 -04:00
|
|
|
BAR: "4567",
|
2019-02-15 10:37:04 -05:00
|
|
|
},
|
2020-03-28 13:03:49 -04:00
|
|
|
stdout: "piped",
|
2019-02-15 10:37:04 -05:00
|
|
|
});
|
|
|
|
const output = await p.output();
|
|
|
|
const s = new TextDecoder().decode(output);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(s, "01234567");
|
2019-02-15 10:37:04 -05:00
|
|
|
p.close();
|
|
|
|
});
|
2019-04-21 21:26:56 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-03-21 17:44:18 -04:00
|
|
|
cmd: [
|
2019-04-21 21:26:56 -04:00
|
|
|
"python",
|
|
|
|
"-c",
|
2020-03-28 13:03:49 -04:00
|
|
|
"from time import sleep; import sys; sleep(10000); sys.stderr.write('error')",
|
2019-04-21 21:26:56 -04:00
|
|
|
],
|
2020-03-28 13:03:49 -04:00
|
|
|
stderr: "piped",
|
2019-04-21 21:26:56 -04:00
|
|
|
});
|
|
|
|
assert(!p.stdin);
|
|
|
|
assert(!p.stdout);
|
|
|
|
|
|
|
|
p.close();
|
|
|
|
|
|
|
|
const data = new Uint8Array(10);
|
2020-06-09 07:18:18 -04:00
|
|
|
const r = await p.stderr.read(data);
|
2020-04-28 12:40:43 -04:00
|
|
|
assertEquals(r, null);
|
2020-06-09 07:18:18 -04:00
|
|
|
p.stderr.close();
|
2019-04-21 21:26:56 -04:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function signalNumbers(): void {
|
2020-04-28 12:35:23 -04:00
|
|
|
if (Deno.build.os === "darwin") {
|
2019-04-21 21:26:56 -04:00
|
|
|
assertEquals(Deno.Signal.SIGSTOP, 17);
|
2019-09-09 23:39:42 -04:00
|
|
|
} else if (Deno.build.os === "linux") {
|
2019-04-21 21:26:56 -04:00
|
|
|
assertEquals(Deno.Signal.SIGSTOP, 19);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-17 13:11:24 -04:00
|
|
|
unitTest(function killPermissions(): void {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-05-17 13:11:24 -04:00
|
|
|
// Unlike the other test cases, we don't have permission to spawn a
|
|
|
|
// 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.
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.kill(Deno.pid, Deno.Signal.SIGCONT);
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2020-05-17 13:11:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-05-17 13:11:24 -04:00
|
|
|
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
|
2019-08-06 01:45:36 -04:00
|
|
|
});
|
|
|
|
|
2020-05-17 13:11:24 -04:00
|
|
|
assertEquals(Deno.Signal.SIGINT, 2);
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.kill(p.pid, Deno.Signal.SIGINT);
|
2020-05-17 13:11:24 -04:00
|
|
|
const status = await p.status();
|
2019-04-21 21:26:56 -04:00
|
|
|
|
2020-05-17 13:11:24 -04:00
|
|
|
assertEquals(status.success, false);
|
2020-06-10 11:10:08 -04:00
|
|
|
try {
|
|
|
|
assertEquals(status.code, 128 + Deno.Signal.SIGINT);
|
|
|
|
assertEquals(status.signal, Deno.Signal.SIGINT);
|
|
|
|
} catch {
|
|
|
|
// TODO(nayeemrmn): On Windows sometimes the following values are given
|
|
|
|
// instead. Investigate and remove this catch when fixed.
|
|
|
|
assertEquals(status.code, 1);
|
|
|
|
assertEquals(status.signal, undefined);
|
|
|
|
}
|
2020-05-17 13:11:24 -04:00
|
|
|
p.close();
|
|
|
|
});
|
2019-04-21 21:26:56 -04:00
|
|
|
|
2020-05-17 13:11:24 -04:00
|
|
|
unitTest({ perms: { run: true } }, function killFailed(): void {
|
2020-06-12 15:23:38 -04:00
|
|
|
const p = Deno.run({
|
2020-05-17 13:11:24 -04:00
|
|
|
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
|
2019-04-21 21:26:56 -04:00
|
|
|
});
|
2020-05-17 13:11:24 -04:00
|
|
|
assert(!p.stdin);
|
|
|
|
assert(!p.stdout);
|
2019-04-21 21:26:56 -04:00
|
|
|
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.kill(p.pid, 12345);
|
2020-06-24 18:57:08 -04:00
|
|
|
}, TypeError);
|
2019-04-21 21:26:56 -04:00
|
|
|
|
2020-05-17 13:11:24 -04:00
|
|
|
p.close();
|
|
|
|
});
|