File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,14 @@ public struct Configuration: Sendable {
139139 taskFinishFlag. addOne ( )
140140 result = . success( bodyResult)
141141 } catch {
142+ let execution = Execution < Input , Output , Error > (
143+ processIdentifier: processIdentifier,
144+ inputWriter: nil ,
145+ outputStream: nil ,
146+ errorStream: nil
147+ )
148+ // Attempt to terminate the child process when the body throws
149+ await execution. teardown ( using: self . platformOptions. teardownSequence)
142150 result = . failure( error)
143151 }
144152
Original file line number Diff line number Diff line change @@ -3437,6 +3437,32 @@ extension SubprocessIntegrationTests {
34373437 #expect( output == [ " 100°C " , " 32—x " , " €5 " ] )
34383438 }
34393439 }
3440+
3441+ @Test func testSubprocessTearsdownChildProcessWhenBodyThrows( ) async throws {
3442+ struct MyError : Swift . Error { }
3443+
3444+ #if os(Windows)
3445+ let setup = TestSetup (
3446+ executable: . name( " powershell.exe " ) ,
3447+ arguments: [ " -Command " , " Start-Sleep -Seconds 9999 " ]
3448+ )
3449+ #else
3450+ let setup = TestSetup (
3451+ executable: . name( " tail " ) ,
3452+ arguments: [ " -f " , " /dev/null " ]
3453+ )
3454+ #endif
3455+ await #expect( throws: MyError . self) {
3456+ _ = try await _run (
3457+ setup,
3458+ input: . none,
3459+ output: . discarded,
3460+ error: . discarded
3461+ ) { execution in
3462+ throw MyError ( )
3463+ }
3464+ }
3465+ }
34403466}
34413467
34423468// MARK: - Utilities
You can’t perform that action at this time.
0 commit comments