Skip to content

Commit 4e026f0

Browse files
authored
Merge pull request #75 from swiftlang/eng/PR-fix-testSubprocessPlatfomOptionsPreSpawnProcessConfigurator
Make testSubprocessPlatfomOptionsPreSpawnProcessConfigurator more robust
2 parents 80bd50f + f481d20 commit 4e026f0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Tests/SubprocessTests/SubprocessTests+Linux.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,34 @@ import Testing
2727
// MARK: PlatformOption Tests
2828
@Suite(.serialized)
2929
struct SubprocessLinuxTests {
30-
@Test func testSubprocessPlatformOptionsPreSpawnProcessConfigurator() async throws {
30+
@Test(
31+
.enabled(
32+
if: getgid() == 0,
33+
"This test requires root privileges"
34+
)
35+
)
36+
func testSubprocessPlatformOptionsPreSpawnProcessConfigurator() async throws {
3137
var platformOptions = PlatformOptions()
3238
platformOptions.preSpawnProcessConfigurator = {
33-
setgid(4321)
39+
guard setgid(4321) == 0 else {
40+
// Returns EPERM when:
41+
// The calling process is not privileged (does not have the
42+
// CAP_SETGID capability in its user namespace), and gid does
43+
// not match the real group ID or saved set-group-ID of the
44+
// calling process.
45+
perror("setgid")
46+
abort()
47+
}
3448
}
3549
let idResult = try await Subprocess.run(
3650
.path("/usr/bin/id"),
3751
arguments: ["-g"],
3852
platformOptions: platformOptions,
39-
output: .string
53+
output: .string,
54+
error: .string
4055
)
56+
let error = try #require(idResult.standardError)
57+
try #require(error == "")
4158
#expect(idResult.terminationStatus.isSuccess)
4259
let id = try #require(idResult.standardOutput)
4360
#expect(

0 commit comments

Comments
 (0)