Skip to content

Commit 43823ca

Browse files
authored
Introduce ParsingTests (#235)
Introduce a unit test that parsers an entire build log. The build log represents a clean build of Backyard Birds on Xcode 15.1.
1 parent 84d24a9 commit 43823ca

File tree

3 files changed

+3161
-1
lines changed

3 files changed

+3161
-1
lines changed

Package.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ let package = Package(
3838
),
3939
.testTarget(
4040
name: "XcbeautifyLibTests",
41-
dependencies: ["XcbeautifyLib"]
41+
dependencies: ["XcbeautifyLib"],
42+
resources: [
43+
.copy("ParsingTests/clean_build_xcode_15_1.txt"),
44+
]
4245
),
4346
]
4447
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import XCTest
2+
@testable import XcbeautifyLib
3+
4+
final class ParsingTests: XCTestCase {
5+
func testCleanBuildXcode15_1() throws {
6+
let url = Bundle.module.url(forResource: "clean_build_xcode_15_1", withExtension: "txt")!
7+
8+
var buildLog: [String] = try String(contentsOf: url)
9+
.components(separatedBy: .newlines)
10+
11+
let parser = Parser(
12+
colored: false,
13+
renderer: .terminal,
14+
preserveUnbeautifiedLines: false,
15+
additionalLines: {
16+
guard !buildLog.isEmpty else {
17+
XCTFail("The build log should never be empty when fetching additional lines.")
18+
return nil
19+
}
20+
return buildLog.removeFirst()
21+
}
22+
)
23+
24+
var uncapturedOutput = 0
25+
26+
while !buildLog.isEmpty {
27+
let line = buildLog.removeFirst()
28+
if !line.isEmpty, parser.parse(line: line) == nil {
29+
uncapturedOutput += 1
30+
}
31+
}
32+
33+
// The following is a magic number.
34+
// It represents the number of lines that aren't captured by the Parser.
35+
// Slowly, this value should decrease until it reaches 0.
36+
// It uses `XCTAssertEqual` instead of `XCTAssertLessThanOrEqual` as a reminder.
37+
// Update this magic number whenever `uncapturedOutput` is less than the current magic number.
38+
// There's a regression whenever `uncapturedOutput` is greater than the current magic number.
39+
XCTAssertEqual(uncapturedOutput, 2218)
40+
}
41+
}

0 commit comments

Comments
 (0)