@@ -746,6 +746,10 @@ extension SubprocessUnixTests {
746
746
. enabled(
747
747
if: getgid ( ) == 0 ,
748
748
" 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) "
749
753
)
750
754
)
751
755
func testSubprocessPlatformOptionsProcessGroupID( ) async throws {
@@ -764,15 +768,19 @@ extension SubprocessUnixTests {
764
768
#expect( psResult. terminationStatus. isSuccess)
765
769
let resultValue = try #require(
766
770
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) " )
771
773
// PGID should == PID
772
- #expect( resultValue [ 2 ] == resultValue [ 3 ] )
774
+ #expect( match . output . pid == match . output . pgid )
773
775
}
774
776
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 {
776
784
guard #available( SubprocessSpan , * ) else {
777
785
return
778
786
}
@@ -941,19 +949,14 @@ internal func assertNewSessionCreated<Output: OutputProtocol>(
941
949
#expect( result. terminationStatus. isSuccess)
942
950
let psValue = try #require(
943
951
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) " )
948
954
// If setsid() has been called successfully, we shold observe:
949
955
// - pid == pgid
950
956
// - 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) )
957
960
#expect( pid == pgid)
958
961
#expect( tpgid <= 0 )
959
962
}
@@ -1009,11 +1012,14 @@ extension SubprocessUnixTests {
1009
1012
let limitString = limitResult
1010
1013
. standardOutput?
1011
1014
. trimmingCharacters ( in: . whitespacesAndNewlines) ,
1012
- let limit = Int ( limitString)
1015
+ let ulimit = Int ( limitString)
1013
1016
else {
1014
1017
Issue . record ( " Failed to run ulimit -n " )
1015
1018
return
1016
1019
}
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 )
1017
1023
// Since we open two pipes per `run`, launch
1018
1024
// limit / 4 subprocesses should reveal any
1019
1025
// file descriptor leaks
0 commit comments