2019-07-31 07:13:05 -04:00
|
|
|
#!/usr/bin/env -S deno run --reload --allow-run
|
2019-05-08 19:15:24 -04:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import "./unit_tests.ts";
|
|
|
|
import { permissionCombinations, parseUnitTestOutput } from "./test_util.ts";
|
|
|
|
|
2019-06-01 11:13:36 -04:00
|
|
|
interface TestResult {
|
|
|
|
perms: string;
|
|
|
|
output: string;
|
|
|
|
result: number;
|
|
|
|
}
|
|
|
|
|
2019-05-08 19:15:24 -04:00
|
|
|
function permsToCliFlags(perms: Deno.Permissions): string[] {
|
|
|
|
return Object.keys(perms)
|
|
|
|
.map(
|
|
|
|
(key): string => {
|
|
|
|
if (!perms[key]) return "";
|
|
|
|
|
|
|
|
const cliFlag = key.replace(
|
|
|
|
/\.?([A-Z])/g,
|
|
|
|
(x, y): string => `-${y.toLowerCase()}`
|
|
|
|
);
|
|
|
|
return `--allow-${cliFlag}`;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.filter((e): boolean => e.length > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fmtPerms(perms: Deno.Permissions): string {
|
|
|
|
let fmt = permsToCliFlags(perms).join(" ");
|
|
|
|
|
|
|
|
if (!fmt) {
|
|
|
|
fmt = "<no permissions>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
|
console.log(
|
|
|
|
"Discovered permission combinations for tests:",
|
|
|
|
permissionCombinations.size
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const perms of permissionCombinations.values()) {
|
|
|
|
console.log("\t" + fmtPerms(perms));
|
|
|
|
}
|
|
|
|
|
2019-06-01 11:13:36 -04:00
|
|
|
const testResults = new Set<TestResult>();
|
2019-05-08 19:15:24 -04:00
|
|
|
|
|
|
|
for (const perms of permissionCombinations.values()) {
|
|
|
|
const permsFmt = fmtPerms(perms);
|
|
|
|
console.log(`Running tests for: ${permsFmt}`);
|
|
|
|
const cliPerms = permsToCliFlags(perms);
|
|
|
|
// run subsequent tests using same deno executable
|
|
|
|
const args = [
|
2019-08-06 17:05:47 -04:00
|
|
|
Deno.execPath(),
|
2019-05-08 19:15:24 -04:00
|
|
|
"run",
|
|
|
|
"--no-prompt",
|
|
|
|
...cliPerms,
|
|
|
|
"js/unit_tests.ts"
|
|
|
|
];
|
|
|
|
|
|
|
|
const p = Deno.run({
|
|
|
|
args,
|
|
|
|
stdout: "piped"
|
|
|
|
});
|
|
|
|
|
|
|
|
const { actual, expected, resultOutput } = parseUnitTestOutput(
|
|
|
|
await p.output(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
let result = 0;
|
|
|
|
|
|
|
|
if (!actual && !expected) {
|
|
|
|
console.error("Bad js/unit_test.ts output");
|
|
|
|
result = 1;
|
|
|
|
} else if (expected !== actual) {
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
testResults.add({
|
|
|
|
perms: permsFmt,
|
|
|
|
output: resultOutput,
|
|
|
|
result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// if any run tests returned non-zero status then whole test
|
|
|
|
// run should fail
|
|
|
|
let testsFailed = false;
|
|
|
|
|
2019-06-01 11:13:36 -04:00
|
|
|
for (const testResult of testResults) {
|
2019-05-08 19:15:24 -04:00
|
|
|
console.log(`Summary for ${testResult.perms}`);
|
|
|
|
console.log(testResult.output + "\n");
|
2019-06-01 11:13:36 -04:00
|
|
|
testsFailed = testsFailed || Boolean(testResult.result);
|
2019-05-08 19:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (testsFailed) {
|
|
|
|
console.error("Unit tests failed");
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Unit tests passed");
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|