Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cabal-install integration tests hermetic (backport #10205) #10218

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ test-suite integration-tests2
containers,
directory,
filepath,
process,
tasty >= 1.2.3 && <1.6,
tasty-hunit >= 0.10,
tagged
Expand Down
17 changes: 14 additions & 3 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down
Loading