From 2b500e797ad8d064610df59c6f4a91e6bb5b7219 Mon Sep 17 00:00:00 2001 From: Ernesto Cambuston Date: Sat, 20 Apr 2024 19:48:32 -0700 Subject: [PATCH 1/3] fix buildable ref --- Sources/XcodeGenKit/SchemeGenerator.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 1f2a08105..c04a40a7a 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -282,9 +282,11 @@ public class SchemeGenerator { XCScheme.TestPlanReference(reference: "container:\(testPlan.path)", default: defaultTestPlanIndex == index) } ?? [] + let testMacroExpansionBuildableRef = testBuildTargetEntries.map(\.buildableReference).contains(buildableReference) ? buildableReference : testBuildTargetEntries.first?.buildableReference + let testAction = XCScheme.TestAction( buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name, - macroExpansion: buildableReference, + macroExpansion: testMacroExpansionBuildableRef, testables: testables, testPlans: testPlans.isEmpty ? nil : testPlans, preActions: scheme.test?.preActions.map(getExecutionAction) ?? [], From c5016d3dc6c28a5f189ea66f34138d9fd0ed27ce Mon Sep 17 00:00:00 2001 From: Ernesto Cambuston Date: Sat, 20 Apr 2024 20:24:40 -0700 Subject: [PATCH 2/3] fix test --- Sources/XcodeGenKit/SchemeGenerator.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index c04a40a7a..c69974e27 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -281,8 +281,8 @@ public class SchemeGenerator { let testPlans = scheme.test?.testPlans.enumerated().map { index, testPlan in XCScheme.TestPlanReference(reference: "container:\(testPlan.path)", default: defaultTestPlanIndex == index) } ?? [] - - let testMacroExpansionBuildableRef = testBuildTargetEntries.map(\.buildableReference).contains(buildableReference) ? buildableReference : testBuildTargetEntries.first?.buildableReference + let testBuildableEntries = buildActionEntries.filter({ $0.buildFor.contains(.testing) }) + testBuildTargetEntries + let testMacroExpansionBuildableRef = testBuildableEntries.map(\.buildableReference).contains(buildableReference) ? buildableReference : testBuildableEntries.first?.buildableReference let testAction = XCScheme.TestAction( buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name, From 4c6b0176e32e8cf2210f3b2baf979effaf21cd7a Mon Sep 17 00:00:00 2001 From: Ernesto Cambuston Date: Thu, 20 Jun 2024 14:00:57 -0700 Subject: [PATCH 3/3] add test --- .../SchemeGeneratorTests.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift index b5f392d38..31af67475 100644 --- a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift @@ -479,6 +479,46 @@ class SchemeGeneratorTests: XCTestCase { try expect(xcscheme.launchAction?.macroExpansion?.buildableName) == "MyApp.app" } + $0.it("generates scheme with macroExpansion from tests when the main target is not part of the scheme") { + let app = Target( + name: "MyApp", + type: .application, + platform: .iOS, + dependencies: [] + ) + + let mockApp = Target( + name: "MockApp", + type: .application, + platform: .iOS, + dependencies: [] + ) + + let testBundle = Target( + name: "TestBundle", + type: .unitTestBundle, + platform: .iOS + ) + let appTarget = Scheme.BuildTarget(target: .local(app.name), buildTypes: [.running]) + let mockAppTarget = Scheme.BuildTarget(target: .local(mockApp.name), buildTypes: [.testing]) + let testBundleTarget = Scheme.BuildTarget(target: .local(testBundle.name), buildTypes: [.testing]) + + let scheme = Scheme( + name: "TestScheme", + build: Scheme.Build(targets: [appTarget, mockAppTarget, testBundleTarget]), + run: Scheme.Run(config: "Debug", macroExpansion: "MyApp") + ) + let project = Project( + name: "test", + targets: [app, mockApp, testBundle], + schemes: [scheme] + ) + let xcodeProject = try project.generateXcodeProject() + + let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first) + try expect(xcscheme.testAction?.macroExpansion?.buildableName) == "MockApp.app" + } + $0.it("generates scheme with test target of local swift package") { let targetScheme = TargetScheme( testTargets: [Scheme.Test.TestTarget(targetReference: TestableTargetReference(name: "XcodeGenKitTests", location: .package("XcodeGen")))])