diff --git a/.gitignore b/.gitignore index 3450353924b..f2568f428f8 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..e6373cd18b8 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 "CABAL_DIR" 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