2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-01-27 09:06:18 -05:00
|
|
|
/// FLAGS
|
|
|
|
|
2024-03-04 19:41:16 -05:00
|
|
|
import { parse } from "../../util/std/flags/mod.ts";
|
|
|
|
import { join, resolve, ROOT_PATH } from "../../../tools/util.js";
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
export const {
|
|
|
|
json,
|
2021-06-06 12:08:50 -04:00
|
|
|
wptreport,
|
2021-01-27 09:06:18 -05:00
|
|
|
quiet,
|
|
|
|
release,
|
2021-01-30 13:22:24 -05:00
|
|
|
rebuild,
|
2021-01-27 09:06:18 -05:00
|
|
|
["--"]: rest,
|
|
|
|
["auto-config"]: autoConfig,
|
2022-01-06 05:24:37 -05:00
|
|
|
["inspect-brk"]: inspectBrk,
|
2023-03-02 17:05:17 -05:00
|
|
|
["no-ignore"]: noIgnore,
|
2021-06-14 07:48:57 -04:00
|
|
|
binary,
|
2021-01-27 09:06:18 -05:00
|
|
|
} = parse(Deno.args, {
|
|
|
|
"--": true,
|
2023-03-02 17:05:17 -05:00
|
|
|
boolean: ["quiet", "release", "no-interactive", "inspect-brk", "no-ignore"],
|
2021-06-14 07:48:57 -04:00
|
|
|
string: ["json", "wptreport", "binary"],
|
2021-01-27 09:06:18 -05:00
|
|
|
});
|
|
|
|
|
2021-06-14 07:48:57 -04:00
|
|
|
export function denoBinary() {
|
|
|
|
if (binary) {
|
2021-06-23 11:46:15 -04:00
|
|
|
return resolve(binary);
|
2021-06-14 07:48:57 -04:00
|
|
|
}
|
|
|
|
return join(ROOT_PATH, `./target/${release ? "release" : "debug"}/deno`);
|
|
|
|
}
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
/// WPT TEST MANIFEST
|
|
|
|
|
|
|
|
export interface Manifest {
|
|
|
|
items: {
|
|
|
|
testharness: ManifestFolder;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
export interface ManifestFolder {
|
|
|
|
[key: string]: ManifestFolder | ManifestTest;
|
|
|
|
}
|
|
|
|
export type ManifestTest = [
|
|
|
|
hash: string,
|
|
|
|
...variations: ManifestTestVariation[],
|
|
|
|
];
|
|
|
|
export type ManifestTestVariation = [
|
|
|
|
path: string,
|
|
|
|
options: ManifestTestOptions,
|
|
|
|
];
|
|
|
|
export interface ManifestTestOptions {
|
2021-06-02 19:12:28 -04:00
|
|
|
// deno-lint-ignore camelcase
|
|
|
|
script_metadata: [string, string][];
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
|
2024-03-04 19:41:16 -05:00
|
|
|
const MANIFEST_PATH = join(ROOT_PATH, "./tests/wpt/runner/manifest.json");
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
export async function updateManifest() {
|
2022-05-18 16:00:11 -04:00
|
|
|
const status = await runPy(
|
2021-01-30 13:22:24 -05:00
|
|
|
[
|
|
|
|
"wpt",
|
|
|
|
"manifest",
|
|
|
|
"--tests-root",
|
|
|
|
".",
|
|
|
|
"-p",
|
|
|
|
MANIFEST_PATH,
|
|
|
|
...(rebuild ? ["--rebuild"] : []),
|
|
|
|
],
|
2021-01-27 09:06:18 -05:00
|
|
|
{},
|
2022-05-18 16:00:11 -04:00
|
|
|
).status;
|
2021-01-27 09:06:18 -05:00
|
|
|
assert(status.success, "updating wpt manifest should succeed");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getManifest(): Manifest {
|
|
|
|
const manifestText = Deno.readTextFileSync(MANIFEST_PATH);
|
|
|
|
return JSON.parse(manifestText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// WPT TEST EXPECTATIONS
|
|
|
|
|
2024-03-04 19:41:16 -05:00
|
|
|
const EXPECTATION_PATH = join(ROOT_PATH, "./tests/wpt/runner/expectation.json");
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
export interface Expectation {
|
|
|
|
[key: string]: Expectation | boolean | string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getExpectation(): Expectation {
|
|
|
|
const expectationText = Deno.readTextFileSync(EXPECTATION_PATH);
|
|
|
|
return JSON.parse(expectationText);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveExpectation(expectation: Expectation) {
|
|
|
|
Deno.writeTextFileSync(
|
|
|
|
EXPECTATION_PATH,
|
|
|
|
JSON.stringify(expectation, undefined, " "),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getExpectFailForCase(
|
|
|
|
expectation: boolean | string[],
|
|
|
|
caseName: string,
|
|
|
|
): boolean {
|
2023-03-03 08:50:18 -05:00
|
|
|
if (noIgnore) return false;
|
2021-01-27 09:06:18 -05:00
|
|
|
if (typeof expectation == "boolean") {
|
|
|
|
return !expectation;
|
|
|
|
}
|
|
|
|
return expectation.includes(caseName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// UTILS
|
|
|
|
|
|
|
|
class AssertionError extends Error {
|
|
|
|
name = "AssertionError";
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function assert(condition: unknown, message: string): asserts condition {
|
|
|
|
if (!condition) {
|
|
|
|
throw new AssertionError(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 08:43:17 -05:00
|
|
|
export function runPy<T extends Omit<Deno.CommandOptions, "cwd">>(
|
2021-01-27 09:06:18 -05:00
|
|
|
args: string[],
|
2022-05-18 16:00:11 -04:00
|
|
|
options: T,
|
2022-12-02 08:43:17 -05:00
|
|
|
): Deno.ChildProcess {
|
2021-01-27 09:06:18 -05:00
|
|
|
const cmd = Deno.build.os == "windows" ? "python.exe" : "python3";
|
2022-12-02 08:43:17 -05:00
|
|
|
return new Deno.Command(cmd, {
|
2022-05-18 16:00:11 -04:00
|
|
|
args,
|
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2021-01-27 09:06:18 -05:00
|
|
|
...options,
|
2024-02-15 22:32:28 -05:00
|
|
|
cwd: join(ROOT_PATH, "./tests/wpt/suite/"),
|
2022-12-02 08:43:17 -05:00
|
|
|
}).spawn();
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function checkPy3Available() {
|
2022-07-21 04:45:15 -04:00
|
|
|
const { success, stdout } = await runPy(["--version"], {
|
2022-05-18 16:00:11 -04:00
|
|
|
stdout: "piped",
|
|
|
|
}).output();
|
2022-07-21 04:45:15 -04:00
|
|
|
assert(success, "failed to run python --version");
|
2022-05-18 16:00:11 -04:00
|
|
|
const output = new TextDecoder().decode(stdout);
|
2021-01-27 09:06:18 -05:00
|
|
|
assert(
|
|
|
|
output.includes("Python 3."),
|
|
|
|
`The ${
|
|
|
|
Deno.build.os == "windows" ? "python.exe" : "python3"
|
2021-02-02 22:21:48 -05:00
|
|
|
} in your path is not Python 3.`,
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function cargoBuild() {
|
2021-06-14 14:57:02 -04:00
|
|
|
if (binary) return;
|
2022-12-02 08:43:17 -05:00
|
|
|
const { success } = await new Deno.Command("cargo", {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["build", ...(release ? ["--release"] : [])],
|
2021-01-27 09:06:18 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-05-18 16:00:11 -04:00
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2022-12-02 08:43:17 -05:00
|
|
|
}).output();
|
2022-07-21 04:45:15 -04:00
|
|
|
assert(success, "cargo build failed");
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
2021-06-06 12:08:50 -04:00
|
|
|
|
2021-07-07 13:56:47 -04:00
|
|
|
export function escapeLoneSurrogates(input: string): string;
|
|
|
|
export function escapeLoneSurrogates(input: string | null): string | null;
|
|
|
|
export function escapeLoneSurrogates(input: string | null): string | null {
|
|
|
|
if (input === null) return null;
|
|
|
|
return input.replace(
|
|
|
|
/[\uD800-\uDFFF]/gu,
|
|
|
|
(match) => `U+${match.charCodeAt(0).toString(16)}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-06 12:08:50 -04:00
|
|
|
/// WPTREPORT
|
|
|
|
|
|
|
|
export async function generateRunInfo(): Promise<unknown> {
|
|
|
|
const oses = {
|
|
|
|
"windows": "win",
|
|
|
|
"darwin": "mac",
|
|
|
|
"linux": "linux",
|
2023-06-12 06:14:27 -04:00
|
|
|
"freebsd": "freebsd",
|
|
|
|
"openbsd": "openbsd",
|
2021-06-06 12:08:50 -04:00
|
|
|
};
|
2022-12-02 08:43:17 -05:00
|
|
|
const proc = await new Deno.Command("git", {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["rev-parse", "HEAD"],
|
2024-02-15 22:32:28 -05:00
|
|
|
cwd: join(ROOT_PATH, "tests", "wpt", "suite"),
|
2022-05-18 16:00:11 -04:00
|
|
|
stderr: "inherit",
|
2022-12-02 08:43:17 -05:00
|
|
|
}).output();
|
2022-05-18 16:00:11 -04:00
|
|
|
const revision = (new TextDecoder().decode(proc.stdout)).trim();
|
2022-12-02 08:43:17 -05:00
|
|
|
const proc2 = await new Deno.Command(denoBinary(), {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["eval", "console.log(JSON.stringify(Deno.version))"],
|
2024-02-15 22:32:28 -05:00
|
|
|
cwd: join(ROOT_PATH, "tests", "wpt", "suite"),
|
2022-12-02 08:43:17 -05:00
|
|
|
}).output();
|
2022-05-18 16:00:11 -04:00
|
|
|
const version = JSON.parse(new TextDecoder().decode(proc2.stdout));
|
2021-06-06 12:08:50 -04:00
|
|
|
const runInfo = {
|
|
|
|
"os": oses[Deno.build.os],
|
|
|
|
"processor": Deno.build.arch,
|
|
|
|
"version": "unknown",
|
|
|
|
"os_version": "unknown",
|
|
|
|
"bits": 64,
|
|
|
|
"has_sandbox": true,
|
|
|
|
"webrender": false,
|
|
|
|
"automation": false,
|
|
|
|
"linux_distro": "unknown",
|
|
|
|
"revision": revision,
|
|
|
|
"python_version": 3,
|
|
|
|
"product": "deno",
|
|
|
|
"debug": false,
|
|
|
|
"browser_version": version.deno,
|
|
|
|
"browser_channel": version.deno.includes("+") ? "canary" : "stable",
|
|
|
|
"verify": false,
|
|
|
|
"wasm": false,
|
|
|
|
"headless": true,
|
|
|
|
};
|
|
|
|
return runInfo;
|
|
|
|
}
|