Skip to content

Commit

Permalink
Work around issue #4515 in several new-build integration tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grayjay authored and 23Skidoo committed May 9, 2018
1 parent fcc5382 commit 09418b1
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions cabal-testsuite/PackageTests/NewBuild/T4375/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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])
Expand All @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion cabal-testsuite/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 09418b1

Please sign in to comment.