mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Add coverage targets for target schemes (#1189)
* Changes * Tests and docs * Update fixtures * Update CHANGELOG.md Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
### Added
|
||||
|
||||
- Added the option to specify a `location` in a test target [#1150](https://github.com/yonaskolb/XcodeGen/issues/1150) @KrisRJack
|
||||
- Added `coverageTargets` for target test schemes. This enables to gather code coverage for specific targets. [#1189](https://github.com/yonaskolb/XcodeGen/pull/1189) @gabriellanata
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -653,6 +653,7 @@ This is a convenience used to automatically generate schemes for a target based
|
||||
- [x] **configVariants**: **[String]** - This generates a scheme for each entry, using configs that contain the name with debug and release variants. This is useful for having different environment schemes.
|
||||
- [ ] **testTargets**: **[[Test Target](#test-target)]** - a list of test targets that should be included in the scheme. These will be added to the build targets and the test entries. Each entry can either be a simple string, or a [Test Target](#test-target)
|
||||
- [ ] **gatherCoverageData**: **Bool** - a boolean that indicates if this scheme should gather coverage data. This defaults to false
|
||||
- [ ] **coverageTargets**: **[String]** - a list of targets to gather code coverage. Each entry can either be a simple string, or a string using [Project Reference](#project-reference)
|
||||
- [ ] **disableMainThreadChecker**: **Bool** - a boolean that indicates if this scheme should disable the Main Thread Checker. This defaults to false
|
||||
- [ ] **stopOnEveryMainThreadCheckerIssue**: **Bool** - a boolean that indicates if this scheme should stop at every Main Thread Checker issue. This defaults to false
|
||||
- [ ] **buildImplicitDependencies**: **Bool** - Flag to determine if Xcode should build implicit dependencies of this scheme. By default this is `true` if not set.
|
||||
@@ -691,6 +692,9 @@ targets:
|
||||
- Staging
|
||||
- Production
|
||||
gatherCoverageData: true
|
||||
coverageTargets:
|
||||
- MyTarget1
|
||||
- ExternalTarget/OtherTarget1
|
||||
commandLineArguments:
|
||||
"-MyEnabledArg": true
|
||||
"-MyDisabledArg": false
|
||||
|
||||
@@ -11,6 +11,7 @@ public struct TargetScheme: Equatable {
|
||||
public var testTargets: [Scheme.Test.TestTarget]
|
||||
public var configVariants: [String]
|
||||
public var gatherCoverageData: Bool
|
||||
public var coverageTargets: [TargetReference]
|
||||
public var storeKitConfiguration: String?
|
||||
public var language: String?
|
||||
public var region: String?
|
||||
@@ -26,6 +27,7 @@ public struct TargetScheme: Equatable {
|
||||
testTargets: [Scheme.Test.TestTarget] = [],
|
||||
configVariants: [String] = [],
|
||||
gatherCoverageData: Bool = gatherCoverageDataDefault,
|
||||
coverageTargets: [TargetReference] = [],
|
||||
storeKitConfiguration: String? = nil,
|
||||
language: String? = nil,
|
||||
region: String? = nil,
|
||||
@@ -40,6 +42,7 @@ public struct TargetScheme: Equatable {
|
||||
self.testTargets = testTargets
|
||||
self.configVariants = configVariants
|
||||
self.gatherCoverageData = gatherCoverageData
|
||||
self.coverageTargets = coverageTargets
|
||||
self.storeKitConfiguration = storeKitConfiguration
|
||||
self.language = language
|
||||
self.region = region
|
||||
@@ -69,6 +72,19 @@ extension TargetScheme: JSONObjectConvertible {
|
||||
} else {
|
||||
testTargets = []
|
||||
}
|
||||
|
||||
if let targets = jsonDictionary["coverageTargets"] as? [Any] {
|
||||
coverageTargets = try targets.compactMap { target in
|
||||
if let string = target as? String {
|
||||
return try TargetReference(string)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
coverageTargets = []
|
||||
}
|
||||
|
||||
configVariants = jsonDictionary.json(atKeyPath: "configVariants") ?? []
|
||||
gatherCoverageData = jsonDictionary.json(atKeyPath: "gatherCoverageData") ?? TargetScheme.gatherCoverageDataDefault
|
||||
storeKitConfiguration = jsonDictionary.json(atKeyPath: "storeKitConfiguration")
|
||||
@@ -88,6 +104,7 @@ extension TargetScheme: JSONEncodable {
|
||||
public func toJSONValue() -> Any {
|
||||
var dict: [String: Any] = [
|
||||
"configVariants": configVariants,
|
||||
"coverageTargets": coverageTargets.map { $0.reference },
|
||||
"commandLineArguments": commandLineArguments,
|
||||
"testTargets": testTargets.map { $0.toJSONValue() },
|
||||
"environmentVariables": environmentVariables.map { $0.toJSONValue() },
|
||||
|
||||
@@ -413,6 +413,7 @@ extension Scheme {
|
||||
test: .init(
|
||||
config: debugConfig,
|
||||
gatherCoverageData: targetScheme.gatherCoverageData,
|
||||
coverageTargets: targetScheme.coverageTargets,
|
||||
disableMainThreadChecker: targetScheme.disableMainThreadChecker,
|
||||
commandLineArguments: targetScheme.commandLineArguments,
|
||||
targets: targetScheme.testTargets,
|
||||
|
||||
+10
-1
@@ -28,7 +28,7 @@
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "NO"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "NO"
|
||||
disableMainThreadChecker = "YES">
|
||||
<Testables>
|
||||
@@ -72,6 +72,15 @@
|
||||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
<CodeCoverageTargets>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "0867B0DACEF28C11442DE8F7"
|
||||
BuildableName = "App_iOS.app"
|
||||
BlueprintName = "App_iOS"
|
||||
ReferencedContainer = "container:Project.xcodeproj">
|
||||
</BuildableReference>
|
||||
</CodeCoverageTargets>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Production Debug"
|
||||
|
||||
+10
-1
@@ -28,7 +28,7 @@
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "NO"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "NO"
|
||||
disableMainThreadChecker = "YES">
|
||||
<Testables>
|
||||
@@ -72,6 +72,15 @@
|
||||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
<CodeCoverageTargets>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "0867B0DACEF28C11442DE8F7"
|
||||
BuildableName = "App_iOS.app"
|
||||
BlueprintName = "App_iOS"
|
||||
ReferencedContainer = "container:Project.xcodeproj">
|
||||
</BuildableReference>
|
||||
</CodeCoverageTargets>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Staging Debug"
|
||||
|
||||
+10
-1
@@ -28,7 +28,7 @@
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "NO"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "NO"
|
||||
disableMainThreadChecker = "YES">
|
||||
<Testables>
|
||||
@@ -72,6 +72,15 @@
|
||||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
<CodeCoverageTargets>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "0867B0DACEF28C11442DE8F7"
|
||||
BuildableName = "App_iOS.app"
|
||||
BlueprintName = "App_iOS"
|
||||
ReferencedContainer = "container:Project.xcodeproj">
|
||||
</BuildableReference>
|
||||
</CodeCoverageTargets>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Test Debug"
|
||||
|
||||
@@ -152,6 +152,8 @@ targets:
|
||||
- App_iOS_Tests
|
||||
- App_iOS_UITests
|
||||
gatherCoverageData: true
|
||||
coverageTargets:
|
||||
- App_iOS
|
||||
disableMainThreadChecker: true
|
||||
stopOnEveryMainThreadCheckerIssue: true
|
||||
configVariants:
|
||||
|
||||
@@ -463,6 +463,7 @@ class ProjectSpecTests: XCTestCase {
|
||||
parallelizable: false)],
|
||||
configVariants: ["foo"],
|
||||
gatherCoverageData: true,
|
||||
coverageTargets: ["App"],
|
||||
storeKitConfiguration: "Configuration.storekit",
|
||||
disableMainThreadChecker: true,
|
||||
stopOnEveryMainThreadCheckerIssue: false,
|
||||
|
||||
@@ -712,6 +712,7 @@ class SpecLoadingTests: XCTestCase {
|
||||
"ENV1": true,
|
||||
],
|
||||
"gatherCoverageData": true,
|
||||
"coverageTargets": ["t1"],
|
||||
"storeKitConfiguration": "Configuration.storekit",
|
||||
"language": "en",
|
||||
"region": "US",
|
||||
@@ -740,6 +741,7 @@ class SpecLoadingTests: XCTestCase {
|
||||
testTargets: ["t1", "t2"],
|
||||
configVariants: ["dev", "app-store"],
|
||||
gatherCoverageData: true,
|
||||
coverageTargets: ["t1"],
|
||||
storeKitConfiguration: "Configuration.storekit",
|
||||
language: "en",
|
||||
region: "US",
|
||||
|
||||
@@ -326,6 +326,25 @@ class SchemeGeneratorTests: XCTestCase {
|
||||
try expect(xcscheme.testAction?.postActions.count) == 0
|
||||
}
|
||||
|
||||
$0.it("generates target schemes with code coverage options") {
|
||||
var target = app
|
||||
target.scheme = try TargetScheme(
|
||||
gatherCoverageData: true,
|
||||
coverageTargets: [
|
||||
TargetReference(framework.name),
|
||||
]
|
||||
)
|
||||
|
||||
let project = Project(name: "test", targets: [target, framework])
|
||||
let xcodeProject = try project.generateXcodeProject()
|
||||
try expect(xcodeProject.sharedData?.schemes.count) == 1
|
||||
|
||||
let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
|
||||
try expect(xcscheme.testAction?.codeCoverageEnabled) == true
|
||||
try expect(xcscheme.testAction?.codeCoverageTargets.count) == 1
|
||||
try expect(xcscheme.testAction?.codeCoverageTargets.first?.blueprintName) == framework.name
|
||||
}
|
||||
|
||||
$0.it("generates scheme using external project file") {
|
||||
prepareXcodeProj: do {
|
||||
let project = try! Project(path: fixturePath + "scheme_test/test_project.yml")
|
||||
|
||||
Reference in New Issue
Block a user