Add summary reporting for failed tests

This commit is contained in:
Radon Rosborough 2020-07-30 12:00:52 -06:00
parent 510cc1e0c0
commit f93a7e2aed
1 changed files with 53 additions and 36 deletions

View File

@ -128,11 +128,11 @@ class Test {
} }
}; };
wait = async <T>(handler: (msg: any) => T) => { wait = async <T>(desc: string, handler: (msg: any) => T) => {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
this.handleUpdate = () => { this.handleUpdate = () => {
if (this.timedOut) { if (this.timedOut) {
reject("timeout"); reject(`timeout while waiting for ${desc}`);
} else { } else {
while (this.handledMessages < this.messages.length) { while (this.handledMessages < this.messages.length) {
const msg = this.messages[this.handledMessages]; const msg = this.messages[this.handledMessages];
@ -150,7 +150,7 @@ class Test {
waitForOutput = async (pattern: string) => { waitForOutput = async (pattern: string) => {
let output = ""; let output = "";
return await this.wait((msg: any) => { return await this.wait(`output ${JSON.stringify(pattern)}`, (msg: any) => {
const prevLength = output.length; const prevLength = output.length;
if (msg.event === "terminalOutput") { if (msg.event === "terminalOutput") {
output += msg.output; output += msg.output;
@ -161,7 +161,7 @@ class Test {
testEnsure = async () => { testEnsure = async () => {
this.send({ event: "ensure" }); this.send({ event: "ensure" });
const code = await this.wait((msg: any) => { const code = await this.wait("ensure response", (msg: any) => {
if (msg.event === "ensured") { if (msg.event === "ensured") {
return msg.code; return msg.code;
} }
@ -210,7 +210,7 @@ class Test {
const input = this.config.format!.input; const input = this.config.format!.input;
const output = this.config.format!.output || this.config.template; const output = this.config.format!.output || this.config.template;
this.send({ event: "formatCode", code: input }); this.send({ event: "formatCode", code: input });
const result = await this.wait((msg: any) => { const result = await this.wait("formatter response", (msg: any) => {
if (msg.event === "formattedCode") { if (msg.event === "formattedCode") {
return msg.code; return msg.code;
} }
@ -230,7 +230,7 @@ class Test {
this.config.template.slice(0, idx) + this.config.template.slice(0, idx) +
insertedCode + insertedCode +
this.config.template.slice(idx); this.config.template.slice(idx);
const root = await this.wait((msg: any) => { const root = await this.wait("lspStarted message", (msg: any) => {
if (msg.event === "lspStarted") { if (msg.event === "lspStarted") {
return msg.root; return msg.root;
} }
@ -441,7 +441,7 @@ class Test {
}, },
}, },
}); });
await this.wait((msg: any) => { await this.wait("response to lsp initialize", (msg: any) => {
return ( return (
msg.event === "lspOutput" && msg.event === "lspOutput" &&
msg.output.id === "0d75333a-47d8-4da8-8030-c81d7bd9eed7" msg.output.id === "0d75333a-47d8-4da8-8030-c81d7bd9eed7"
@ -482,7 +482,9 @@ class Test {
}, },
}, },
}); });
const items: any = await this.wait((msg: any) => { const items: any = await this.wait(
"response to lsp completion request",
(msg: any) => {
if (msg.event === "lspOutput") { if (msg.event === "lspOutput") {
if (msg.output.method === "workspace/configuration") { if (msg.output.method === "workspace/configuration") {
this.send({ this.send({
@ -501,7 +503,8 @@ class Test {
return msg.output.result.items; return msg.output.result.items;
} }
} }
}); }
);
if ( if (
!(items && items.filter(({ label }: any) => label === item).length > 0) !(items && items.filter(({ label }: any) => label === item).length > 0)
) { ) {
@ -550,11 +553,11 @@ const testTypes: {
}; };
function getTestList() { function getTestList() {
const tests: { lang: string; test: string }[] = []; const tests: { lang: string; type: string }[] = [];
for (const [id, cfg] of Object.entries(langs)) { for (const [id, cfg] of Object.entries(langs)) {
for (const [test, { pred }] of Object.entries(testTypes)) { for (const [type, { pred }] of Object.entries(testTypes)) {
if (pred(cfg)) { if (pred(cfg)) {
tests.push({ lang: id, test }); tests.push({ lang: id, type });
} }
} }
} }
@ -571,11 +574,11 @@ async function main() {
const args = process.argv.slice(2); const args = process.argv.slice(2);
for (const arg of args) { for (const arg of args) {
tests = tests.filter( tests = tests.filter(
({ lang, test }) => ({ lang, type }) =>
arg arg
.split(",") .split(",")
.filter((arg) => .filter((arg) =>
[lang, test].concat(langs[lang].aliases || []).includes(arg) [lang, type].concat(langs[lang].aliases || []).includes(arg)
).length > 0 ).length > 0
); );
} }
@ -610,9 +613,9 @@ async function main() {
} }
await promisify(rimraf)("tests"); await promisify(rimraf)("tests");
const queue = new PQueue({ concurrency: CONCURRENCY }); const queue = new PQueue({ concurrency: CONCURRENCY });
let passed = 0; let passed = new Set();
let failed = 0; let failed = new Map();
for (const { lang, test: type } of tests) { for (const { lang, type } of tests) {
let test: Test; let test: Test;
queue queue
.add(() => { .add(() => {
@ -620,7 +623,7 @@ async function main() {
return test.run(); return test.run();
}) })
.then(async () => { .then(async () => {
passed += 1; passed.add({ lang, type });
console.error(`PASSED: ${lang}/${type}`); console.error(`PASSED: ${lang}/${type}`);
await writeLog( await writeLog(
lang, lang,
@ -629,7 +632,7 @@ async function main() {
); );
}) })
.catch(async (err) => { .catch(async (err) => {
failed += 1; failed.set({ lang, type }, err);
console.error(`FAILED: ${lang}/${type}`); console.error(`FAILED: ${lang}/${type}`);
console.error(test.getLog()); console.error(test.getLog());
console.error(err); console.error(err);
@ -646,7 +649,21 @@ async function main() {
.catch(console.error); .catch(console.error);
} }
await queue.onIdle(); await queue.onIdle();
process.exit(failed ? 1 : 0); console.error();
console.error(
"================================================================================"
);
console.error();
if (passed.size > 0) {
console.error(`${passed.size} test${passed.size !== 1 ? "s" : ""} PASSED`);
}
if (failed.size > 0) {
console.error(`${failed.size} test${failed.size !== 1 ? "s" : ""} FAILED`);
Array.from(failed).forEach(([{ lang, type }, err]) =>
console.error(` - ${lang}/${type} (${err})`)
);
}
process.exit(failed.size > 0 ? 1 : 0);
} }
main().catch(console.error); main().catch(console.error);