diff --git a/Tests/IntegrationTests/PluginGenerationTests.swift b/Tests/IntegrationTests/PluginGenerationTests.swift index dca7be1..08a2753 100644 --- a/Tests/IntegrationTests/PluginGenerationTests.swift +++ b/Tests/IntegrationTests/PluginGenerationTests.swift @@ -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)") }