Skip to content

Commit

Permalink
Create ParsingCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Dec 19, 2024
1 parent ef6e251 commit 7a67e86
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ let package = Package(
"XMLCoder",
]
),
.executableTarget(
name: "ParsingCheck",
dependencies: [
"XcbeautifyLib",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.testTarget(
name: "XcbeautifyLibTests",
dependencies: ["XcbeautifyLib"],
Expand Down
48 changes: 48 additions & 0 deletions Sources/ParsingCheck/ParsingCheck.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import ArgumentParser
import Darwin
import Foundation
import XcbeautifyLib

@main
struct ParsingCheck: ParsableCommand {

@Option
var filePath: String

@Option
var uncapturedOutput: Int

enum ParsingCheckError: Error {
case dataReadError
case noData
case regression(Int)
}

func run() throws {
guard let data = FileManager.default.contents(atPath: filePath) else {
throw ParsingCheckError.noData
}

guard !data.isEmpty else {
throw ParsingCheckError.noData
}

var buildLog: [String] = String(decoding: data, as: UTF8.self)
.components(separatedBy: .newlines)

let parser = Parser()

var uncapturedOutput = 0

while !buildLog.isEmpty {
let line = buildLog.removeFirst()
if !line.isEmpty, parser.parse(line: line) == nil {
uncapturedOutput += 1
}
}

guard self.uncapturedOutput == uncapturedOutput else {
throw ParsingCheckError.regression(uncapturedOutput)
}
}
}

0 comments on commit 7a67e86

Please sign in to comment.