From 12aea54878482aa2a67ed64a18f1891d24a540f3 Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Wed, 5 Dec 2018 19:13:18 +1100 Subject: [PATCH] generate TestTargetID project attributes for unit tests --- Sources/XcodeGenKit/PBXProjGenerator.swift | 13 ++++++------- .../TestProject/Project.xcodeproj/project.pbxproj | 9 +++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index cfab3bce..3e024264 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -310,8 +310,8 @@ public class PBXProjGenerator { var targetAttributes: [PBXTarget: [String: Any]] = [:] - let uiTestTargets = pbxProj.nativeTargets.filter { $0.productType == .uiTestBundle } - for uiTestTarget in uiTestTargets { + let testTargets = pbxProj.nativeTargets.filter { $0.productType == .uiTestBundle || $0.productType == .unitTestBundle } + for testTarget in testTargets { // look up TEST_TARGET_NAME build setting func testTargetName(_ target: PBXTarget) -> String? { @@ -322,11 +322,10 @@ public class PBXProjGenerator { .first } - guard let name = testTargetName(uiTestTarget) else { continue } + guard let name = testTargetName(testTarget) else { continue } guard let target = self.pbxProj.targets(named: name).first else { continue } - // FIX: Can't set in xcproj 5.0+ - targetAttributes[uiTestTarget, default: [:]].merge(["TestTargetID": target]) + targetAttributes[testTarget, default: [:]].merge(["TestTargetID": target]) } func generateTargetAttributes(_ target: ProjectTarget, pbxTarget: PBXTarget) { @@ -817,12 +816,12 @@ public class PBXProjGenerator { } // automatically set test target name - if target.type == .uiTestBundle, + if target.type == .uiTestBundle || target.type == .unitTestBundle, !project.targetHasBuildSetting("TEST_TARGET_NAME", target: target, config: config) { for dependency in target.dependencies { if dependency.type == .target, let dependencyTarget = project.getTarget(dependency.reference), - dependencyTarget.type == .application { + dependencyTarget.type.isApp { buildSettings["TEST_TARGET_NAME"] = dependencyTarget.name break } diff --git a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj index 8b2f0211..7a9f095b 100644 --- a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj @@ -1362,6 +1362,9 @@ AT_D40C01B2BAD29EDEA392714DFB69FE8F = { CUSTOM = value; }; + NT_193BAF154270D1C21E269EDF2A1BD3F6 = { + TestTargetID = NT_BEB0891E36797FE2214A0A9D516D408D; + }; NT_B91A6EACD6F5192FECA2E95FD531D0CA = { ProvisioningStyle = Automatic; }; @@ -2829,6 +2832,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Production Debug"; }; @@ -3119,6 +3123,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Staging Release"; }; @@ -3359,6 +3364,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Test Release"; }; @@ -3843,6 +3849,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Test Debug"; }; @@ -4472,6 +4479,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Production Release"; }; @@ -4488,6 +4496,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.project.App-iOS-Tests"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = App_iOS; }; name = "Staging Debug"; };