Commit 09418b1d authored by kristenk's avatar kristenk Committed by Mikhail Glushenkov
Browse files

Work around issue #4515 in several new-build integration tests.

This commit uses a temporary directory for the nix store in several of the
new-build tests in cabal-testsuite.  The directory is given a very short path on
Windows in order to avoid issues with long store paths.
parent fcc5382c
......@@ -10,16 +10,17 @@ import Test.Cabal.Prelude
-- qualifier as pkg, even though they are both build targets of the project.
-- The solution must use --independent-goals to give pkg and setup-dep different
-- qualifiers.
main = cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
fails $ cabal "new-build" ["pkg:my-exe", "--dry-run"]
-- Disabled recording because whether or not we get
-- detailed information for the build of my-exe depends
-- on whether or not the Cabal library version is recent
-- enough
r1 <- recordMode DoNotRecord $ cabal' "new-build" ["pkg:my-exe", "--independent-goals"]
assertOutputContains "Setup.hs: setup-dep from project" r1
withPlan $ do
r2 <- runPlanExe' "pkg" "my-exe" []
assertOutputContains "Main.hs: setup-dep from repo" r2
main = withShorterPathForNewBuildStore $ \storeDir ->
cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
fails $ cabalG ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe", "--dry-run"]
-- Disabled recording because whether or not we get
-- detailed information for the build of my-exe depends
-- on whether or not the Cabal library version is recent
-- enough
r1 <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe", "--independent-goals"]
assertOutputContains "Setup.hs: setup-dep from project" r1
withPlan $ do
r2 <- runPlanExe' "pkg" "my-exe" []
assertOutputContains "Main.hs: setup-dep from repo" r2
......@@ -2,10 +2,11 @@ import Test.Cabal.Prelude
-- The one local package, pkg, has a setup dependency on setup-dep-2.0, which is
-- in the repository.
main = cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
r <- recordMode DoNotRecord $ cabal' "new-build" ["pkg"]
-- pkg's setup script should print out a message that it imported from
-- setup-dep:
assertOutputContains "pkg Setup.hs: setup-dep-2.0" r
main = withShorterPathForNewBuildStore $ \storeDir ->
cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
r <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg"]
-- pkg's setup script should print out a message that it imported from
-- setup-dep:
assertOutputContains "pkg Setup.hs: setup-dep-2.0" r
......@@ -2,14 +2,15 @@ import Test.Cabal.Prelude
-- The one local package, pkg, has a dependency on remote-pkg-2.0, which has a
-- setup dependency on remote-setup-dep-3.0.
main = cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
r1 <- recordMode DoNotRecord $ cabal' "new-build" ["pkg:my-exe"]
-- remote-pkg's setup script should print out a message that it imported from
-- remote-setup-dep:
assertOutputContains "remote-pkg Setup.hs: remote-setup-dep-3.0" r1
withPlan $ do
r2 <- runPlanExe' "pkg" "my-exe" []
-- pkg's executable should print a message that it imported from remote-pkg:
assertOutputContains "pkg Main.hs: remote-pkg-2.0" r2
main = withShorterPathForNewBuildStore $ \storeDir ->
cabalTest $ do
skipUnless =<< hasNewBuildCompatBootCabal
withRepo "repo" $ do
r1 <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "new-build" ["pkg:my-exe"]
-- remote-pkg's setup script should print out a message that it imported from
-- remote-setup-dep:
assertOutputContains "remote-pkg Setup.hs: remote-setup-dep-3.0" r1
withPlan $ do
r2 <- runPlanExe' "pkg" "my-exe" []
-- pkg's executable should print a message that it imported from remote-pkg:
assertOutputContains "pkg Main.hs: remote-pkg-2.0" r2
import Test.Cabal.Prelude
main = cabalTest $ do
main = withShorterPathForNewBuildStore $ \storeDir ->
cabalTest $ do
-- Don't run this test unless the GHC is sufficiently recent
-- to not ship boot old-time/old-locale
skipUnless =<< ghcVersionIs (>= mkVersion [7,11])
......@@ -8,4 +9,4 @@ main = cabalTest $ do
-- we had the full Hackage index, we'd try it.)
skipUnless =<< ghcVersionIs (< mkVersion [8,1])
withRepo "repo" $ do
cabal "new-build" ["a"]
cabalG ["--store-dir=" ++ storeDir] "new-build" ["a"]
......@@ -5,48 +5,49 @@ import System.Directory
-- Test for 'cabal new-freeze' with only a single library dependency.
-- my-local-package depends on my-library-dep, which has versions 1.0 and 2.0.
main = cabalTest $ withSourceCopy $
withRepo "repo" $ do
cwd <- fmap testCurrentDir getTestEnv
let freezeFile = cwd </> "cabal.project.freeze"
shouldNotExist freezeFile
-- new-build should choose the latest version for the dependency.
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency
-- Freeze a dependency on the older version.
cabal "new-freeze" ["--constraint=my-library-dep==1.0"]
-- The file should constrain the dependency, but not the local package.
shouldExist freezeFile
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
assertFileDoesNotContain freezeFile "my-local-package"
-- cabal should be able to build the package using the constraint from the
-- freeze file.
cabal' "new-build" [] >>= assertDoesNotUseLatestDependency
-- Re-running new-freeze should not change the constraints, because cabal
-- should use the existing freeze file when choosing the new install plan.
cabal "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
-- cabal should choose the latest version again after the freeze file is
-- removed.
liftIO $ removeFile freezeFile
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency
-- Re-running new-freeze with no constraints or freeze file should constrain
-- the dependency to the latest version.
cabal "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==2.0"
assertFileDoesNotContain freezeFile "my-local-package"
where
assertUsesLatestDependency out = do
assertOutputContains "my-library-dep-2.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-1.0" out
assertDoesNotUseLatestDependency out = do
assertOutputContains "my-library-dep-1.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-2.0" out
main = withShorterPathForNewBuildStore $ \storeDir ->
cabalTest $ withSourceCopy $
withRepo "repo" $ do
cwd <- fmap testCurrentDir getTestEnv
let freezeFile = cwd </> "cabal.project.freeze"
shouldNotExist freezeFile
-- new-build should choose the latest version for the dependency.
cabalG' ["--store-dir=" ++ storeDir] "new-build" ["--dry-run"] >>= assertUsesLatestDependency
-- Freeze a dependency on the older version.
cabalG ["--store-dir=" ++ storeDir] "new-freeze" ["--constraint=my-library-dep==1.0"]
-- The file should constrain the dependency, but not the local package.
shouldExist freezeFile
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
assertFileDoesNotContain freezeFile "my-local-package"
-- cabal should be able to build the package using the constraint from the
-- freeze file.
cabalG' ["--store-dir=" ++ storeDir] "new-build" [] >>= assertDoesNotUseLatestDependency
-- Re-running new-freeze should not change the constraints, because cabal
-- should use the existing freeze file when choosing the new install plan.
cabalG ["--store-dir=" ++ storeDir] "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
-- cabal should choose the latest version again after the freeze file is
-- removed.
liftIO $ removeFile freezeFile
cabalG' ["--store-dir=" ++ storeDir] "new-build" ["--dry-run"] >>= assertUsesLatestDependency
-- Re-running new-freeze with no constraints or freeze file should constrain
-- the dependency to the latest version.
cabalG ["--store-dir=" ++ storeDir] "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==2.0"
assertFileDoesNotContain freezeFile "my-local-package"
where
assertUsesLatestDependency out = do
assertOutputContains "my-library-dep-2.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-1.0" out
assertDoesNotUseLatestDependency out = do
assertOutputContains "my-library-dep-1.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-2.0" out
......@@ -27,7 +27,7 @@ import Distribution.Simple.Program.Db
import Distribution.Simple.Program
import Distribution.System (OS(Windows,Linux,OSX), buildOS)
import Distribution.Simple.Utils
( withFileContents, tryFindPackageDesc )
( withFileContents, withTempDirectory, tryFindPackageDesc )
import Distribution.Simple.Configure
( getPersistBuildConfig )
import Distribution.Version
......@@ -36,6 +36,7 @@ import Distribution.Types.UnqualComponentName
import Distribution.Types.LocalBuildInfo
import Distribution.PackageDescription
import Distribution.PackageDescription.Parsec
import Distribution.Verbosity (normal)
import Distribution.Compat.Stack
......@@ -930,3 +931,14 @@ isTestFile f =
".test.hs" -> True
".multitest.hs" -> True
_ -> False
-- | Work around issue #4515 (store paths exceeding the Windows path length
-- limit) by creating a temporary directory for the new-build store. This
-- function creates a directory immediately under the current drive on Windows.
-- The directory must be passed to new- commands with --store-dir.
withShorterPathForNewBuildStore :: (FilePath -> IO a) -> IO a
withShorterPathForNewBuildStore test = do
tempDir <- if buildOS == Windows
then takeDrive `fmap` getCurrentDirectory
else getTemporaryDirectory
withTempDirectory normal tempDir "cabal-test-store" test
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment