2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2020-03-13 15:57:32 +01:00
|
|
|
|
2021-02-02 19:05:46 +08:00
|
|
|
import * as colors from "../../../test_util/std/fmt/colors.ts";
|
2020-06-12 16:58:04 +01:00
|
|
|
export { colors };
|
2021-02-02 19:05:46 +08:00
|
|
|
import { resolve } from "../../../test_util/std/path/mod.ts";
|
2019-03-06 20:48:46 -05:00
|
|
|
export {
|
|
|
|
assert,
|
2019-05-17 20:03:01 +02:00
|
|
|
assertEquals,
|
2022-09-28 17:41:12 +05:30
|
|
|
assertFalse,
|
2023-03-22 12:13:24 +08:00
|
|
|
AssertionError,
|
2019-08-27 16:33:39 +01:00
|
|
|
assertMatch,
|
2019-05-17 20:03:01 +02:00
|
|
|
assertNotEquals,
|
2023-01-29 23:15:01 +09:00
|
|
|
assertNotStrictEquals,
|
2021-09-05 21:43:46 +01:00
|
|
|
assertRejects,
|
2020-06-06 11:43:00 +08:00
|
|
|
assertStrictEquals,
|
2020-10-26 16:03:30 +01:00
|
|
|
assertStringIncludes,
|
2020-09-27 06:22:32 -04:00
|
|
|
assertThrows,
|
2020-03-29 04:03:49 +11:00
|
|
|
fail,
|
2021-02-22 04:26:17 -08:00
|
|
|
unimplemented,
|
2020-09-27 06:22:32 -04:00
|
|
|
unreachable,
|
2021-02-02 19:05:46 +08:00
|
|
|
} from "../../../test_util/std/testing/asserts.ts";
|
|
|
|
export { deferred } from "../../../test_util/std/async/deferred.ts";
|
2021-04-12 00:40:42 +01:00
|
|
|
export type { Deferred } from "../../../test_util/std/async/deferred.ts";
|
2021-06-25 10:44:14 +09:00
|
|
|
export { delay } from "../../../test_util/std/async/delay.ts";
|
2023-01-16 07:09:26 +11:00
|
|
|
export { readLines } from "../../../test_util/std/io/read_lines.ts";
|
2021-02-02 19:05:46 +08:00
|
|
|
export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts";
|
2018-08-23 19:47:43 -04:00
|
|
|
|
2020-06-12 02:36:20 +10:00
|
|
|
export function pathToAbsoluteFileUrl(path: string): URL {
|
|
|
|
path = resolve(path);
|
|
|
|
|
|
|
|
return new URL(`file://${Deno.build.os === "windows" ? "/" : ""}${path}`);
|
|
|
|
}
|
2022-03-12 01:18:49 +09:00
|
|
|
|
2022-12-02 12:41:52 -05:00
|
|
|
export function execCode(code: string): Promise<readonly [number, string]> {
|
|
|
|
return execCode2(code).finished();
|
|
|
|
}
|
2022-03-12 01:18:49 +09:00
|
|
|
|
2022-12-02 12:41:52 -05:00
|
|
|
export function execCode2(code: string) {
|
|
|
|
const command = new Deno.Command(Deno.execPath(), {
|
2022-05-18 22:00:11 +02:00
|
|
|
args: [
|
2022-03-12 01:18:49 +09:00
|
|
|
"eval",
|
|
|
|
"--unstable",
|
|
|
|
"--no-check",
|
|
|
|
code,
|
|
|
|
],
|
2022-12-02 12:41:52 -05:00
|
|
|
stdout: "piped",
|
|
|
|
stderr: "inherit",
|
|
|
|
});
|
|
|
|
|
|
|
|
const child = command.spawn();
|
|
|
|
const stdout = child.stdout.pipeThrough(new TextDecoderStream()).getReader();
|
|
|
|
let output = "";
|
|
|
|
|
|
|
|
return {
|
|
|
|
async waitStdoutText(text: string) {
|
|
|
|
while (true) {
|
|
|
|
const readData = await stdout.read();
|
|
|
|
if (readData.value) {
|
|
|
|
output += readData.value;
|
|
|
|
if (output.includes(text)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (readData.done) {
|
|
|
|
throw new Error(`Did not find text '${text}' in stdout.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async finished() {
|
|
|
|
while (true) {
|
|
|
|
const readData = await stdout.read();
|
|
|
|
if (readData.value) {
|
|
|
|
output += readData.value;
|
|
|
|
}
|
|
|
|
if (readData.done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const status = await child.status;
|
|
|
|
return [status.code, output] as const;
|
|
|
|
},
|
|
|
|
};
|
2022-03-12 01:18:49 +09:00
|
|
|
}
|