Skip to content

Commit 67816ef

Browse files
committed
Fix running identically named parameterized tests on second run
1 parent 4ecd869 commit 67816ef

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/TestExplorer/TestParsers/SwiftTestingOutputParser.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,15 @@ export class SwiftTestingOutputParser {
347347
}));
348348
}
349349

350+
private testItemIndexFromTestID(testID: string, runState: ITestRunState): number {
351+
const testName = this.testName(testID);
352+
const id = runState.getTestItemIndex(testName, undefined);
353+
if (id === -1) {
354+
return runState.getTestItemIndex(testID, undefined);
355+
}
356+
return id;
357+
}
358+
350359
private parse(item: SwiftTestEvent, runState: ITestRunState) {
351360
if (
352361
item.kind === "test" &&
@@ -358,8 +367,7 @@ export class SwiftTestingOutputParser {
358367
// map an event.payload.testID back to a test case.
359368
this.buildTestCaseMapForParameterizedTest(item);
360369

361-
const testName = this.testName(item.payload.id);
362-
const testIndex = runState.getTestItemIndex(testName, undefined);
370+
const testIndex = this.testItemIndexFromTestID(item.payload.id, runState);
363371
// If a test has test cases it is paramterized and we need to notify
364372
// the caller that the TestClass should be added to the vscode.TestRun
365373
// before it starts.
@@ -385,8 +393,7 @@ export class SwiftTestingOutputParser {
385393
this.testRunStarted();
386394
return;
387395
} else if (item.payload.kind === "testStarted") {
388-
const testName = this.testName(item.payload.testID);
389-
const testIndex = runState.getTestItemIndex(testName, undefined);
396+
const testIndex = this.testItemIndexFromTestID(item.payload.testID, runState);
390397
runState.started(testIndex, item.payload.instant.absolute);
391398
return;
392399
} else if (item.payload.kind === "testCaseStarted") {
@@ -398,8 +405,7 @@ export class SwiftTestingOutputParser {
398405
runState.started(testIndex, item.payload.instant.absolute);
399406
return;
400407
} else if (item.payload.kind === "testSkipped") {
401-
const testName = this.testName(item.payload.testID);
402-
const testIndex = runState.getTestItemIndex(testName, undefined);
408+
const testIndex = this.testItemIndexFromTestID(item.payload.testID, runState);
403409
runState.skipped(testIndex);
404410
return;
405411
} else if (item.payload.kind === "issueRecorded") {
@@ -444,8 +450,7 @@ export class SwiftTestingOutputParser {
444450
}
445451
return;
446452
} else if (item.payload.kind === "testEnded") {
447-
const testName = this.testName(item.payload.testID);
448-
const testIndex = runState.getTestItemIndex(testName, undefined);
453+
const testIndex = this.testItemIndexFromTestID(item.payload.testID, runState);
449454

450455
// When running a single test the testEnded and testCaseEnded events
451456
// have the same ID, and so we'd end the same test twice.

0 commit comments

Comments
 (0)