@@ -696,6 +696,33 @@ class TestProcess : XCTestCase {
696
696
}
697
697
}
698
698
699
+ func test_pipeCloseBeforeLaunch( ) {
700
+ let process = Process ( )
701
+ let stdInput = Pipe ( )
702
+ let stdOutput = Pipe ( )
703
+
704
+ process. executableURL = xdgTestHelperURL ( )
705
+ process. arguments = [ " --cat " ]
706
+ process. standardInput = stdInput
707
+ process. standardOutput = stdOutput
708
+
709
+ let string = " Hello, World "
710
+ let stdInputPipe = stdInput. fileHandleForWriting
711
+ XCTAssertNoThrow ( try stdInputPipe. write ( XCTUnwrap ( string. data ( using: . utf8) ) ) )
712
+ stdInputPipe. closeFile ( )
713
+
714
+ XCTAssertNoThrow ( try process. run ( ) )
715
+ process. waitUntilExit ( )
716
+
717
+ let stdOutputPipe = stdOutput. fileHandleForReading
718
+ do {
719
+ let readData = try XCTUnwrap ( stdOutputPipe. readToEnd ( ) )
720
+ let readString = String ( data: readData, encoding: . utf8)
721
+ XCTAssertEqual ( string, readString)
722
+ } catch {
723
+ XCTFail ( " \( error) " )
724
+ }
725
+ }
699
726
700
727
static var allTests : [ ( String , ( TestProcess ) -> ( ) throws -> Void ) ] {
701
728
var tests = [
@@ -724,6 +751,7 @@ class TestProcess : XCTestCase {
724
751
( " test_redirect_all_using_nil " , test_redirect_all_using_nil) ,
725
752
( " test_plutil " , test_plutil) ,
726
753
( " test_currentDirectory " , test_currentDirectory) ,
754
+ ( " test_pipeCloseBeforeLaunch " , test_pipeCloseBeforeLaunch)
727
755
]
728
756
729
757
#if !os(Windows)
0 commit comments