diff --git a/Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift b/Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift index 27603f144..306d4698f 100644 --- a/Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift +++ b/Sources/SourceKitLSP/Swift/CodeActions/PackageManifestEdits.swift @@ -43,21 +43,36 @@ struct PackageManifestEdits: SyntaxCodeActionProvider { } do { - // Describe the target we are going to create. - let target = try TargetDescription( - name: "\(targetName)Tests", - dependencies: [.byName(name: targetName, condition: nil)], - type: .test - ) + var actions: [CodeAction] = [] - let edits = try AddTarget.addTarget(target, to: scope.file) - return [ - CodeAction( - title: "Add test target", - kind: .refactor, - edit: edits.asWorkspaceEdit(snapshot: scope.snapshot) - ) + let variants: [(AddTarget.TestHarness, String)] = [ + (.swiftTesting, "Swift Testing"), + (.xctest, "XCTest"), ] + for (testingLibrary, libraryName) in variants { + // Describe the target we are going to create. + let target = try TargetDescription( + name: "\(targetName)Tests", + dependencies: [.byName(name: targetName, condition: nil)], + type: .test + ) + + let edits = try AddTarget.addTarget( + target, + to: scope.file, + configuration: .init(testHarness: testingLibrary) + ) + + actions.append( + CodeAction( + title: "Add test target (\(libraryName))", + kind: .refactor, + edit: edits.asWorkspaceEdit(snapshot: scope.snapshot) + ) + ) + } + + return actions } catch { return [] } diff --git a/Tests/SourceKitLSPTests/CodeActionTests.swift b/Tests/SourceKitLSPTests/CodeActionTests.swift index 27752e902..7939c3d75 100644 --- a/Tests/SourceKitLSPTests/CodeActionTests.swift +++ b/Tests/SourceKitLSPTests/CodeActionTests.swift @@ -609,12 +609,12 @@ final class CodeActionTests: XCTestCase { // Make sure we get the expected package manifest editing actions. let addTestAction = codeActions.first { action in - return action.title == "Add test target" + return action.title == "Add test target (Swift Testing)" } XCTAssertNotNil(addTestAction) guard let addTestChanges = addTestAction?.edit?.documentChanges else { - XCTFail("Didn't have changes in the 'Add test target' action") + XCTFail("Didn't have changes in the 'Add test target (Swift Testing)' action") return }