Skip to content

Commit

Permalink
Set CABAL_DIR in cabal-tests (fixes haskell#5187).
Browse files Browse the repository at this point in the history
This change gives each test a new cabal directory on Windows and prevents the
tests from accessing the user's cabal directory.

This commit also re-enables
PackageTests/Regression/T4154/install-time-with-constraint.test.hs on Windows.
  • Loading branch information
grayjay committed Mar 31, 2018
1 parent d44329f commit a880c85
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/CustomDep/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ main = cabalTest $ do
-- database, don't record the output
recordMode DoNotRecord $ do
-- TODO: Hack, delete me
withEnvFilter (/= "HOME") $ do
withEnvFilter (`notElem` ["HOME", "CABAL_DIR"]) $ do
cabal "new-build" ["all"]
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/CustomPlain/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ main = cabalTest $ do
-- Regression test for #4393
recordMode DoNotRecord $ do
-- TODO: Hack; see also CustomDep/cabal.test.hs
withEnvFilter (/= "HOME") $ do
withEnvFilter (`notElem` ["HOME", "CABAL_DIR"]) $ do
-- On -v2, we don't have vQuiet set, which suppressed
-- the error
cabal "new-build" ["-v1"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import Test.Cabal.Prelude
-- building its setup script with the installed Cabal, which depends on the
-- installed time, even though the installed time doesn't fit the constraint.
main = cabalTest $ do
-- TODO: Run this test on Windows once #5187 is resolved.
skipIf =<< isWindows

cabal "new-build" ["time", "--constraint=time==99999", "--dry-run"]

-- Temporarily disabled recording here because output is not stable
Expand Down
16 changes: 11 additions & 5 deletions cabal-testsuite/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ module Test.Cabal.Monad (
testPrefixDir,
testDistDir,
testPackageDbDir,
testHomeDir,
testSandboxDir,
testSandboxConfigFile,
testRepoDir,
testKeysDir,
testSourceCopyDir,
testCabalDir,
testUserCabalConfigFile,
testActualFile,
-- * Skipping tests
Expand Down Expand Up @@ -316,7 +316,10 @@ runTestM mode m = do
-- Try to avoid Unicode output
[ ("LC_ALL", Just "C")
-- Hermetic builds (knot-tied)
, ("HOME", Just (testHomeDir env))],
, ("HOME", Just (testHomeDir env))
-- Set CABAL_DIR in addition to HOME, since HOME has no
-- effect on Windows.
, ("CABAL_DIR", Just (testCabalDir env))],
testShouldFail = False,
testRelativeCurrentDir = ".",
testHavePackageDb = False,
Expand All @@ -343,7 +346,7 @@ runTestM mode m = do
-- the default configuration hardcodes Hackage, which we do
-- NOT want to assume for these tests (no test should
-- hit Hackage.)
liftIO $ createDirectoryIfMissing True (testHomeDir env </> ".cabal")
liftIO $ createDirectoryIfMissing True (testCabalDir env)
ghc_path <- programPathM ghcProgram
liftIO $ writeFile (testUserCabalConfigFile env)
$ unlines [ "with-compiler: " ++ ghc_path ]
Expand Down Expand Up @@ -637,10 +640,13 @@ testKeysDir env = testWorkDir env </> "keys"
testSourceCopyDir :: TestEnv -> FilePath
testSourceCopyDir env = testWorkDir env </> "source"

-- | The user cabal directory
testCabalDir :: TestEnv -> FilePath
testCabalDir env = testHomeDir env </> ".cabal"

-- | The user cabal config file
-- TODO: Not obviously working on Windows
testUserCabalConfigFile :: TestEnv -> FilePath
testUserCabalConfigFile env = testHomeDir env </> ".cabal" </> "config"
testUserCabalConfigFile env = testCabalDir env </> "config"

-- | The file where the expected output of the test lives
testExpectFile :: TestEnv -> FilePath
Expand Down
2 changes: 1 addition & 1 deletion cabal-testsuite/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ withRepo repo_dir m = do
hackageRepoTool "bootstrap" ["--keys", testKeysDir env, "--repo", testRepoDir env]
-- 5. Wire it up in .cabal/config
-- TODO: libify this
let package_cache = testHomeDir env </> ".cabal" </> "packages"
let package_cache = testCabalDir env </> "packages"
liftIO $ appendFile (testUserCabalConfigFile env)
$ unlines [ "repository test-local-repo"
, " url: file:" ++ testRepoDir env
Expand Down

0 comments on commit a880c85

Please sign in to comment.