Skip to content

Commit 3038cac

Browse files
cameroncookecodex
andcommitted
fix(test): Count parameterized Swift Testing results once
Swift Testing result lines can include parameterized case metadata such as "with 4 test cases", but Xcode's discovery and run summaries count that output as one reported test item. Count each result line once so CLI progress and final summaries stay aligned with discovered tests. Fixes GH-384 Co-Authored-By: OpenAI Codex <codex@openai.com>
1 parent 24a295a commit 3038cac

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/utils/__tests__/xcodebuild-event-parser.test.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ describe('xcodebuild-event-parser', () => {
593593
expect(summary).toMatchObject({
594594
fragment: 'build-summary',
595595
operation: 'TEST',
596-
totalTests: 5,
597-
passedTests: 5,
596+
totalTests: 2,
597+
passedTests: 2,
598598
failedTests: 0,
599599
skippedTests: 0,
600600
});
@@ -624,7 +624,7 @@ describe('xcodebuild-event-parser', () => {
624624
]);
625625
});
626626

627-
it('does not double-count xcodebuild-formatted test lines when a Swift Testing summary follows', () => {
627+
it('keeps xcodebuild-formatted test lines independent from Swift Testing summaries', () => {
628628
const events = collectEvents('TEST', [
629629
{
630630
source: 'stdout',
@@ -639,7 +639,7 @@ describe('xcodebuild-event-parser', () => {
639639
const progress = events.filter((event) => event.fragment === 'test-progress');
640640
expect(progress).toEqual([
641641
expect.objectContaining({ completed: 1, failed: 0, skipped: 0 }),
642-
expect.objectContaining({ completed: 1, failed: 0, skipped: 0 }),
642+
expect.objectContaining({ completed: 2, failed: 0, skipped: 0 }),
643643
]);
644644
});
645645

@@ -662,6 +662,29 @@ describe('xcodebuild-event-parser', () => {
662662
]);
663663
});
664664

665+
it('keeps parameterized Swift Testing result counts aligned with the run summary', () => {
666+
const events = collectRunStateEvents([
667+
{
668+
source: 'stdout',
669+
text: '✔ Test "Parameterized test" with 4 test cases passed after 0.001 seconds.\n',
670+
},
671+
{
672+
source: 'stdout',
673+
text: '✔ Test run with 1 test in 1 suite passed after 0.001 seconds.\n',
674+
},
675+
]);
676+
677+
const summary = events.filter((event) => event.fragment === 'build-summary').at(-1);
678+
expect(summary).toMatchObject({
679+
fragment: 'build-summary',
680+
operation: 'TEST',
681+
totalTests: 1,
682+
passedTests: 1,
683+
failedTests: 0,
684+
skippedTests: 0,
685+
});
686+
});
687+
665688
it('processes full test lifecycle', () => {
666689
const events = collectEvents('TEST', [
667690
{ source: 'stdout', text: 'Resolve Package Graph\n' },
@@ -684,7 +707,7 @@ describe('xcodebuild-event-parser', () => {
684707
expect(fragments).toContain('test-failure');
685708
});
686709

687-
it('increments counts by caseCount for parameterized Swift Testing results', () => {
710+
it('counts parameterized Swift Testing result lines once for progress', () => {
688711
const events = collectEvents('TEST', [
689712
{
690713
source: 'stdout',
@@ -695,7 +718,7 @@ describe('xcodebuild-event-parser', () => {
695718
const progress = events.filter((e) => e.fragment === 'test-progress');
696719
expect(progress).toHaveLength(1);
697720
if (progress[0].fragment === 'test-progress') {
698-
expect(progress[0].completed).toBe(3);
721+
expect(progress[0].completed).toBe(1);
699722
}
700723
});
701724

src/utils/xcodebuild-event-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export function createXcodebuildEventParser(options: EventParserOptions): Xcodeb
236236
testCase: ParsedTestCase,
237237
source: 'xcodebuild' | 'swift-testing' = 'xcodebuild',
238238
): void {
239-
const increment = testCase.caseCount ?? 1;
239+
const increment = 1;
240240
completedCount += increment;
241241
const durationMs = parseDurationMs(testCase.durationText);
242242

0 commit comments

Comments
 (0)