Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print out the failed tests after the summary #554

Merged
merged 6 commits into from
Aug 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 33 additions & 2 deletions testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function test(t: TestDefinition | TestFunction): void {

const RED_FAILED = red("FAILED");
const GREEN_OK = green("OK");
const RED_BG_FAIL = bgRed(" FAIL ");

interface TestStats {
filtered: number;
Expand Down Expand Up @@ -165,6 +166,17 @@ function report(result: TestResult): void {
result.printed = true;
}

function printFailedSummary(results: TestResults): void {
results.cases.forEach(
(v): void => {
if (!v.ok) {
console.error(`${RED_BG_FAIL} ${red(v.name)}`);
console.error(v.error);
}
}
);
}

function printResults(
stats: TestStats,
results: TestResults,
Expand All @@ -184,7 +196,7 @@ function printResults(
}
// Attempting to match the output of Rust's test runner.
print(
`\ntest result: ${stats.failed ? RED_FAILED : GREEN_OK}. ` +
`\ntest result: ${stats.failed ? RED_BG_FAIL : GREEN_OK} ` +
`${stats.passed} passed; ${stats.failed} failed; ` +
`${stats.ignored} ignored; ${stats.measured} measured; ` +
`${stats.filtered} filtered out ` +
Expand Down Expand Up @@ -251,6 +263,7 @@ async function runTestsParallel(

async function runTestsSerial(
stats: TestStats,
results: TestResults,
tests: TestDefinition[],
exitOnFail: boolean,
disableLog: boolean
Expand All @@ -273,13 +286,30 @@ async function runTestsSerial(
print(
GREEN_OK + " " + name + " " + promptTestTime(end - start, true)
);
results.cases.forEach(
(v): void => {
if (v.name === name) {
v.ok = true;
v.printed = true;
}
}
);
} catch (err) {
if (disableLog) {
print(CLEAR_LINE, false);
}
print(`${RED_FAILED} ${name}`);
print(err.stack);
stats.failed++;
results.cases.forEach(
(v): void => {
if (v.name === name) {
v.error = err;
v.ok = false;
v.printed = true;
}
}
);
if (exitOnFail) {
break;
}
Expand Down Expand Up @@ -329,7 +359,7 @@ export async function runTests({
if (parallel) {
await runTestsParallel(stats, results, tests, exitOnFail);
} else {
await runTestsSerial(stats, tests, exitOnFail, disableLog);
await runTestsSerial(stats, results, tests, exitOnFail, disableLog);
}
const end = performance.now();
if (disableLog) {
Expand All @@ -341,6 +371,7 @@ export async function runTests({
// promise rejections being swallowed.
setTimeout((): void => {
console.error(`There were ${stats.failed} test failures.`);
printFailedSummary(results);
Deno.exit(1);
}, 0);
}
Expand Down