@@ -746,6 +746,10 @@ extension SubprocessUnixTests {
746746 . enabled(
747747 if: getgid ( ) == 0 ,
748748 " This test requires root privileges "
749+ ) ,
750+ . enabled(
751+ if: ( try ? Executable . name ( " ps " ) . resolveExecutablePath ( in: . inherit) ) != nil ,
752+ " This test requires ps (install procps package on Debian or RedHat Linux distros) "
749753 )
750754 )
751755 func testSubprocessPlatformOptionsProcessGroupID( ) async throws {
@@ -764,15 +768,19 @@ extension SubprocessUnixTests {
764768 #expect( psResult. terminationStatus. isSuccess)
765769 let resultValue = try #require(
766770 psResult. standardOutput
767- ) . split { $0. isWhitespace || $0. isNewline }
768- #expect( resultValue. count == 4 )
769- #expect( resultValue [ 0 ] == " PID " )
770- #expect( resultValue [ 1 ] == " PGID " )
771+ )
772+ let match = try #require( try #/\s*PID\s*PGID\s*(?<pid>[\-]?[0-9]+)\s*(?<pgid>[\-]?[0-9]+)\s*/# . wholeMatch ( in: resultValue) , " ps output was in an unexpected format: \n \n \( resultValue) " )
771773 // PGID should == PID
772- #expect( resultValue [ 2 ] == resultValue [ 3 ] )
774+ #expect( match . output . pid == match . output . pgid )
773775 }
774776
775- @Test func testSubprocessPlatformOptionsCreateSession( ) async throws {
777+ @Test (
778+ . enabled(
779+ if: ( try ? Executable . name ( " ps " ) . resolveExecutablePath ( in: . inherit) ) != nil ,
780+ " This test requires ps (install procps package on Debian or RedHat Linux distros) "
781+ )
782+ )
783+ func testSubprocessPlatformOptionsCreateSession( ) async throws {
776784 guard #available( SubprocessSpan , * ) else {
777785 return
778786 }
@@ -941,19 +949,14 @@ internal func assertNewSessionCreated<Output: OutputProtocol>(
941949 #expect( result. terminationStatus. isSuccess)
942950 let psValue = try #require(
943951 result. standardOutput
944- ) . split {
945- return $0. isNewline || $0. isWhitespace
946- }
947- #expect( psValue. count == 6 )
952+ )
953+ let match = try #require( try #/\s*PID\s*PGID\s*TPGID\s*(?<pid>[\-]?[0-9]+)\s*(?<pgid>[\-]?[0-9]+)\s*(?<tpgid>[\-]?[0-9]+)\s*/# . wholeMatch ( in: psValue) , " ps output was in an unexpected format: \n \n \( psValue) " )
948954 // If setsid() has been called successfully, we shold observe:
949955 // - pid == pgid
950956 // - tpgid <= 0
951- #expect( psValue [ 0 ] == " PID " )
952- #expect( psValue [ 1 ] == " PGID " )
953- #expect( psValue [ 2 ] == " TPGID " )
954- let pid = try #require( Int ( psValue [ 3 ] ) )
955- let pgid = try #require( Int ( psValue [ 4 ] ) )
956- let tpgid = try #require( Int ( psValue [ 5 ] ) )
957+ let pid = try #require( Int ( match. output. pid) )
958+ let pgid = try #require( Int ( match. output. pgid) )
959+ let tpgid = try #require( Int ( match. output. tpgid) )
957960 #expect( pid == pgid)
958961 #expect( tpgid <= 0 )
959962}
@@ -1009,11 +1012,14 @@ extension SubprocessUnixTests {
10091012 let limitString = limitResult
10101013 . standardOutput?
10111014 . trimmingCharacters ( in: . whitespacesAndNewlines) ,
1012- let limit = Int ( limitString)
1015+ let ulimit = Int ( limitString)
10131016 else {
10141017 Issue . record ( " Failed to run ulimit -n " )
10151018 return
10161019 }
1020+ // Constrain to an ultimate upper limit of 4096, since Docker containers can have limits like 2^20 which is a bit too high for this test.
1021+ // Common defaults are 2560 for macOS and 1024 for Linux.
1022+ let limit = min ( ulimit, 4096 )
10171023 // Since we open two pipes per `run`, launch
10181024 // limit / 4 subprocesses should reveal any
10191025 // file descriptor leaks
0 commit comments