Emcee
91 строка · 3.4 Кб
1import Foundation
2
3public enum AppleBuildArtifacts: Codable, Hashable, CustomStringConvertible {
4case iosLogicTests(
5xcTestBundle: XcTestBundle
6)
7
8case iosApplicationTests(
9xcTestBundle: XcTestBundle,
10appBundle: AppBundleLocation
11)
12
13case iosUiTests(
14xcTestBundle: XcTestBundle,
15appBundle: AppBundleLocation,
16runner: RunnerAppLocation,
17additionalApplicationBundles: [AdditionalAppBundleLocation]
18)
19
20public var xcTestBundle: XcTestBundle {
21switch self {
22case .iosLogicTests(let xcTestBundle):
23return xcTestBundle
24case .iosApplicationTests(let xcTestBundle, _):
25return xcTestBundle
26case .iosUiTests(let xcTestBundle, _, _, _):
27return xcTestBundle
28}
29}
30
31private enum CodingKeys: CodingKey {
32case xcTestBundle
33case appBundle
34case runner
35case additionalApplicationBundles
36}
37
38public init(from decoder: Decoder) throws {
39let container = try decoder.container(keyedBy: CodingKeys.self)
40let xcTestBundle = try container.decode(XcTestBundle.self, forKey: .xcTestBundle)
41
42if let runner = try container.decodeIfPresent(RunnerAppLocation.self, forKey: .runner) {
43let appBundle = try container.decode(AppBundleLocation.self, forKey: .appBundle)
44self = .iosUiTests(
45xcTestBundle: xcTestBundle,
46appBundle: appBundle,
47runner: runner,
48additionalApplicationBundles: try container.decodeIfPresent(
49[AdditionalAppBundleLocation].self, forKey: .additionalApplicationBundles
50) ?? []
51)
52} else if let appBundle = try container.decodeIfPresent(AppBundleLocation.self, forKey: .appBundle) {
53self = .iosApplicationTests(
54xcTestBundle: xcTestBundle,
55appBundle: appBundle
56)
57} else {
58self = .iosLogicTests(xcTestBundle: xcTestBundle)
59}
60}
61
62public func encode(to encoder: Encoder) throws {
63var container = encoder.container(keyedBy: CodingKeys.self)
64
65switch self {
66case .iosLogicTests(let xcTestBundle):
67try container.encode(xcTestBundle, forKey: .xcTestBundle)
68
69case .iosApplicationTests(let xcTestBundle, let appBundle):
70try container.encode(xcTestBundle, forKey: .xcTestBundle)
71try container.encode(appBundle, forKey: .appBundle)
72
73case .iosUiTests(let xcTestBundle, let appBundle, let runner, let additionalApplicationBundles):
74try container.encode(xcTestBundle, forKey: .xcTestBundle)
75try container.encode(appBundle, forKey: .appBundle)
76try container.encode(runner, forKey: .runner)
77try container.encode(additionalApplicationBundles, forKey: .additionalApplicationBundles)
78}
79}
80
81public var description: String {
82switch self {
83case .iosLogicTests(let xcTestBundle):
84return "iOS logic tests \(xcTestBundle)"
85case .iosApplicationTests(let xcTestBundle, let appBundle):
86return "iOS application tests \(xcTestBundle) \(appBundle)"
87case .iosUiTests(let xcTestBundle, let appBundle, let runner, let additionalApplicationBundles):
88return "iOS UI tests \(xcTestBundle) \(appBundle) \(runner) \(additionalApplicationBundles)"
89}
90}
91}
92