1
0
Fork 0
gobject-generator/Tests/GObjectGeneratorCLITests/CLITests.swift

41 lines
1.2 KiB
Swift

import Testing
import Foundation
@Test("CLI produces help output")
func testCLIHelp() throws {
let process = Process()
let binPath = findBinary() ?? failBinaryNotFound()
process.executableURL = binPath
process.arguments = ["--help"]
let output = try process.runAndCapture()
#expect(output.contains("Usage:"))
#expect(output.contains("--monorepo-config"))
#expect(output.contains("--output"))
#expect(output.contains("--skip-report"))
}
private func findBinary() -> URL? {
let candidates = [
URL(fileURLWithPath: ".build/debug/generator"),
URL(fileURLWithPath: ".build/release/generator"),
]
return candidates.first { FileManager.default.fileExists(atPath: $0.path) }
}
private func failBinaryNotFound() -> URL {
Issue.record("generator binary not found at any expected path")
return URL(fileURLWithPath: "/nonexistent")
}
extension Process {
func runAndCapture() throws -> String {
let stdout = Pipe()
standardOutput = stdout
standardError = Pipe()
try run()
waitUntilExit()
let data = stdout.fileHandleForReading.readDataToEndOfFile()
return String(data: data, encoding: .utf8) ?? ""
}
}