From 7d5bd45ab22582220fcebdde8e9d11ec6f089338 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Thu, 12 Oct 2023 13:00:45 +0200 Subject: [PATCH] Add test_environment_isolation --- Tests/ShellOutTests/ShellOutTests.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/ShellOutTests/ShellOutTests.swift b/Tests/ShellOutTests/ShellOutTests.swift index 6aa8107..6e68845 100644 --- a/Tests/ShellOutTests/ShellOutTests.swift +++ b/Tests/ShellOutTests/ShellOutTests.swift @@ -267,6 +267,20 @@ final class ShellOutTests: XCTestCase { v0.1.0 """) } + + func test_environment_isolation() async throws { + setenv("TOKEN", "secret", 1) + defer { unsetenv("TOKEN") } + + await XCTAssertEqualAsync( + try await shellOut(to: "bash", arguments: ["-c", "echo $TOKEN"], + environment: ProcessInfo.processInfo.environment).stdout, "secret" + ) + await XCTAssertEqualAsync( + try await shellOut(to: "bash", arguments: ["-c", "echo $TOKEN"], + environment: [:]).stdout, "" + ) + } } extension ShellOutTests {