1
0
Fork 0
gobject-generator/Tests/SwiftGtkGenCLITests/CLITests.swift
Brendan Szymanski 1330f2bd25 Initial commit: SwiftGtkGen GIR-to-Swift binding generator
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.
2026-07-01 03:27:41 -04:00

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) ?? ""
}
}