From 8394dc311d9002d98193a7fb2cf3e5eef74bc9a7 Mon Sep 17 00:00:00 2001 From: mmews Date: Thu, 1 Feb 2024 17:15:49 +0100 Subject: [PATCH] several refactorings --- .../runner/node/NodeTestRunner.n4js | 6 ++-- .../src/n4js/n4js/lang/N4Injector.n4js | 2 +- .../n4js/mangelhaft/types/ResultGroup.n4js | 1 + .../n4js/mangelhaft/types/ResultGroups.n4js | 29 ++++++++++++------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/n4js-libs/packages/n4js-mangelhaft-cli/src/n4js/org/eclipse/n4js/mangelhaft/runner/node/NodeTestRunner.n4js b/n4js-libs/packages/n4js-mangelhaft-cli/src/n4js/org/eclipse/n4js/mangelhaft/runner/node/NodeTestRunner.n4js index 10634ceb8f..9e47761e90 100644 --- a/n4js-libs/packages/n4js-mangelhaft-cli/src/n4js/org/eclipse/n4js/mangelhaft/runner/node/NodeTestRunner.n4js +++ b/n4js-libs/packages/n4js-mangelhaft-cli/src/n4js/org/eclipse/n4js/mangelhaft/runner/node/NodeTestRunner.n4js @@ -13,7 +13,6 @@ import * as lib_fs from "fs"; import {Module} from "module"; import * as lib_glob from "glob"; import * as lib_path from "path"; -import * as lib_url from "url"; import cli_color_+ from "cli-color"; import * as lib_coverage+ from "istanbul-lib-coverage"; import {NodeTestCLI} from "org/eclipse/n4js/mangelhaft/runner/node/NodeTestCLI"; @@ -37,7 +36,6 @@ import {XUnitReporter} from "org/eclipse/n4js/mangelhaft/reporter/xunit/XUnitRep const DEFAULT_TEST_CATALOG_NAME = "test-catalog.json"; -const GLOB_PREFIX = "glob:"; export public class NodeTestRunner { @@ -116,7 +114,9 @@ export public class NodeTestRunner { const failed = (concatResultGroups.failures !== 0) || (concatResultGroups.errors !== 0); if (failed) { - log(`${fail("Test run failed.")} To rerun just the failing tests use the command: \n n4js-mangelhaft ${this.consoleReporter.unsuccessfulTests.map(test => `\\\n -f ${test}`).join(" ")}`); + const optionCmdLine = NodeTestCLI.toCommandLine(options); + const failedTests = this.consoleReporter.unsuccessfulTests.map(test => `\\\n -f ${test}`).join(" "); + log(`${fail("Test run failed.")} To rerun the failing tests only, execute: \n n4js-mangelhaft ${optionCmdLine} ${failedTests}`); } const nycCoveragePath = options.nycCoveragePath; diff --git a/n4js-libs/packages/n4js-runtime/src/n4js/n4js/lang/N4Injector.n4js b/n4js-libs/packages/n4js-runtime/src/n4js/n4js/lang/N4Injector.n4js index ca7cd62c90..1949a5bd7d 100644 --- a/n4js-libs/packages/n4js-runtime/src/n4js/n4js/lang/N4Injector.n4js +++ b/n4js-libs/packages/n4js-runtime/src/n4js/n4js/lang/N4Injector.n4js @@ -482,7 +482,7 @@ export public class N4Injector{ if(!meta.typeVar){ throw new DIConfigurationError('Cannot create provider ' + meta.type + " typelet is " + meta.typeVar); } - return this.createAnonymousProvider(meta.typeVar) as N4Object; + return this.createAnonymousProvider(meta.typeVar); } return this.internalCreate(meta.type, delegate, cachedInstances); } diff --git a/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroup.n4js b/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroup.n4js index 828e45b689..c01b738042 100644 --- a/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroup.n4js +++ b/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroup.n4js @@ -11,6 +11,7 @@ import {TestResult} from "org/eclipse/n4js/mangelhaft/types/TestResult"; import {TestStatus} from "org/eclipse/n4js/mangelhaft/types/TestStatus"; + export public class ResultGroup { public description?: string = ""; public testResults?: TestResult[] = []; diff --git a/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroups.n4js b/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroups.n4js index 8bb7138188..4c3151b5a5 100644 --- a/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroups.n4js +++ b/n4js-libs/packages/org.eclipse.n4js.mangelhaft/src/n4js/org/eclipse/n4js/mangelhaft/types/ResultGroups.n4js @@ -15,6 +15,7 @@ import {ResultGroup} from "org/eclipse/n4js/mangelhaft/types/ResultGroup"; import {TestResult} from "org/eclipse/n4js/mangelhaft/types/TestResult"; import {aggregateTestStatuses} from "org/eclipse/n4js/mangelhaft/types/TestStatus"; + export public class ResultGroups { public results: ResultGroup[]; public successes: number = 0; @@ -24,7 +25,7 @@ export public class ResultGroups { public constructor(results: ResultGroup[]) { this.results = results; - ResultGroups.accumulateResults(this, results); + this.accumulateResults(results); } /** * Aggregates ResultGroups into a single ResultGroup. tests with the same name are collapsed with @@ -51,17 +52,14 @@ export public class ResultGroups { result = new ResultGroup(Array.from(trMap.values()), description); return result; } - private static accumulateResults(target:ResultGroups, results:(? extends ~~ResultGroup)[]): ResultGroups { + + private accumulateResults(results: ResultGroup[]): void { for (let result of results) { - target.successes += result.successes; - target.failures += result.failures; - target.errors += result.errors; - target.skipped += result.skipped; - if (result instanceof ResultGroups) { - target.results = target.results.concat(result.results); // joe TODO consider refactoring of ResultGroup and ResultGroups - } + this.successes += result.successes; + this.failures += result.failures; + this.errors += result.errors; + this.skipped += result.skipped; } - return target; } /** @@ -72,10 +70,19 @@ export public class ResultGroups { public static concat(...resultGroups: ResultGroups): ResultGroups { return this.concatArray(resultGroups); } + /** * same as concat but takes a whole array */ public static concatArray(resultGroupss: ResultGroups[]): ResultGroups { - return this.accumulateResults(new ResultGroups([]), (resultGroupss as Object) as (? extends ~~ResultGroup)[]); // joe TODO consider refactoring of ResultGroup and ResultGroups + const newResultGroups = new ResultGroups([]); + for (let resultGroup of resultGroupss) { + newResultGroups.successes += resultGroup.successes; + newResultGroups.failures += resultGroup.failures; + newResultGroups.errors += resultGroup.errors; + newResultGroups.skipped += resultGroup.skipped; + newResultGroups.results = newResultGroups.results.concat(resultGroup.results); + } + return newResultGroups; } }