Skip to content

Commit f0d869f

Browse files
authored
Merge pull request #1197 from DougGregor/package-editing-refactor-with-swift-testing
2 parents 624d4b6 + 638fd5b commit f0d869f

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift

+28-13
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,36 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
4343
}
4444

4545
do {
46-
// Describe the target we are going to create.
47-
let target = try TargetDescription(
48-
name: "\(targetName)Tests",
49-
dependencies: [.byName(name: targetName, condition: nil)],
50-
type: .test
51-
)
46+
var actions: [CodeAction] = []
5247

53-
let edits = try AddTarget.addTarget(target, to: scope.file)
54-
return [
55-
CodeAction(
56-
title: "Add test target",
57-
kind: .refactor,
58-
edit: edits.asWorkspaceEdit(snapshot: scope.snapshot)
59-
)
48+
let variants: [(AddTarget.TestHarness, String)] = [
49+
(.swiftTesting, "Swift Testing"),
50+
(.xctest, "XCTest"),
6051
]
52+
for (testingLibrary, libraryName) in variants {
53+
// Describe the target we are going to create.
54+
let target = try TargetDescription(
55+
name: "\(targetName)Tests",
56+
dependencies: [.byName(name: targetName, condition: nil)],
57+
type: .test
58+
)
59+
60+
let edits = try AddTarget.addTarget(
61+
target,
62+
to: scope.file,
63+
configuration: .init(testHarness: testingLibrary)
64+
)
65+
66+
actions.append(
67+
CodeAction(
68+
title: "Add test target (\(libraryName))",
69+
kind: .refactor,
70+
edit: edits.asWorkspaceEdit(snapshot: scope.snapshot)
71+
)
72+
)
73+
}
74+
75+
return actions
6176
} catch {
6277
return []
6378
}

Tests/SourceKitLSPTests/CodeActionTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,12 @@ final class CodeActionTests: XCTestCase {
609609

610610
// Make sure we get the expected package manifest editing actions.
611611
let addTestAction = codeActions.first { action in
612-
return action.title == "Add test target"
612+
return action.title == "Add test target (Swift Testing)"
613613
}
614614
XCTAssertNotNil(addTestAction)
615615

616616
guard let addTestChanges = addTestAction?.edit?.documentChanges else {
617-
XCTFail("Didn't have changes in the 'Add test target' action")
617+
XCTFail("Didn't have changes in the 'Add test target (Swift Testing)' action")
618618
return
619619
}
620620

0 commit comments

Comments
 (0)