From a84311ac397d851b21a5c95ffeb44005ef9262f7 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 30 Mar 2020 18:21:25 +0200 Subject: [PATCH] Change withEnv to not clear the whole env (#5281) The way we use `withEnv` it is really intended to set a few environment variables in an already existing environment instead of clearing everything before. This PR changes it to do only that. changelog_begin changelog_end closes #5280 --- daml-assistant/test/DA/Daml/Assistant/Tests.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/daml-assistant/test/DA/Daml/Assistant/Tests.hs b/daml-assistant/test/DA/Daml/Assistant/Tests.hs index 785d8595db..e28ba0f1dd 100644 --- a/daml-assistant/test/DA/Daml/Assistant/Tests.hs +++ b/daml-assistant/test/DA/Daml/Assistant/Tests.hs @@ -33,7 +33,9 @@ import qualified Data.Conduit.Tar as Tar -- unix specific import System.PosixCompat.Files (createSymbolicLink) --- | Replace all environment variables for test action, then restore them. +-- | Set the given environment variables, then restore them. +-- Envirnoment variables not in the given list are unmodified. +-- -- Avoids System.Environment.setEnv because it treats empty strings as -- "delete environment variable", unlike main-tester's withEnv which -- consequently conflates (Just "") with Nothing. @@ -41,11 +43,7 @@ withEnv :: [(String, Maybe String)] -> IO t -> IO t withEnv vs m = bracket pushEnv popEnv (const m) where pushEnv :: IO [(String, Maybe String)] - pushEnv = do - oldEnv <- getEnvironment - let ks = map fst vs - vs' = [(key, Nothing) | (key, _) <- oldEnv, key `notElem` ks] ++ vs - replaceEnv vs' + pushEnv = replaceEnv vs popEnv :: [(String, Maybe String)] -> IO () popEnv vs' = void $ replaceEnv vs'