Skip to content

Commit

Permalink
Merge pull request #68 from matepek/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
matepek authored Mar 1, 2019
2 parents f783242 + b86b21a commit eaf4f1d
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 104 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.22]

### Changed

- the test list parser timeout from 5 to 30 seconds.

### Added

- section picker for debugging.

### Fixed

- a bug related to env variables in case of debugging.

## [2.3.21] - 2019-02-26

### Added

- `testExplorer.sort`, so I removed my logic. If you want the old ordering set this to `byLabelWithSuitesFirst`.
- tooltip: it will show more info about the suites and tests
- tooltip: it will show more info about the suites and tests.

## [2.3.20] - 2019-02-22

Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"@typescript-eslint/parser": "^1.4.2",
"deep-equal": "^1.0.1",
"eslint": "^5.14.1",
"eslint-config-prettier": "^4.0.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"fs-extra": "^7.0.1",
"mocha-eslint": "^5.0.0",
"prettier": "^1.16.4",
"request-promise": "4.2.2",
"sinon": "^7.2.4",
"sinon": "^7.2.5",
"typescript": "^3.3.3333",
"vsce": "^1.57.1",
"vscode": "^1.1.30"
Expand Down
135 changes: 111 additions & 24 deletions src/Catch2TestInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ interface XmlObject {
[prop: string]: any; //eslint-disable-line
}

export class Catch2Section {
public constructor(name: string, filename: string, line: number) {
this.name = name;
this.filename = filename;
this.line = line;
}

public readonly name: string;
public readonly filename: string;
public readonly line: number;
public readonly children: Catch2Section[] = [];
public failed: boolean = false;
}

export class Catch2TestInfo extends AbstractTestInfo {
public constructor(
shared: SharedVariables,
Expand All @@ -27,6 +41,7 @@ export class Catch2TestInfo extends AbstractTestInfo {
line: number,
execPath: string,
execOptions: SpawnOptions,
sections?: Catch2Section[],
) {
super(
shared,
Expand All @@ -41,6 +56,13 @@ export class Catch2TestInfo extends AbstractTestInfo {
execPath,
execOptions,
);
this._sections = sections;
}

private _sections: undefined | Catch2Section[];

public get sections(): undefined | Catch2Section[] {
return this._sections;
}

public getEscapedTestName(): string {
Expand Down Expand Up @@ -89,19 +111,21 @@ export class Catch2TestInfo extends AbstractTestInfo {
}

private _processXmlTagTestCaseInner(testCase: XmlObject, testEvent: TestEvent): void {
const title = '⬇️⬇️⬇️ "' + testCase.$.name + '" at line ' + testCase.$.line;
const title: Catch2Section = new Catch2Section(testCase.$.name, testCase.$.filename, testCase.$.line);

if (testCase.OverallResult[0].$.hasOwnProperty('durationInSeconds')) {
testEvent.message += '⏱ Duration: ' + testCase.OverallResult[0].$.durationInSeconds + ' second(s).\n';
}

this._processInfoWarningAndFailureTags(testCase, title, testEvent);
this._processInfoWarningAndFailureTags(testCase, title, [], testEvent);

this._processXmlTagExpressions(testCase, title, [], testEvent);

this._processXmlTagExpressions(testCase, title, testEvent);
this._processXmlTagSections(testCase, title, [], testEvent, title);

this._processXmlTagSections(testCase, title, testEvent);
this._sections = title.children;

this._processXmlTagFatalErrorConditions(testCase, title, testEvent);
this._processXmlTagFatalErrorConditions(testCase, title, [], testEvent);

if (testCase.OverallResult[0].hasOwnProperty('StdOut')) {
testEvent.message += '⬇️⬇️⬇️ std::cout:';
Expand All @@ -126,7 +150,12 @@ export class Catch2TestInfo extends AbstractTestInfo {
}
}

private _processInfoWarningAndFailureTags(xml: XmlObject, title: string, testEvent: TestEvent): void {
private _processInfoWarningAndFailureTags(
xml: XmlObject,
title: Catch2Section,
stack: Catch2Section[],
testEvent: TestEvent,
): void {
if (xml.hasOwnProperty('Info')) {
for (let j = 0; j < xml.Info.length; ++j) {
const info = xml.Info[j];
Expand Down Expand Up @@ -156,22 +185,25 @@ export class Catch2TestInfo extends AbstractTestInfo {
}
}

private _processXmlTagExpressions(xml: XmlObject, title: string, testEvent: TestEvent): void {
private _processXmlTagExpressions(
xml: XmlObject,
title: Catch2Section,
stack: Catch2Section[],
testEvent: TestEvent,
): void {
if (xml.hasOwnProperty('Expression')) {
for (let j = 0; j < xml.Expression.length; ++j) {
const expr = xml.Expression[j];
try {
testEvent.message +=
title +
' ➡️ ' +
(expr.$.type ? expr.$.type : '<unknown>') +
' at line ' +
expr.$.line +
':\n' +
' Original:\n ' +
this._getTitle(
title,
stack,
new Catch2Section(expr.$.type ? expr.$.type : '<unknown>', expr.$.filename, expr.$.line),
) +
':\n Original:\n ' +
expr.Original.map((x: string) => x.trim()).join('; ') +
'\n' +
' Expanded:\n ' +
'\n Expanded:\n ' +
expr.Expanded.map((x: string) => x.trim()).join('; ') +
'\n' +
'⬆️⬆️⬆️\n\n';
Expand All @@ -182,37 +214,66 @@ export class Catch2TestInfo extends AbstractTestInfo {
} catch (error) {
this._shared.log.error(error);
}
this._processXmlTagFatalErrorConditions(expr, title, testEvent);
this._processXmlTagFatalErrorConditions(expr, title, stack, testEvent);
}
}
}

private _processXmlTagSections(xml: XmlObject, title: string, testEvent: TestEvent): void {
private _processXmlTagSections(
xml: XmlObject,
title: Catch2Section,
stack: Catch2Section[],
testEvent: TestEvent,
parentSection: Catch2Section,
): void {
if (xml.hasOwnProperty('Section')) {
for (let j = 0; j < xml.Section.length; ++j) {
const section = xml.Section[j];
try {
title += ' ➡️ "' + section.$.name + '" at line ' + section.$.line;
let currSection = parentSection.children.find(
v => v.name === section.$.name && v.filename === section.$.filename && v.line === section.$.line,
);

this._processInfoWarningAndFailureTags(xml, title, testEvent);
if (currSection === undefined) {
currSection = new Catch2Section(section.$.name, section.$.filename, section.$.line);
parentSection.children.push(currSection);
}

this._processXmlTagExpressions(section, title, testEvent);
if (
section.OverallResults &&
section.OverallResults.length > 0 &&
section.OverallResults[0].$.failures !== '0'
) {
currSection.failed = true;
}

const currStack = stack.concat(currSection);

this._processInfoWarningAndFailureTags(xml, title, currStack, testEvent);

this._processXmlTagSections(section, title, testEvent);
this._processXmlTagExpressions(section, title, currStack, testEvent);

this._processXmlTagSections(section, title, currStack, testEvent, currSection);
} catch (error) {
this._shared.log.error(error);
}
}
}
}

private _processXmlTagFatalErrorConditions(expr: XmlObject, title: string, testEvent: TestEvent): void {
private _processXmlTagFatalErrorConditions(
expr: XmlObject,
title: Catch2Section,
stack: Catch2Section[],
testEvent: TestEvent,
): void {
if (expr.hasOwnProperty('FatalErrorCondition')) {
try {
for (let j = 0; j < expr.FatalErrorCondition.length; ++j) {
const fatal = expr.FatalErrorCondition[j];

testEvent.message += title + ' ➡️ Fatal Error at line ' + expr.$.line + ':\n';
testEvent.message +=
this._getTitle(title, stack, new Catch2Section('Fatal Error', expr.$.filename, expr.$.line)) + ':\n';
if (fatal.hasOwnProperty('_')) {
testEvent.message += ' Error: ' + fatal._.trim() + '\n';
} else {
Expand All @@ -226,4 +287,30 @@ export class Catch2TestInfo extends AbstractTestInfo {
}
}
}

private _getTitle(title: Catch2Section, stack: Catch2Section[], suffix: Catch2Section): string {
return (
'⬇️⬇️⬇️ ' +
[title]
.concat(stack, suffix)
.map((f: Catch2Section) => '"' + f.name + '" at line ' + f.line)
.join(' ➡️ ')
);
}

// private _getExecParamStr(stack: Section[]): string {
// return (
// '{ "exec": ' +
// this.execPath +
// '",\n' +
// ' "cwd": "' +
// this.execOptions.cwd +
// '"\n' +
// ' "args": ["' +
// this.getEscapedTestName().replace('"', '\\"') +
// '"' +
// stack.map(f => ', "-c", "' + f.name.replace('"', '\\"') + '"').join('') +
// '] }'
// );
// }
}
Loading

0 comments on commit eaf4f1d

Please sign in to comment.