Skip to content

Commit 075ba0e

Browse files
committed
Fix tests and add more normalizers
1 parent 6553de5 commit 075ba0e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cabal-testsuite/PackageTests/Path/All/cabal.out

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# cabal path
2-
Resolving dependencies...
32
compiler-flavour: ghc
43
compiler-id: ghc-<GHCVER>
5-
compiler-path: /home/hugin/.ghcup/bin/ghc
4+
compiler-path: <GHCPATH>
65
cache-dir: <ROOT>/cabal.dist/home/.cabal/packages
76
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
87
store-dir: <ROOT>/cabal.dist/home/.cabal/store

cabal-testsuite/src/Test/Cabal/Monad.hs

+8
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ runTestM mode m =
300300
program_db1
301301
verbosity
302302

303+
ghcLocation <- case lookupProgramByName "ghc" program_db2 of
304+
Nothing -> fail "runTestM.lookupProgramByName: No location for 'ghc' was found"
305+
Just ghcProg -> pure $ programPath ghcProg
306+
303307
program_db3 <-
304308
reconfigurePrograms verbosity
305309
([("cabal", p) | p <- maybeToList (argCabalInstallPath cargs)] ++
@@ -321,6 +325,7 @@ runTestM mode m =
321325
testProgramDb = program_db,
322326
testPlatform = platform,
323327
testCompiler = comp,
328+
testCompilerPath = ghcLocation,
324329
testPackageDBStack = db_stack,
325330
testVerbosity = verbosity,
326331
testMtimeChangeDelay = Nothing,
@@ -538,6 +543,8 @@ mkNormalizerEnv = do
538543
= addTrailingPathSeparator tmpDir,
539544
normalizerGhcVersion
540545
= compilerVersion (testCompiler env),
546+
normalizerGhcPath
547+
= testCompilerPath env,
541548
normalizerKnownPackages
542549
= mapMaybe simpleParse (words list_out),
543550
normalizerPlatform
@@ -607,6 +614,7 @@ data TestEnv = TestEnv
607614
, testProgramDb :: ProgramDb
608615
-- | Compiler we are running tests for
609616
, testCompiler :: Compiler
617+
, testCompilerPath :: FilePath
610618
-- | Platform we are running tests on
611619
, testPlatform :: Platform
612620
-- | Package database stack (actually this changes lol)

cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Text.Regex.TDFA
1616
import Data.Array ((!))
1717

1818
import qualified Data.Foldable as F
19+
import System.FilePath (dropExtension)
1920

2021
normalizeOutput :: NormalizerEnv -> String -> String
2122
normalizeOutput nenv =
@@ -50,6 +51,7 @@ normalizeOutput nenv =
5051
-- Normalize architecture
5152
. resub (posixRegexEscape (display (normalizerPlatform nenv))) "<ARCH>"
5253
. normalizeBuildInfoJson
54+
. normalizePathCmdOutput
5355
-- Some GHC versions are chattier than others
5456
. resub "^ignoring \\(possibly broken\\) abi-depends field for packages" ""
5557
-- Normalize the current GHC version. Apply this BEFORE packageIdRegex,
@@ -70,12 +72,19 @@ normalizeOutput nenv =
7072
resub (posixRegexEscape (display pid) ++ "(-[A-Za-z0-9.-]+)?")
7173
(prettyShow (packageName pid) ++ "-<VERSION>")
7274

75+
normalizePathCmdOutput =
76+
-- clear the ghc path out of all supported output formats
77+
resub ("compiler-path: " <> posixRegexEscape (dropExtension (normalizerGhcPath nenv)))
78+
"compiler-path: <GHCPATH>"
79+
. resub ("\"compiler-path\"\\s*:\\s*\"" <> posixRegexEscape (normalizerGhcPath nenv) <> "\"")
80+
"\"compiler-path\": \"<GHCPATH>\""
81+
7382
-- 'build-info.json' contains a plethora of host system specific information.
7483
--
7584
-- This must happen before the root-dir normalisation.
7685
normalizeBuildInfoJson =
7786
-- Remove ghc path from show-build-info output
78-
resub ("\"path\":\"[^\"]*\"}")
87+
resub ("\"path\":\"" <> posixRegexEscape (normalizerGhcPath nenv) <> "\"}")
7988
"\"path\":\"<GHCPATH>\"}"
8089
-- Remove cabal version output from show-build-info output
8190
. resub ("{\"cabal-version\":\"" ++ posixRegexEscape (display (normalizerCabalVersion nenv)) ++ "\"")
@@ -104,6 +113,7 @@ data NormalizerEnv = NormalizerEnv
104113
-- `/var` is a symlink for `/private/var`.
105114
, normalizerGblTmpDir :: FilePath
106115
, normalizerGhcVersion :: Version
116+
, normalizerGhcPath :: FilePath
107117
, normalizerKnownPackages :: [PackageId]
108118
, normalizerPlatform :: Platform
109119
, normalizerCabalVersion :: Version

cabal-testsuite/src/Test/Cabal/Prelude.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,11 @@ cabalGArgs global_args cmd args input = do
302302
, "info"
303303
, "init"
304304
, "haddock-project"
305-
, "path"
306305
]
307306
= [ ]
308307

309308
-- new-build commands are affected by testCabalProjectFile
310-
| cmd == "v2-sdist"
309+
| cmd `elem` ["v2-sdist", "path"]
311310
= [ "--project-file=" ++ fp | Just fp <- [testCabalProjectFile env] ]
312311

313312
| cmd == "v2-clean"

0 commit comments

Comments
 (0)