Skip to content

Commit 075db6f

Browse files
authored
Fix debugging entire XCTest targets (#1209)
When right clicking a test target and debugging the tests, no XCTests are run. The test run argument simplification code would simplify too much when debugging a test target; the `xctest` binary does not accept a test target as an `-XCTest` argument. Only fully specified test names or test suites are permitted. Issue: #1207
1 parent f2300d3 commit 075db6f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/TestExplorer/TestRunArguments.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export class TestRunArguments {
123123
const { xcTestResult, swiftTestResult } = this.simplifyTestArgs(
124124
testItem,
125125
xcTestArgs,
126-
swiftTestArgs
126+
swiftTestArgs,
127+
isDebug
127128
);
128129

129130
return {
@@ -156,12 +157,23 @@ export class TestRunArguments {
156157
private simplifyTestArgs(
157158
testItem: vscode.TestItem,
158159
xcTestArgs: vscode.TestItem[],
159-
swiftTestArgs: vscode.TestItem[]
160+
swiftTestArgs: vscode.TestItem[],
161+
isDebug: boolean
160162
): { xcTestResult: vscode.TestItem[]; swiftTestResult: vscode.TestItem[] } {
161163
// If we've worked all the way up to a test target, it may have both swift-testing
162164
// and XCTests.
163165
const isTestTarget = !!testItem.tags.find(tag => tag.id === "test-target");
166+
164167
if (isTestTarget) {
168+
// We cannot simplify away test suites leaving only the target if we are debugging,
169+
// since the exact names of test suites to run need to be passed to the xctest binary.
170+
// It will not debug all tests with only the target name.
171+
if (isDebug) {
172+
return {
173+
xcTestResult: xcTestArgs,
174+
swiftTestResult: swiftTestArgs,
175+
};
176+
}
165177
return {
166178
// Add a trailing .* to match a test target name exactly.
167179
// This prevents TestTarget matching TestTarget2.

test/integration-tests/testexplorer/TestRunArguments.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,35 @@ suite("TestRunArguments Suite", () => {
317317
testItems: [testTargetId, xcSuiteId, xcTestId, anotherXcSuiteId, anotherXcTestId1],
318318
});
319319
});
320+
321+
test("Full XCTest Target (debug mode)", () => {
322+
const xcTestId2 = "XCTest Item 2";
323+
const anotherXcSuiteId = "Another XCTest Suite";
324+
const anotherXcTestId1 = "Another XCTest Item 1";
325+
const anotherXcTestId2 = "Another XCTest Item 2";
326+
const dsl = `
327+
tt:${testTargetId}
328+
xc:${xcSuiteId}
329+
xc:${xcTestId}
330+
xc:${xcTestId2}
331+
xc:${anotherXcSuiteId}
332+
xc:${anotherXcTestId1}
333+
xc:${anotherXcTestId2}
334+
`;
335+
createTestItemTree(controller, dsl);
336+
const testArgs = new TestRunArguments(runRequestByIds([testTargetId]), true);
337+
assertRunArguments(testArgs, {
338+
xcTestArgs: [xcSuiteId, anotherXcSuiteId],
339+
swiftTestArgs: [],
340+
testItems: [
341+
anotherXcTestId1,
342+
anotherXcTestId2,
343+
anotherXcSuiteId,
344+
xcSuiteId,
345+
testTargetId,
346+
xcTestId2,
347+
xcTestId,
348+
],
349+
});
350+
});
320351
});

0 commit comments

Comments
 (0)