Extracted from gtk-swift monorepo. Previous history contains 38 commits across the full Phase 1 development including GIR XML parsing, IR model, analysis engine, code generation, CLI, plugins, and documentation.
41 lines
1.3 KiB
Swift
41 lines
1.3 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("--library"))
|
|
#expect(output.contains("--output"))
|
|
}
|
|
|
|
private func findBinary() -> URL? {
|
|
let candidates = [
|
|
URL(fileURLWithPath: ".build/debug/swift-gtk-gen"),
|
|
URL(fileURLWithPath: "generator/.build/debug/swift-gtk-gen"),
|
|
URL(fileURLWithPath: ".build/release/swift-gtk-gen"),
|
|
URL(fileURLWithPath: "generator/.build/release/swift-gtk-gen"),
|
|
]
|
|
return candidates.first { FileManager.default.fileExists(atPath: $0.path) }
|
|
}
|
|
|
|
private func failBinaryNotFound() -> URL {
|
|
Issue.record("swift-gtk-gen 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) ?? ""
|
|
}
|
|
}
|