this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Split stdout/stderr for test command runner

onevcat 858a2388 66647b82

+20 -13
+20 -13
Tests/TestUtilities.swift
··· 6 6 let defaultSimulatorUDID = ProcessInfo.processInfo.environment["SIMULATOR_UDID"] 7 7 8 8 struct CommandOutput { 9 - let output: String 9 + let stdout: String 10 + let stderr: String 10 11 let exitCode: Int32 12 + 13 + var output: String { 14 + stdout + (stderr.isEmpty ? "" : "\n\(stderr)") 15 + } 11 16 } 12 17 13 18 struct CommandRunner { 14 - static func run(_ command: String) async throws -> (output: String, exitCode: Int32) { 19 + static func run(_ command: String) async throws -> CommandOutput { 15 20 let process = Process() 16 21 process.executableURL = URL(fileURLWithPath: "/bin/bash") 17 22 process.arguments = ["-c", command] ··· 26 31 27 32 let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() 28 33 let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile() 29 - let output = String(data: outputData, encoding: .utf8) ?? "" 30 - let error = String(data: errorData, encoding: .utf8) ?? "" 34 + let stdout = String(data: outputData, encoding: .utf8) ?? "" 35 + let stderr = String(data: errorData, encoding: .utf8) ?? "" 31 36 32 - let combinedOutput = output + (error.isEmpty ? "" : "\n\(error)") 37 + let combinedOutput = stdout + (stderr.isEmpty ? "" : "\n\(stderr)") 33 38 34 39 if process.terminationStatus != 0 { 35 40 throw NSError( ··· 39 44 ) 40 45 } 41 46 42 - return (combinedOutput, process.terminationStatus) 47 + return CommandOutput(stdout: stdout, stderr: stderr, exitCode: process.terminationStatus) 43 48 } 44 49 } 45 50 ··· 78 83 79 84 struct UIStateParser { 80 85 static func parseDescribeUIOutput(_ jsonString: String) throws -> UIElement { 81 - // The describe-ui command outputs a header "Accessibility Information (JSON):" 86 + // The describe-ui command outputs a header "Accessibility Information (JSON):" 82 87 // followed by the JSON array. We need to extract just the JSON part. 83 88 var jsonContent = jsonString 84 89 ··· 184 189 185 190 // Check if the command failed 186 191 if result.exitCode != 0 { 187 - throw TestError.unexpectedState("axe describe-ui command failed with exit code \(result.exitCode). Output: \(result.output)") 192 + let output = result.stdout + (result.stderr.isEmpty ? "" : "\n\(result.stderr)") 193 + throw TestError.unexpectedState("axe describe-ui command failed with exit code \(result.exitCode). Output: \(output)") 188 194 } 189 195 190 - return try UIStateParser.parseDescribeUIOutput(result.output) 196 + return try UIStateParser.parseDescribeUIOutput(result.stdout) 191 197 } 192 198 193 199 @discardableResult ··· 199 205 200 206 // Use the built executable directly for faster test execution 201 207 let axePath = try getAxePath() 202 - let (output, exitCode) = try await CommandRunner.run("\(axePath) \(fullCommand)") 208 + let result = try await CommandRunner.run("\(axePath) \(fullCommand)") 203 209 204 210 // Check if the command failed 205 - if exitCode != 0 { 206 - throw TestError.unexpectedState("axe command '\(fullCommand)' failed with exit code \(exitCode). Output: \(output)") 211 + if result.exitCode != 0 { 212 + let output = result.stdout + (result.stderr.isEmpty ? "" : "\n\(result.stderr)") 213 + throw TestError.unexpectedState("axe command '\(fullCommand)' failed with exit code \(result.exitCode). Output: \(output)") 207 214 } 208 215 209 - return CommandOutput(output: output, exitCode: exitCode) 216 + return result 210 217 } 211 218 } 212 219