Skip to content

Commit b9f0466

Browse files
committed
Add test for duplicate environment variables when invoking testsuite
Adds a simple test case that identifies and reports duplicate environment variables in the Cabal environment. For issue (#10718)
1 parent 2e8aaae commit b9f0466

File tree

9 files changed

+52
-7
lines changed

9 files changed

+52
-7
lines changed

Cabal/src/Distribution/Simple/Bench.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ bench args pkg_descr lbi flags = do
8888
dieWithException verbosity $
8989
NoBenchMarkProgram cmd
9090

91-
9291
-- Compute the appropriate environment for running the benchmark
9392
let progDb = LBI.withPrograms lbiForBench
9493
pathVar = progSearchPath progDb

Cabal/src/Distribution/Simple/Test/ExeV10.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ runTest pkg_descr lbi clbi hpcMarkupInfo flags suite = do
9595
(testOptions flags)
9696
tixFile = packageRoot (testCommonFlags flags) </> getSymbolicPath (tixFilePath distPref way (testName'))
9797

98-
shellEnv <- getFullEnvironment ([("PATH", Just newPath)]
99-
++ [("HPCTIXFILE", Just tixFile) | isCoverageEnabled]
100-
++ envOverrides)
98+
shellEnv <-
99+
getFullEnvironment
100+
( [("PATH", Just newPath)]
101+
++ [("HPCTIXFILE", Just tixFile) | isCoverageEnabled]
102+
++ envOverrides
103+
)
101104

102105
-- Add (DY)LD_LIBRARY_PATH if needed
103106
shellEnv' <-

Cabal/src/Distribution/Simple/Test/LibV09.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ runTest pkg_descr lbi clbi hpcMarkupInfo flags suite = do
103103
let opts = map (testOption pkg_descr lbi suite) $ testOptions flags
104104
tixFile = i $ tixFilePath distPref way testName'
105105

106-
shellEnv <- getFullEnvironment ([("PATH", Just newPath)]
107-
++ [("HPCTIXFILE", Just tixFile) | isCoverageEnabled]
108-
++ envOverrides)
106+
shellEnv <-
107+
getFullEnvironment
108+
( [("PATH", Just newPath)]
109+
++ [("HPCTIXFILE", Just tixFile) | isCoverageEnabled]
110+
++ envOverrides
111+
)
109112
-- Add (DY)LD_LIBRARY_PATH if needed
110113
shellEnv' <-
111114
if LBI.withDynExe lbi

cabal-testsuite/PackageTests/DuplicateEnvVars/cabal.out

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: p
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ recordMode DoNotRecord $ do
4+
res <- cabal' "test" ["all"]
5+
assertOutputContains "No duplicate environment variables found" res
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Main where
2+
3+
import Data.List (group, sort)
4+
import System.Environment (getEnvironment)
5+
6+
main = do
7+
env <- getEnvironment
8+
let sortedEnv = sort env
9+
duplicates = filter (\g -> length g > 1) $ group $ map fst sortedEnv
10+
11+
if null duplicates
12+
then putStrLn "No duplicate environment variables found."
13+
else do
14+
putStrLn "Found duplicate environment variables:"
15+
mapM_ (\d -> putStrLn $ " - " ++ head d) duplicates
16+
fail "Test failed due to duplicate environment variables"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cabal-version: 3.0
2+
name: p
3+
version: 0.1.0.0
4+
build-type: Simple
5+
6+
test-suite env-test
7+
default-language: Haskell2010
8+
type: exitcode-stdio-1.0
9+
main-is: Main.hs
10+
build-depends: base

changelog.d/pr-10827.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
synopsis: "Fix duplicate environment variables in test and benchmark runs"
3+
packages: [Cabal, cabal-install]
4+
prs: 10827
5+
issues: 10718
6+
---
7+
8+
Cabal no longer creates duplicate environment variables when running test suites, benchmarks, or internal executables. Previously, when setting up the environment for these processes, Cabal would append the overridden environment to the existing environment, creating duplicates of the same variable.

0 commit comments

Comments
 (0)