Skip to content

Commit 1101f5c

Browse files
committed
[SwiftTestTool] Print message when text exits via signal
- https://bugs.swift.org/browse/SR-4754 - <rdar://problem/31940383> [SR-4754]: [XCTest] Non-zero exit without further output
1 parent 45e33ae commit 1101f5c

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,20 @@ final class TestRunner {
349349
/// and second argument containing the output of the execution.
350350
func test() -> (Bool, String) {
351351
var output = ""
352-
var success = true
352+
var success = false
353353
do {
354354
let process = Process(arguments: args(), redirectOutput: true, verbose: false)
355355
try process.launch()
356356
let result = try process.waitUntilExit()
357357
output = try (result.utf8Output() + result.utf8stderrOutput()).chuzzle() ?? ""
358-
success = result.exitStatus == .terminated(code: 0)
359-
} catch {
360-
success = false
361-
}
358+
switch result.exitStatus {
359+
case .terminated(code: 0):
360+
success = true
361+
case .signalled(let signal):
362+
output += "\n" + exitSignalText(code: signal)
363+
default: break
364+
}
365+
} catch {}
362366
return (success, output)
363367
}
364368

@@ -369,10 +373,19 @@ final class TestRunner {
369373
try processSet.add(process)
370374
try process.launch()
371375
let result = try process.waitUntilExit()
372-
return result.exitStatus == .terminated(code: 0)
373-
} catch {
374-
return false
375-
}
376+
switch result.exitStatus {
377+
case .terminated(code: 0):
378+
return true
379+
case .signalled(let signal):
380+
print(exitSignalText(code: signal))
381+
default: break
382+
}
383+
} catch {}
384+
return false
385+
}
386+
387+
private func exitSignalText(code: Int32) -> String {
388+
return "Exited with signal code \(code)"
376389
}
377390
}
378391

@@ -494,6 +507,9 @@ final class ParallelTestRunner {
494507
for error in failureOutput {
495508
stdoutStream <<< error
496509
}
510+
if !failureOutput.isEmpty {
511+
stdoutStream <<< "\n"
512+
}
497513
stdoutStream.flush()
498514
}
499515
}

0 commit comments

Comments
 (0)