Skip to content

Commit

Permalink
Fix tests and add more normalizers
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Mar 10, 2024
1 parent 65993bc commit 4b95b78
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cabal-testsuite/PackageTests/Path/All/cabal.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# cabal path
Resolving dependencies...
compiler-flavour: ghc
compiler-id: ghc-<GHCVER>
compiler-path: /home/hugin/.ghcup/bin/ghc
compiler-path: <GHCPATH>
cache-dir: <ROOT>/cabal.dist/home/.cabal/packages
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
store-dir: <ROOT>/cabal.dist/home/.cabal/store
Expand Down
8 changes: 8 additions & 0 deletions cabal-testsuite/src/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ runTestM mode m =
program_db1
verbosity

ghcLocation <- case lookupProgramByName "ghc" program_db2 of
Nothing -> fail "runTestM.lookupProgramByName: No location for 'ghc' was found"
Just ghcProg -> pure $ programPath ghcProg

program_db3 <-
reconfigurePrograms verbosity
([("cabal", p) | p <- maybeToList (argCabalInstallPath cargs)] ++
Expand All @@ -321,6 +325,7 @@ runTestM mode m =
testProgramDb = program_db,
testPlatform = platform,
testCompiler = comp,
testCompilerPath = ghcLocation,
testPackageDBStack = db_stack,
testVerbosity = verbosity,
testMtimeChangeDelay = Nothing,
Expand Down Expand Up @@ -536,6 +541,8 @@ mkNormalizerEnv = do
= addTrailingPathSeparator tmpDir,
normalizerGhcVersion
= compilerVersion (testCompiler env),
normalizerGhcPath
= testCompilerPath env,
normalizerKnownPackages
= mapMaybe simpleParse (words list_out),
normalizerPlatform
Expand Down Expand Up @@ -605,6 +612,7 @@ data TestEnv = TestEnv
, testProgramDb :: ProgramDb
-- | Compiler we are running tests for
, testCompiler :: Compiler
, testCompilerPath :: FilePath
-- | Platform we are running tests on
, testPlatform :: Platform
-- | Package database stack (actually this changes lol)
Expand Down
13 changes: 11 additions & 2 deletions cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ normalizeOutput nenv =
"/incoming/new-<RAND>"
-- Normalize architecture
. resub (posixRegexEscape (display (normalizerPlatform nenv))) "<ARCH>"
. normalizeBuildInfoJson
-- Some GHC versions are chattier than others
. resub "^ignoring \\(possibly broken\\) abi-depends field for packages" ""
-- Normalize the current GHC version. Apply this BEFORE packageIdRegex,
Expand All @@ -63,19 +62,28 @@ normalizeOutput nenv =
++ "(-[a-z0-9]+)?")
"<GHCVER>"
else id)
. normalizeBuildInfoJson
. normalizePathCmdOutput
-- hackage-security locks occur non-deterministically
. resub "(Released|Acquired|Waiting) .*hackage-security-lock\n" ""
where
packageIdRegex pid =
resub (posixRegexEscape (display pid) ++ "(-[A-Za-z0-9.-]+)?")
(prettyShow (packageName pid) ++ "-<VERSION>")

normalizePathCmdOutput =
-- clear the ghc path out of all supported output formats
resub ("compiler-path: " <> posixRegexEscape (normalizerGhcPath nenv))
"compiler-path: <GHCPATH>"
. resub ("\"compiler-path\"\\s*:\\s*\"" <> posixRegexEscape (normalizerGhcPath nenv) <> "\"")
"\"compiler-path\": \"<GHCPATH>\""

-- 'build-info.json' contains a plethora of host system specific information.
--
-- This must happen before the root-dir normalisation.
normalizeBuildInfoJson =
-- Remove ghc path from show-build-info output
resub ("\"path\":\"[^\"]*\"}")
resub ("\"path\":\"" <> posixRegexEscape (normalizerGhcPath nenv) <> "\"}")
"\"path\":\"<GHCPATH>\"}"
-- Remove cabal version output from show-build-info output
. resub ("{\"cabal-version\":\"" ++ posixRegexEscape (display (normalizerCabalVersion nenv)) ++ "\"")
Expand Down Expand Up @@ -104,6 +112,7 @@ data NormalizerEnv = NormalizerEnv
-- `/var` is a symlink for `/private/var`.
, normalizerGblTmpDir :: FilePath
, normalizerGhcVersion :: Version
, normalizerGhcPath :: FilePath
, normalizerKnownPackages :: [PackageId]
, normalizerPlatform :: Platform
, normalizerCabalVersion :: Version
Expand Down
3 changes: 1 addition & 2 deletions cabal-testsuite/src/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,11 @@ cabalGArgs global_args cmd args input = do
, "info"
, "init"
, "haddock-project"
, "path"
]
= [ ]

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

| cmd == "v2-clean"
Expand Down

0 comments on commit 4b95b78

Please sign in to comment.