Fix pipe deadlock in plugin and CLI integration tests
This commit is contained in:
parent
dd1cad2961
commit
cacd83dfe4
1 changed files with 15 additions and 2 deletions
|
|
@ -23,6 +23,8 @@ struct PluginGenerationTests {
|
|||
// Phase 1: Build the test package (triggers the plugin).
|
||||
// The plugin runs as a build-tool step before compilation;
|
||||
// generated files exist in .build/ even if compilation fails.
|
||||
let buildLog = URL(fileURLWithPath: "/tmp/test-plugin-build.log")
|
||||
try? FileManager.default.removeItem(at: buildLog)
|
||||
let buildProcess = Process()
|
||||
buildProcess.executableURL = URL(fileURLWithPath: "/usr/bin/swift")
|
||||
buildProcess.arguments = ["build"]
|
||||
|
|
@ -30,14 +32,20 @@ struct PluginGenerationTests {
|
|||
let buildPipe = Pipe()
|
||||
buildProcess.standardOutput = buildPipe
|
||||
buildProcess.standardError = buildPipe
|
||||
// Drain pipe to file in background to avoid buffer deadlock
|
||||
DispatchQueue.global().async {
|
||||
let data = buildPipe.fileHandleForReading.readDataToEndOfFile()
|
||||
try? data.write(to: buildLog)
|
||||
}
|
||||
try buildProcess.run()
|
||||
buildProcess.waitUntilExit()
|
||||
let buildOutput = (try? String(contentsOf: buildLog, encoding: .utf8)) ?? ""
|
||||
|
||||
|
||||
// Find generated Swift files under .build/ containing the "Generated by SwiftGtkGen" header
|
||||
let buildDir = pluginPkgDir.appendingPathComponent(".build")
|
||||
let generatedFiles = findGeneratedFiles(in: buildDir)
|
||||
|
||||
let buildOutput = String(data: buildPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
|
||||
if generatedFiles.isEmpty {
|
||||
Issue.record(
|
||||
"No generated files found. Build may not have triggered the plugin.\nBuild output:\n\(buildOutput)"
|
||||
|
|
@ -48,6 +56,7 @@ struct PluginGenerationTests {
|
|||
// Phase 2: Lint all generated files
|
||||
let configPath = "/home/echo/Projects/Swift/gtk-swift/swift-gtk-gen/.swift-format"
|
||||
for file in generatedFiles {
|
||||
let lintLog = URL(fileURLWithPath: "/tmp/test-plugin-lint.log")
|
||||
let lintProcess = Process()
|
||||
lintProcess.executableURL = URL(fileURLWithPath: "/usr/bin/swift")
|
||||
lintProcess.arguments = [
|
||||
|
|
@ -59,10 +68,14 @@ struct PluginGenerationTests {
|
|||
let lintPipe = Pipe()
|
||||
lintProcess.standardOutput = lintPipe
|
||||
lintProcess.standardError = lintPipe
|
||||
DispatchQueue.global().async {
|
||||
let data = lintPipe.fileHandleForReading.readDataToEndOfFile()
|
||||
try? data.write(to: lintLog)
|
||||
}
|
||||
try lintProcess.run()
|
||||
lintProcess.waitUntilExit()
|
||||
|
||||
let lintOutput = String(data: lintPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
|
||||
let lintOutput = (try? String(contentsOf: lintLog, encoding: .utf8)) ?? ""
|
||||
if lintProcess.terminationStatus != 0 {
|
||||
Issue.record("Lint failed for \(file.lastPathComponent):\n\(lintOutput)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue