|
1 | | -# swift-xcresult-parser |
| 1 | +# swift-xcresult-parser |
| 2 | + |
| 3 | +A type-safe Swift library for parsing Xcode `.xcresult` bundles and extracting build warnings, errors, and test failures in a structured format. |
| 4 | + |
| 5 | +[](https://swift.org) |
| 6 | +[](https://developer.apple.com/macos) |
| 7 | +[](LICENSE) |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Parse xcresult bundles**: Extract structured data from Xcode result bundles |
| 12 | +- **Zero external dependencies**: Uses only `xcrun xcresulttool` (ships with Xcode) |
| 13 | +- **Type-safe output**: Strongly-typed Swift models with resilient decoding |
| 14 | +- **Async/await support**: Modern Swift concurrency |
| 15 | +- **Forward compatible**: Handles unknown enum values gracefully for future Xcode versions |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +- Swift 6.2+ |
| 20 | +- macOS 15+ |
| 21 | +- Xcode 16+ |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +### Swift Package Manager |
| 26 | + |
| 27 | +Add the following to your `Package.swift`: |
| 28 | + |
| 29 | +```swift |
| 30 | +dependencies: [ |
| 31 | + .package(url: "https://github.com/diogot/swift-xcresult-parser.git", from: "1.0.0") |
| 32 | +] |
| 33 | +``` |
| 34 | + |
| 35 | +Then add `XCResultParser` to your target dependencies: |
| 36 | + |
| 37 | +```swift |
| 38 | +.target(name: "YourTarget", dependencies: ["XCResultParser"]) |
| 39 | +``` |
| 40 | + |
| 41 | +## Usage |
| 42 | + |
| 43 | +### Basic Usage |
| 44 | + |
| 45 | +```swift |
| 46 | +import XCResultParser |
| 47 | + |
| 48 | +let parser = XCResultParser(path: "path/to/test.xcresult") |
| 49 | +let result = try await parser.parse() |
| 50 | + |
| 51 | +// Access build issues |
| 52 | +for issue in result.buildResults?.allIssues ?? [] { |
| 53 | + print("\(issue.severity): \(issue.message)") |
| 54 | + if let loc = issue.sourceLocation { |
| 55 | + print(" at \(loc.file):\(loc.line)") |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// Access test failures |
| 60 | +for failure in result.testResults?.failures ?? [] { |
| 61 | + print("FAIL: \(failure.testClass).\(failure.testName)") |
| 62 | + print(" \(failure.message)") |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Parse Only Build Results |
| 67 | + |
| 68 | +```swift |
| 69 | +let parser = XCResultParser(path: "path/to/test.xcresult") |
| 70 | +let buildResults = try await parser.parseBuildResults() |
| 71 | + |
| 72 | +print("Warnings: \(buildResults.warningCount)") |
| 73 | +print("Errors: \(buildResults.errorCount)") |
| 74 | +``` |
| 75 | + |
| 76 | +### Parse Only Test Results |
| 77 | + |
| 78 | +```swift |
| 79 | +let parser = XCResultParser(path: "path/to/test.xcresult") |
| 80 | +let testResults = try await parser.parseTestResults() |
| 81 | + |
| 82 | +let summary = testResults.summary |
| 83 | +print("Total: \(summary.totalCount)") |
| 84 | +print("Passed: \(summary.passedCount)") |
| 85 | +print("Failed: \(summary.failedCount)") |
| 86 | +``` |
| 87 | + |
| 88 | +### Source Location Handling |
| 89 | + |
| 90 | +The library normalizes source locations from two different xcresulttool formats: |
| 91 | + |
| 92 | +```swift |
| 93 | +// Build issues provide absolute paths |
| 94 | +if let location = buildIssue.sourceLocation { |
| 95 | + let relativePath = location.relativePath(from: "/path/to/repo") |
| 96 | + print("\(relativePath):\(location.line)") |
| 97 | +} |
| 98 | + |
| 99 | +// Test failures provide filename and line |
| 100 | +for failure in testResults.failures { |
| 101 | + if let location = failure.sourceLocation { |
| 102 | + print("\(location.file):\(location.line)") |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## API Reference |
| 108 | + |
| 109 | +### XCResultParser |
| 110 | + |
| 111 | +```swift |
| 112 | +public final class XCResultParser: Sendable { |
| 113 | + public init(path: String) |
| 114 | + public func parse() async throws -> XCResult |
| 115 | + public func parseBuildResults() async throws -> BuildResults |
| 116 | + public func parseTestResults() async throws -> TestResults |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### Models |
| 121 | + |
| 122 | +- `XCResult` - Combined build and test results |
| 123 | +- `BuildResults` - Build action results with warnings, errors, analyzer warnings |
| 124 | +- `BuildIssue` - Individual build warning or error with source location |
| 125 | +- `TestResults` - Test execution results with device info and test node tree |
| 126 | +- `TestNode` - Hierarchical test node (test plan, bundle, suite, case, etc.) |
| 127 | +- `TestFailure` - Flattened test failure for easy reporting |
| 128 | +- `SourceLocation` - File path, line, and optional column |
| 129 | +- `TestResult` - Test outcome (passed, failed, skipped, expectedFailure) |
| 130 | +- `TestNodeType` - Node type in test hierarchy |
| 131 | +- `Severity` - Issue severity level (notice, warning, failure) |
| 132 | + |
| 133 | +## License |
| 134 | + |
| 135 | +MIT License - see [LICENSE](LICENSE) for details. |
0 commit comments