From 0ab298dd34c951ae0d07eb708ef88db98067cbdb Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 23 Nov 2017 20:02:20 +0200 Subject: [PATCH] Change `failedTests` to live on the `testList`. Since tests themselves already keep track of their failure, and the test list (i.e. the `TestList` class) tracks other concepts of grouped tests, such as "all tests", "filtered tests", etc. (like a `TestList` class would!) I believe it makes sense for it to also maintain a collection of "failed tests"... (in list form, of course!) This will allow the `Run.runTest` logic to move into `run.js` file without needing to pass back a separate `failed` variable in the event of a failure, since that is already being tracked through the `notifyFailed` facility. --- tools/tool-testing/selftest.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/tool-testing/selftest.js b/tools/tool-testing/selftest.js index 513482da1a..0775b390c3 100644 --- a/tools/tool-testing/selftest.js +++ b/tools/tool-testing/selftest.js @@ -291,6 +291,7 @@ class TestList { tagsToSkip = (tagsToSkip || []); testState = (testState || null); // optional this.allTests = allTests; + this.failedTests = []; this.skippedTags = tagsToSkip; this.skipCounts = {}; this.testState = testState; @@ -341,6 +342,8 @@ class TestList { // Mark the file that this test lives in as having failures. this.fileInfo[test.file].hasFailures = true; + this.failedTests.push(test); + // Mark that the specific test failed. test.failed = true; @@ -561,7 +564,6 @@ export function runTests(options) { testList.startTime = new Date; let totalRun = 0; - const failedTests = []; const totalTries = (options.retries || 0) + 1; @@ -658,7 +660,6 @@ export function runTests(options) { Console.rawError(" => Test threw exception: " + failure.stack + "\n"); } - failedTests.push(test); testList.notifyFailed(test, failure); } else { Console.error( @@ -679,21 +680,22 @@ export function runTests(options) { Console.error(testList.generateSkipReport()); - if (testList.filteredTests.length === 0) { + const failureCount = testList.failedTests.length; + + if (!totalRun) { Console.error("No tests run."); return 0; - } else if (failedTests.length === 0) { + } else if (!failureCount) { let disclaimers = ''; - if (testList.filteredTests.length < testList.allTests.length) { + if (totalRun < testList.allTests.length) { disclaimers += " other"; } Console.error("All" + disclaimers + " tests passed."); return 0; } else { - const failureCount = failedTests.length; Console.error(failureCount + " failure" + (failureCount > 1 ? "s" : "") + ":"); - failedTests.forEach((test) => { + testList.failedTests.forEach((test) => { Console.rawError(" - " + test.file + ": " + test.name + "\n"); }); return 1;