@@ -567,7 +567,7 @@ class TestProcess : XCTestCase {
567
567
568
568
func test_fileDescriptorsAreNotInherited( ) throws {
569
569
let task = Process ( )
570
- let clonedFD = dup ( 1 )
570
+ let someExtraFDs = [ dup ( 1 ) , dup ( 1 ) , dup ( 1 ) , dup ( 1 ) , dup ( 1 ) , dup ( 1 ) , dup ( 1 ) ]
571
571
task. executableURL = xdgTestHelperURL ( )
572
572
task. arguments = [ " --print-open-file-descriptors " ]
573
573
task. standardInput = FileHandle . nullDevice
@@ -576,13 +576,20 @@ class TestProcess : XCTestCase {
576
576
task. standardError = FileHandle . nullDevice
577
577
XCTAssertNoThrow ( try task. run ( ) )
578
578
579
- try task. run ( )
580
579
try stdoutPipe. fileHandleForWriting. close ( )
581
580
let stdoutData = try stdoutPipe. fileHandleForReading. readToEnd ( )
582
581
task. waitUntilExit ( )
583
- print ( String ( decoding: stdoutData ?? Data ( ) , as: Unicode . UTF8. self) )
584
- XCTAssertEqual ( " 0 \n 1 \n 2 \n " , String ( decoding: stdoutData ?? Data ( ) , as: Unicode . UTF8. self) )
585
- close ( clonedFD)
582
+ let stdoutString = String ( decoding: stdoutData ?? Data ( ) , as: Unicode . UTF8. self)
583
+ #if os(macOS)
584
+ XCTAssertEqual ( " 0 \n 1 \n 2 \n " , stdoutString)
585
+ #else
586
+ // on Linux we should also have a /dev/urandom open as well as some socket that Process uses for something.
587
+ XCTAssert ( stdoutString. utf8. starts ( with: " 0 \n 1 \n 2 \n 3 \n " . utf8) )
588
+ XCTAssertEqual ( stdoutString. components ( separatedBy: " \n " ) . count, 6 , " \( stdoutString) " )
589
+ #endif
590
+ for fd in someExtraFDs {
591
+ close ( fd)
592
+ }
586
593
}
587
594
588
595
static var allTests : [ ( String , ( TestProcess ) -> ( ) throws -> Void ) ] {
@@ -611,14 +618,14 @@ class TestProcess : XCTestCase {
611
618
( " test_redirect_all_using_null " , test_redirect_all_using_null) ,
612
619
( " test_redirect_all_using_nil " , test_redirect_all_using_nil) ,
613
620
( " test_plutil " , test_plutil) ,
614
- ( " test_fileDescriptorsAreNotInherited " , test_fileDescriptorsAreNotInherited) ,
615
621
]
616
622
617
623
#if !os(Windows)
618
624
// Windows doesn't have signals
619
625
tests += [
620
626
( " test_interrupt " , test_interrupt) ,
621
627
( " test_suspend_resume " , test_suspend_resume) ,
628
+ ( " test_fileDescriptorsAreNotInherited " , test_fileDescriptorsAreNotInherited) ,
622
629
]
623
630
#endif
624
631
return tests
0 commit comments