Skip to content

Commit

Permalink
make cabal-install integration tests hermetic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geekosaur committed Jul 16, 2024
1 parent d037ce7 commit 717745c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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 @@ -399,6 +399,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 "HOME" 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

0 comments on commit 717745c

Please sign in to comment.