Skip to content

Commit

Permalink
master: fixed source file resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed Nov 23, 2021
1 parent fd389ba commit 639e0ba
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.0.4]

### Fixed

- navigation to source file related issue (again)

## [4.0.3] - 2021-11-23

- Improved Output formatting and colorization
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Plenty of more **fine-tuning options** are available under [test.advancedExecuta
| ID | Command |
| -------------------------------- | --------------------------------------------- |
| `testMate.cmd.reload-tests` | Reload tests |
| `testMate.cmd.reload-workspaces` | Force reload workspaces (in case of na issue) |
| `testMate.cmd.reload-workspaces` | Force reload workspaces (in case of an issue) |

## About [Sentry.io](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/log.logSentry.md) integration

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ export abstract class AbstractExecutable implements Disposable {
}
}

protected async _resolveAndFindSourceFilePath(file: string | undefined): Promise<string | undefined> {
public async resolveAndFindSourceFilePath(file: string | undefined): Promise<string | undefined> {
if (typeof file != 'string') return undefined;

let resolved = file;
Expand Down
19 changes: 15 additions & 4 deletions src/AbstractTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,35 @@ export abstract class AbstractTest {

private _subTests: Map<string /*id*/, SubTest> | undefined = undefined;

public getOrCreateSubTest(
public async getOrCreateSubTest(
id: string,
label: string | undefined,
file: string | undefined,
line: string | undefined,
): SubTest {
): Promise<SubTest> {
const resolvedFile = await this.executable.resolveAndFindSourceFilePath(file);

if (this._subTests) {
const found = this._subTests.get(id);

if (found) {
found.updateSub(label, file, line);
found.updateSub(label, resolvedFile, line);
return found;
}
} else {
this._subTests = new Map();
}

const subTest = new SubTest(this.shared, this.executable, this._item, id, label, file, line, this._frameworkTag);
const subTest = new SubTest(
this.shared,
this.executable,
this._item,
id,
label,
resolvedFile,
line,
this._frameworkTag,
);
this._subTests.set(id, subTest);

return subTest;
Expand Down
32 changes: 19 additions & 13 deletions src/framework/Catch2Executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ export class Catch2Executable extends AbstractExecutable {
this.shared.log.error('Could not find catch2 file info1', lines);
}
}

filePath = await this._resolveAndFindSourceFilePath(filePath);
}

let description: string | undefined = lines[i++].substr(4);
Expand Down Expand Up @@ -181,7 +179,7 @@ export class Catch2Executable extends AbstractExecutable {
if (matches) matches.forEach((t: string) => tags.push(t.substring(1, t.length - 1)));
}

const resolvedFile = await this._resolveAndFindSourceFilePath(file);
const resolvedFile = await this.resolveAndFindSourceFilePath(file);

return this._createTreeAndAddTest(
this.getTestGrouping(),
Expand Down Expand Up @@ -447,7 +445,7 @@ class TestCaseListingProcessor implements XmlTagProcessor {
abstract class TagProcessorBase implements XmlTagProcessor {
constructor(public readonly builder: TestResultBuilder, protected readonly shared: WorkspaceShared) {}

public onopentag(tag: XmlTag): XmlTagProcessor | void {
public onopentag(tag: XmlTag): void | XmlTagProcessor | Promise<void | XmlTagProcessor> {
const procCreator = TagProcessorBase.openTagProcessorMap.get(tag.name);
if (procCreator) {
return procCreator(tag, this.builder, this.shared);
Expand Down Expand Up @@ -498,7 +496,12 @@ abstract class TagProcessorBase implements XmlTagProcessor {

private static readonly openTagProcessorMap: Map<
string,
null | ((tag: XmlTag, builder: TestResultBuilder, shared: WorkspaceShared) => void | XmlTagProcessor)
| null
| ((
tag: XmlTag,
builder: TestResultBuilder,
shared: WorkspaceShared,
) => void | XmlTagProcessor | Promise<void | XmlTagProcessor>)
> = new Map([
[
'OverallResult',
Expand Down Expand Up @@ -532,14 +535,14 @@ abstract class TagProcessorBase implements XmlTagProcessor {
],
[
'Section',
(tag: XmlTag, builder: TestResultBuilder, shared: WorkspaceShared): XmlTagProcessor =>
new SectionProcessor(shared, builder, tag.attribs),
(tag: XmlTag, builder: TestResultBuilder, shared: WorkspaceShared): Promise<XmlTagProcessor> =>
SectionProcessor.create(shared, builder, tag.attribs),
],
[
'BenchmarkResults',
(tag: XmlTag, builder: TestResultBuilder, shared: WorkspaceShared): XmlTagProcessor => {
async (tag: XmlTag, builder: TestResultBuilder, shared: WorkspaceShared): Promise<XmlTagProcessor> => {
assert(tag.attribs.name);
const subTest = builder.test.getOrCreateSubTest(tag.attribs.name, undefined, undefined, undefined);
const subTest = await builder.test.getOrCreateSubTest(tag.attribs.name, undefined, undefined, undefined);
const subBuilder = builder.createSubTestBuilder(subTest);
return new BenchmarkResultsProcessor(shared, subBuilder, tag.attribs);
},
Expand Down Expand Up @@ -638,14 +641,17 @@ class TestCaseTagProcessor extends TagProcessorBase {
///

class SectionProcessor extends TagProcessorBase {
public constructor(shared: WorkspaceShared, testBuilder: TestResultBuilder, attribs: Record<string, string>) {
public static async create(shared: WorkspaceShared, testBuilder: TestResultBuilder, attribs: Record<string, string>) {
if (typeof attribs.name !== 'string' || !attribs.name) throw Error('Section must have name attribute');

const subTest = testBuilder.test.getOrCreateSubTest(attribs.name, undefined, attribs.filename, attribs.line);
const subTest = await testBuilder.test.getOrCreateSubTest(attribs.name, undefined, attribs.filename, attribs.line);
const subTestBuilder = testBuilder.createSubTestBuilder(subTest);
subTestBuilder.started();
return new SectionProcessor(shared, subTestBuilder);
}

super(subTestBuilder, shared);
private constructor(shared: WorkspaceShared, testBuilder: TestResultBuilder) {
testBuilder.started();
super(testBuilder, shared);
}

public end(): void {
Expand Down
32 changes: 21 additions & 11 deletions src/framework/DOCExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DOCExecutable extends AbstractExecutable {
): Promise<DOCTest> => {
const tags: string[] = suiteName ? [suiteName] : [];
const skippedB = skipped === 'true';
const resolvedFile = await this._resolveAndFindSourceFilePath(file);
const resolvedFile = await this.resolveAndFindSourceFilePath(file);
return this._createTreeAndAddTest(
this.getTestGrouping(),
testName,
Expand Down Expand Up @@ -319,7 +319,7 @@ abstract class TagProcessorBase implements XmlTagProcessor {
protected readonly caseData: CaseData,
) {}

public onopentag(tag: XmlTag): XmlTagProcessor | void {
public onopentag(tag: XmlTag): void | XmlTagProcessor | Promise<void | XmlTagProcessor> {
const procCreator = TagProcessorBase.openTagProcessorMap.get(tag.name);
if (procCreator) {
return procCreator(tag, this.builder, this.caseData, this.shared);
Expand Down Expand Up @@ -365,7 +365,12 @@ abstract class TagProcessorBase implements XmlTagProcessor {
private static readonly openTagProcessorMap: Map<
string,
| null
| ((tag: XmlTag, builder: TestResultBuilder, caseData: CaseData, shared: WorkspaceShared) => void | XmlTagProcessor)
| ((
tag: XmlTag,
builder: TestResultBuilder,
caseData: CaseData,
shared: WorkspaceShared,
) => void | XmlTagProcessor | Promise<void | XmlTagProcessor>)
> = new Map([
[
'SubCase',
Expand All @@ -374,9 +379,9 @@ abstract class TagProcessorBase implements XmlTagProcessor {
builder: TestResultBuilder,
caseData: CaseData,
shared: WorkspaceShared,
): void | XmlTagProcessor => {
): void | XmlTagProcessor | Promise<XmlTagProcessor> => {
// if name is missing we don't create subcase for it
if (tag.attribs.name) return new SubCaseProcessor(shared, builder, tag.attribs, caseData);
if (tag.attribs.name) return SubCaseProcessor.create(shared, builder, tag.attribs, caseData);
},
],
[
Expand Down Expand Up @@ -449,7 +454,7 @@ class TestCaseTagProcessor extends TagProcessorBase {
test.line = attribs.line;
}

public override onopentag(tag: XmlTag): XmlTagProcessor | void {
public override onopentag(tag: XmlTag): void | XmlTagProcessor | Promise<void | XmlTagProcessor> {
if (tag.name === 'OverallResultsAsserts') {
const durationSec = parseFloat(tag.attribs.duration) || undefined;
if (durationSec === undefined) this.shared.log.errorS('doctest: duration is NaN: ' + tag.attribs.duration);
Expand Down Expand Up @@ -487,12 +492,12 @@ class TestCaseTagProcessor extends TagProcessorBase {
///

class SubCaseProcessor extends TagProcessorBase {
public constructor(
public static async create(
shared: WorkspaceShared,
testBuilder: TestResultBuilder,
attribs: Record<string, string>,
parentCaseData: CaseData,
) {
): Promise<SubCaseProcessor> {
if (typeof attribs.name !== 'string' || !attribs.name) throw Error('Section must have name attribute');

let label: string | undefined = undefined;
Expand All @@ -501,11 +506,16 @@ class SubCaseProcessor extends TagProcessorBase {
if (m) label = m[1];
}

const subTest = testBuilder.test.getOrCreateSubTest(attribs.name, label, attribs.filename, attribs.line);
const subTest = await testBuilder.test.getOrCreateSubTest(attribs.name, label, attribs.filename, attribs.line);
const subTestBuilder = testBuilder.createSubTestBuilder(subTest);
subTestBuilder.started();

super(subTestBuilder, shared, parentCaseData);
return new SubCaseProcessor(shared, subTestBuilder, parentCaseData);
}

private constructor(shared: WorkspaceShared, testBuilder: TestResultBuilder, parentCaseData: CaseData) {
testBuilder.started();

super(testBuilder, shared, parentCaseData);
}

//doctest does not provide result for sub-cases, no point to build
Expand Down
2 changes: 1 addition & 1 deletion src/framework/GoogleTestExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class GoogleTestExecutable extends AbstractExecutable {
typeParam: string | undefined,
valueParam: string | undefined,
): Promise<GoogleTestTest> => {
const resolvedFile = await this._resolveAndFindSourceFilePath(file);
const resolvedFile = await this.resolveAndFindSourceFilePath(file);
return this._createTreeAndAddTest(
this.getTestGrouping(),
testName,
Expand Down

0 comments on commit 639e0ba

Please sign in to comment.