From d9e795dcda8996ece3ae773ce3cb8c2cb8c0e7eb Mon Sep 17 00:00:00 2001 From: brandon s allbery kf8nh Date: Tue, 16 Jul 2024 19:04:56 -0400 Subject: [PATCH] make cabal-install integration tests hermetic They were using the user's config, which is a problem if they don't have one or if it contains settings that interfere with tests (such as `documentation: True`). I'm not entirely certain of this, but it seems to work here. It's a bit of a hack, though. --- .gitignore | 1 + cabal-install/cabal-install.cabal | 1 + cabal-install/tests/IntegrationTests2.hs | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 957786d7055..99c89254ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ bootstrap/*.plan.json /cabal-install/dist/ /cabal-install/Setup /cabal-install/source-file-list +/cabal-install/tests/IntegrationTests2/config/cabal-config .stylish-haskell.yaml .stylish-haskell.yml diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 5f20b3db947..9d307b4e1c6 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -399,6 +399,7 @@ test-suite integration-tests2 containers, directory, filepath, + process, tasty >= 1.2.3 && <1.6, tasty-hunit >= 0.10, tagged diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index c4341ed72ef..76ba1638078 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -74,7 +74,9 @@ import Control.Concurrent (threadDelay) import Control.Exception hiding (assert) import System.FilePath import System.Directory +import System.Environment (setEnv) import System.IO (hPutStrLn, stderr) +import System.Process (callProcess) import Test.Tasty import Test.Tasty.HUnit @@ -93,7 +95,16 @@ removePathForcibly = removeDirectoryRecursive #endif main :: IO () -main = +main = do + -- this is needed to ensure tests aren't affected by the user's cabal config + cwd <- getCurrentDirectory + let configDir = cwd basedir "config" "cabal-config" + setEnv "HOME" configDir + removeDirectoryRecursive configDir <|> return () + createDirectoryIfMissing True configDir + -- sigh + callProcess "cabal" ["user-config", "init", "-f"] + callProcess "cabal" ["update"] defaultMainWithIngredients (defaultIngredients ++ [includingOptions projectConfigOptionDescriptions]) (withProjectConfig $ \config -> @@ -1971,8 +1982,8 @@ testNixFlags = do -- Tests whether config options are commented or not testConfigOptionComments :: Assertion testConfigOptionComments = do - _ <- createDefaultConfigFile verbosity [] (basedir "config/default-config") - defaultConfigFile <- readFile (basedir "config/default-config") + _ <- createDefaultConfigFile verbosity [] (basedir "config" "default-config") + defaultConfigFile <- readFile (basedir "config" "default-config") " url" @=? findLineWith False "url" defaultConfigFile " -- secure" @=? findLineWith True "secure" defaultConfigFile