Skip to content

Commit

Permalink
several refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Feb 1, 2024
1 parent b1ee5af commit 8394dc3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}

0 comments on commit 8394dc3

Please sign in to comment.