Skip to content

Commit 61bfe78

Browse files
authored
Arrays of XCResultValueTypes do not parse correctly (#52)
Change Description: This change addresses an issue where arrays (such as [Double] in the performance metrics object) were not properly being decoded. This was due to the need to decode into the intermediate type of XCResultValueType in order to get to the true values underneath. Test Plan/Testing Performed: Added the xcresult that @OdNairy gave in #51. Added some explicit tests to double-check that the values returned match what we would expect. Also did a quick test if we removed one of the enum cases like "CPU Time" that the metric type enum would properly handle new metric identifier values from new xcresult versions.
1 parent 7918fc6 commit 61bfe78

46 files changed

Lines changed: 220 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Sources/XCParseCore/ActionTestPerformanceMetricSummary.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,40 @@
88

99
import Foundation
1010

11+
12+
public enum ActionTestPerformanceMetric : ExpressibleByStringLiteral {
13+
case ClockMonotonicTime
14+
case CPUCycles
15+
case CPUInstructionsRetired
16+
case CPUTime
17+
case DiskLogicalWrites
18+
case MemoryPhysical
19+
case MemoryPhysicalPeak
20+
case Unknown(name: String)
21+
22+
public init(stringLiteral name: String) {
23+
switch name {
24+
case "com.apple.dt.XCTMetric_Clock.time.monotonic":
25+
self = .ClockMonotonicTime
26+
case "com.apple.dt.XCTMetric_CPU.cycles":
27+
self = .CPUCycles
28+
case "com.apple.dt.XCTMetric_CPU.instructions_retired":
29+
self = .CPUInstructionsRetired
30+
case "com.apple.dt.XCTMetric_CPU.time":
31+
self = .CPUTime
32+
case "com.apple.dt.XCTMetric_Disk.logical.writes":
33+
self = .DiskLogicalWrites
34+
case "com.apple.dt.XCTMetric_Memory.physical":
35+
self = .MemoryPhysical
36+
case "com.apple.dt.XCTMetric_Memory.physical-peak":
37+
self = .MemoryPhysicalPeak
38+
default:
39+
self = .Unknown(name: name)
40+
}
41+
}
42+
}
43+
44+
1145
open class ActionTestPerformanceMetricSummary : Codable {
1246
public let displayName: String
1347
public let unitOfMeasurement: String
@@ -20,6 +54,12 @@ open class ActionTestPerformanceMetricSummary : Codable {
2054
public let maxRegression: Double?
2155
public let maxStandardDeviation: Double?
2256

57+
// Derived
58+
public var metricType : ActionTestPerformanceMetric {
59+
let identifierString = identifier ?? "Identifier Missing"
60+
return ActionTestPerformanceMetric(stringLiteral: identifierString)
61+
}
62+
2363
enum ActionTestPerformanceMetricSummaryCodingKeys: String, CodingKey {
2464
case displayName
2565
case unitOfMeasurement

Sources/XCParseCore/XCPResultDecoding.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ extension KeyedDecodingContainer {
350350
let resultObj = try container.decode(XCResultObject.self)
351351
if let type = resultObj.type.getType() as? T.Type {
352352
list.append(try tmpContainer.decode(type))
353+
} else if let type = resultObj.type.getType() as? XCResultValueType.Type {
354+
let decodedValue = try tmpContainer.decode(type)
355+
if let value = decodedValue.getValue() as? T {
356+
list.append(value)
357+
}
353358
}
354359
}
355360
return list

Tests/Resources/testMetrics.xcresult/Data/data.0~2cZk-rcfcJyIr0RMyhHn8Y66wRloJpYYpy_Uso1cGuGFqXcMufCktonXe3E1AW5WcRtngECJpQzAmjP8NIUSRA==

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/Resources/testMetrics.xcresult/Data/data.0~8nVAn0b5EP01lDGHHno97wQuNrVkgJ6rpbjAf7clB58UbXuhPxSCRxvqRT7E_cc6ZPyDigkCpEzU8vh51DA7LQ==

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/Resources/testMetrics.xcresult/Data/data.0~AJwN_W4l3bSyi3kQ5xNhx0ikEYLjYplHuUMwritsZdoPEU5cgY6GYklyxUr_5Bl3XAoezt3XPt4PTgROJog5AQ==

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)