Skip to content

Commit

Permalink
doctest improvements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Aug 24, 2023
1 parent 6dd0926 commit 65e57fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/RunningExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class RunningExecutable {
try {
if (this.terminated) {
return Promise.resolve();
} else if (this.process.pid) {
} else if (this.process.pid && this.process.exitCode === null) {
os.setPriority(this.process.pid, os.constants.priority.PRIORITY_LOW);
log.debug('setPriority is done', `priority(${priority})`, `pid(${this.process.pid})`);

Expand Down
20 changes: 16 additions & 4 deletions src/framework/doctest/DOCExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class DOCExecutable extends AbstractExecutable<DOCTest> {
description: string | undefined,
skipped: string | undefined,
): Promise<DOCTest> => {
const id = getTestId(file, line, testName);
const tags: string[] = suiteName ? [suiteName] : [];
const skippedB = skipped === 'true';
const resolvedFile = this.findSourceFilePath(file);
Expand All @@ -89,7 +90,7 @@ export class DOCExecutable extends AbstractExecutable<DOCTest> {
tags,
description,
(parent: TestItemParent) =>
new DOCTest(this, parent, testName, suiteName, tags, resolvedFile, line, description, skippedB),
new DOCTest(this, parent, id, testName, suiteName, tags, resolvedFile, line, description, skippedB),
(test: DOCTest) => test.update2(resolvedFile, line, tags, skippedB, description),
);
};
Expand Down Expand Up @@ -156,15 +157,22 @@ export class DOCExecutable extends AbstractExecutable<DOCTest> {
p = p.parentTest;
}
if (!(p instanceof DOCTest)) throw Error('unexpected doctest issue');
if (p.suiteName !== undefined) {
params.push('--test-suite=' + p.suiteName);
}
params.push('--test-case=' + p.getEscapedTestName());
params.push('--subcase=' + subTests.map(s => s.id.replaceAll(',', '?')).join(','));
params.push('--subcase-filter-levels=' + subTests.length);
} else if (childrenToRun.every(v => v instanceof DOCTest)) {
const testNames = childrenToRun.map(c => (c as DOCTest).getEscapedTestName());
const dc = childrenToRun as readonly DOCTest[];
if (dc.length > 0 && dc[0].suiteName && dc.every(v => v.suiteName === dc[0].suiteName)) {
params.push('--test-suite=' + dc[0].suiteName);
}
const testNames = dc.map(c => c.getEscapedTestName());
params.push('--test-case=' + testNames.join(','));
} else {
this.log.warnS('wrong run/debug combo', childrenToRun);
throw Error('Cannot run/debug this combination. Only 1 section or multiple tests can be selected only.');
throw Error('Cannot run/debug this combination. Only 1 section or multiple tests can be selected.');
}

params.push('--no-skip=true');
Expand Down Expand Up @@ -247,6 +255,9 @@ export class DOCExecutable extends AbstractExecutable<DOCTest> {
}
}

const getTestId = (file: string | undefined, line: string | undefined, testName: string) =>
`${file ?? ''}:${line ?? ''}:${testName}`;

///

type Option = Record<string, string> & { rand_seed?: string };
Expand Down Expand Up @@ -286,7 +297,8 @@ class TestSuiteTagProcessor implements XmlTagProcessor {

assert(typeof name === 'string' && name.length > 0);

let test = this.findTest(name);
const testId = getTestId(tag.attribs.filename, tag.attribs.line, name);
let test = this.findTest(testId);
if (!test) {
this.shared.log.info('TestCase not found in children', tag, name);
test = await this.create(
Expand Down
9 changes: 5 additions & 4 deletions src/framework/doctest/DOCTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export class DOCTest extends AbstractTest {
constructor(
executable: AbstractExecutable,
parent: TestItemParent,
testNameAsId: string,
id: string,
private readonly testName: string,
public readonly suiteName: string | undefined,
tags: string[],
file: string | undefined,
Expand All @@ -18,8 +19,8 @@ export class DOCTest extends AbstractTest {
super(
executable,
parent,
testNameAsId,
testNameAsId.startsWith(' Scenario:') ? testNameAsId.trimStart() : testNameAsId,
id,
testName.startsWith(' Scenario:') ? testName.trimStart() : testName,
file,
line,
skipped,
Expand All @@ -43,6 +44,6 @@ export class DOCTest extends AbstractTest {

getEscapedTestName(): string {
/* ',' has special meaning */
return this.id.replace(/,/g, '?');
return this.testName.replace(/,/g, '?');
}
}

0 comments on commit 65e57fd

Please sign in to comment.