simplify target reference

This commit is contained in:
Yonas Kolb 2021-12-31 15:25:08 +11:00
parent 487d25c699
commit c4d85923eb
4 changed files with 17 additions and 18 deletions

View File

@ -824,7 +824,7 @@ A multiline script can be written using the various YAML multiline methods, for
### Test Action
- [ ] **gatherCoverageData**: **Bool** - a boolean that indicates if this scheme should gather coverage data. This defaults to false
- [ ] **coverageTargets**: **[[Testable Target Reference](#testable-target-reference)]** - a list of targets to gather code coverage. Each entry can also either be a simple string, a string using [Project Reference](#project-reference) or [Testable Target Reference](#testable-target-reference)
- [ ] **coverageTargets**: **[[Testable Target Reference](#testable-target-reference)]** - a list of targets to gather code coverage. Each entry can also either be a simple string, or a [Test Target](#test-target)
- [ ] **targets**: **[[Test Target](#test-target)]** - a list of targets to test. Each entry can either be a simple string, or a [Test Target](#test-target)
- [ ] **customLLDBInit**: **String** - the absolute path to the custom `.lldbinit` file
- [ ] **captureScreenshotsAutomatically**: **Bool** - indicates whether screenshots should be captured automatically while UI Testing. This defaults to true.

View File

@ -462,16 +462,7 @@ extension Scheme.Test: JSONObjectConvertible {
gatherCoverageData = jsonDictionary.json(atKeyPath: "gatherCoverageData") ?? Scheme.Test.gatherCoverageDataDefault
if let coverages = jsonDictionary["coverageTargets"] as? [Any] {
coverageTargets = try coverages.compactMap { target in
if let string = target as? String {
return try TestableTargetReference(string)
} else if let dictionary = target as? JSONDictionary,
let target: TestableTargetReference = try? .init(jsonDictionary: dictionary) {
return target
} else {
return nil
}
}
coverageTargets = try coverages.compactMap(TestableTargetReference.init)
} else {
coverageTargets = []
}
@ -548,11 +539,7 @@ extension Scheme.Test: JSONEncodable {
extension Scheme.Test.TestTarget: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
if let name: String = jsonDictionary.json(atKeyPath: "name") {
targetReference = try TestableTargetReference(name)
} else {
self.targetReference = try jsonDictionary.json(atKeyPath: "target")
}
targetReference = try TestableTargetReference(jsonDictionary: jsonDictionary)
randomExecutionOrder = jsonDictionary.json(atKeyPath: "randomExecutionOrder") ?? Scheme.Test.TestTarget.randomExecutionOrderDefault
parallelizable = jsonDictionary.json(atKeyPath: "parallelizable") ?? Scheme.Test.TestTarget.parallelizableDefault
skipped = jsonDictionary.json(atKeyPath: "skipped") ?? false

View File

@ -43,6 +43,17 @@ extension TestableTargetReference {
}
}
public init?(value: Any) throws {
if let string = value as? String {
try self.init(string)
} else if let dictionary = value as? JSONDictionary,
let reference = try? TestableTargetReference(jsonDictionary: dictionary) {
self = reference
} else {
return nil
}
}
public static func local(_ name: String) -> TestableTargetReference {
TestableTargetReference(name: name, location: .local)
}
@ -79,6 +90,8 @@ extension TestableTargetReference: JSONObjectConvertible {
let paths = project.split(separator: "/")
name = String(paths[1])
location = .package(String(paths[0]))
} else if let name: String = jsonDictionary.json(atKeyPath: "name") {
self = try TestableTargetReference(name)
} else {
name = try jsonDictionary.json(atKeyPath: "local")
location = .local

View File

@ -15,8 +15,7 @@ targets:
sources: [SPM]
scheme:
testTargets:
- target:
package: XcodeGen/XcodeGenKitTests
- package: XcodeGen/XcodeGenKitTests
- Tests
dependencies:
- package: Codability