Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debugging entire XCTest targets #1209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/TestExplorer/TestRunArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export class TestRunArguments {
const { xcTestResult, swiftTestResult } = this.simplifyTestArgs(
testItem,
xcTestArgs,
swiftTestArgs
swiftTestArgs,
isDebug
);

return {
Expand Down Expand Up @@ -156,12 +157,23 @@ export class TestRunArguments {
private simplifyTestArgs(
testItem: vscode.TestItem,
xcTestArgs: vscode.TestItem[],
swiftTestArgs: vscode.TestItem[]
swiftTestArgs: vscode.TestItem[],
isDebug: boolean
): { xcTestResult: vscode.TestItem[]; swiftTestResult: vscode.TestItem[] } {
// If we've worked all the way up to a test target, it may have both swift-testing
// and XCTests.
const isTestTarget = !!testItem.tags.find(tag => tag.id === "test-target");

if (isTestTarget) {
// We cannot simplify away test suites leaving only the target if we are debugging,
// since the exact names of test suites to run need to be passed to the xctest binary.
// It will not debug all tests with only the target name.
if (isDebug) {
return {
xcTestResult: xcTestArgs,
swiftTestResult: swiftTestArgs,
};
}
return {
// Add a trailing .* to match a test target name exactly.
// This prevents TestTarget matching TestTarget2.
Expand Down
31 changes: 31 additions & 0 deletions test/integration-tests/testexplorer/TestRunArguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,35 @@ suite("TestRunArguments Suite", () => {
testItems: [testTargetId, xcSuiteId, xcTestId, anotherXcSuiteId, anotherXcTestId1],
});
});

test("Full XCTest Target (debug mode)", () => {
const xcTestId2 = "XCTest Item 2";
const anotherXcSuiteId = "Another XCTest Suite";
const anotherXcTestId1 = "Another XCTest Item 1";
const anotherXcTestId2 = "Another XCTest Item 2";
const dsl = `
tt:${testTargetId}
xc:${xcSuiteId}
xc:${xcTestId}
xc:${xcTestId2}
xc:${anotherXcSuiteId}
xc:${anotherXcTestId1}
xc:${anotherXcTestId2}
`;
createTestItemTree(controller, dsl);
const testArgs = new TestRunArguments(runRequestByIds([testTargetId]), true);
assertRunArguments(testArgs, {
xcTestArgs: [xcSuiteId, anotherXcSuiteId],
swiftTestArgs: [],
testItems: [
anotherXcTestId1,
anotherXcTestId2,
anotherXcSuiteId,
xcSuiteId,
testTargetId,
xcTestId2,
xcTestId,
],
});
});
});