Skip to content

Commit cf6a78c

Browse files
committed
Add separate "add test" manifest actions for XCTest and Swift Testing
1 parent e5d9ff0 commit cf6a78c

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,36 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
5555
}
5656

5757
do {
58-
// Describe the target we are going to create.
59-
let target = try TargetDescription(
60-
name: "\(targetName)Tests",
61-
dependencies: [.byName(name: targetName, condition: nil)],
62-
type: .test
63-
)
58+
var actions: [CodeAction] = []
6459

65-
let edits = try AddTarget.addTarget(target, to: scope.file)
66-
return [
67-
CodeAction(
68-
title: "Add test target",
69-
kind: .refactor,
70-
edit: edits.asWorkspaceEdit(snapshot: scope.snapshot)
71-
)
60+
let variants: [(AddTarget.TestHarness, String)] = [
61+
(.swiftTesting, "Swift Testing"),
62+
(.xctest, "XCTest")
7263
]
64+
for (testingLibrary, libraryName) in variants {
65+
// Describe the target we are going to create.
66+
let target = try TargetDescription(
67+
name: "\(targetName)Tests",
68+
dependencies: [.byName(name: targetName, condition: nil)],
69+
type: .test
70+
)
71+
72+
let edits = try AddTarget.addTarget(
73+
target,
74+
to: scope.file,
75+
configuration: .init(testHarness: testingLibrary)
76+
)
77+
78+
actions.append(
79+
CodeAction(
80+
title: "Add test target (\(libraryName))",
81+
kind: .refactor,
82+
edit: edits.asWorkspaceEdit(snapshot: scope.snapshot)
83+
)
84+
)
85+
}
86+
87+
return actions
7388
} catch {
7489
return []
7590
}

Tests/SourceKitLSPTests/CodeActionTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,13 @@ final class CodeActionTests: XCTestCase {
522522
// Make sure we get the expected package manifest editing actions.
523523
XCTAssertTrue(
524524
codeActions.contains { action in
525-
return action.title == "Add test target"
525+
return action.title == "Add test target (Swift Testing)"
526+
}
527+
)
528+
529+
XCTAssertTrue(
530+
codeActions.contains { action in
531+
return action.title == "Add test target (XCTest)"
526532
}
527533
)
528534

0 commit comments

Comments
 (0)