Skip to content

Commit a6b0d4c

Browse files
committed
Deduplicate config file path calculation in test.
1 parent 4f8aeb2 commit a6b0d4c

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Cabal-tests/Cabal-tests.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ test-suite hackage-tests
160160
, bytestring
161161
, Cabal
162162
, Cabal-tree-diff
163+
, cabal-install
163164
, containers
164165
, deepseq
165166
, directory

Cabal-tests/tests/HackageTests.hs

+5-13
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ import Data.Foldable (traverse_)
2020
import Data.List (isPrefixOf, isSuffixOf)
2121
import Data.Maybe (mapMaybe)
2222
import Data.Monoid (Sum (..))
23+
import Distribution.Client.Config (defaultConfigFile, defaultCacheDir)
2324
import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage)
2425
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
2526
import Distribution.PackageDescription.Quirks (patchQuirks)
2627
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS)
2728
import Numeric (showFFloat)
28-
import System.Directory (getAppUserDataDirectory)
29-
import System.Environment (lookupEnv)
3029
import System.Exit (exitFailure)
3130
import System.FilePath ((</>))
3231

@@ -63,22 +62,15 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
6362
parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool)
6463
-> (FilePath -> B.ByteString -> IO a) -> IO a
6564
parseIndex predicate action = do
66-
cabalDir <- getAppUserDataDirectory "cabal"
67-
configPath <- getCabalConfigPath cabalDir
65+
configPath <- defaultConfigFile
6866
cfg <- B.readFile configPath
6967
cfgFields <- either (fail . show) pure $ Parsec.readFields cfg
68+
repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of
69+
[] -> defaultCacheDir -- Default
70+
(rrc : _) -> return rrc -- User-specified
7071
let repos = reposFromConfig cfgFields
71-
repoCache = case lookupInConfig "remote-repo-cache" cfgFields of
72-
[] -> cabalDir </> "packages" -- Default
73-
(rrc : _) -> rrc -- User-specified
7472
tarName repo = repoCache </> repo </> "01-index.tar"
7573
mconcat <$> traverse (parseIndex' predicate action . tarName) repos
76-
where
77-
getCabalConfigPath cabalDir = do
78-
mx <- lookupEnv "CABAL_CONFIG"
79-
case mx of
80-
Just x -> return x
81-
Nothing -> return (cabalDir </> "config")
8274

8375

8476
parseIndex'

0 commit comments

Comments
 (0)