Skip to content

Commit

Permalink
Merge pull request haskell#3432 from dcoutts/issue-3324
Browse files Browse the repository at this point in the history
Add a regression test for issue haskell#3324
  • Loading branch information
dcoutts committed May 15, 2016
2 parents d05e093 + 6804037 commit 336f85e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ Extra-Source-Files:
tests/IntegrationTests2/exception/configure/a.cabal
tests/IntegrationTests2/exception/no-pkg/empty.in
tests/IntegrationTests2/exception/no-pkg2/cabal.project
tests/IntegrationTests2/regression/3324/cabal.project
tests/IntegrationTests2/regression/3324/p/P.hs
tests/IntegrationTests2/regression/3324/p/p.cabal
tests/IntegrationTests2/regression/3324/q/Q.hs
tests/IntegrationTests2/regression/3324/q/q.cabal
-- END gen-extra-source-files

source-repository head
Expand Down
50 changes: 47 additions & 3 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ tests =
-- , testCase "register" testExceptionInRegisterStep
]
--TODO: need to repeat for packages for the store

, testGroup "Regression tests" $
[ testCase "issue #3324" testRegressionIssue3324
]
]

testExceptionInFindingPackage :: Assertion
Expand Down Expand Up @@ -94,20 +98,43 @@ testExceptionInBuildStep = do
plan <- planProject testdir config
plan' <- executePlan plan
(_pkga1, failure) <- expectPackageFailed plan' pkgidA1
case failure of
BuildFailed _str -> return ()
_ -> assertFailure $ "expected BuildFailed, got " ++ show failure
expectBuildFailed failure
where
testdir = "exception/build"
config = mempty
pkgidA1 = PackageIdentifier (PackageName "a") (Version [1] [])

-- | See <https://github.com/haskell/cabal/issues/3324>
--
testRegressionIssue3324 :: Assertion
testRegressionIssue3324 = do
-- expected failure first time due to missing dep
plan1 <- executePlan =<< planProject testdir config
(_pkgq, failure) <- expectPackageFailed plan1 pkgidQ
expectBuildFailed failure

-- add the missing dep, now it should work
let qcabal = basedir </> testdir </> "q" </> "q.cabal"
withFileFinallyRestore qcabal $ do
appendFile qcabal (" build-depends: p\n")
plan2 <- executePlan =<< planProject testdir config
_ <- expectPackageInstalled plan2 pkgidP
_ <- expectPackageInstalled plan2 pkgidQ
return ()
where
testdir = "regression/3324"
config = mempty
pkgidP = PackageIdentifier (PackageName "p") (Version [0,1] [])
pkgidQ = PackageIdentifier (PackageName "q") (Version [0,1] [])


---------------------------------
-- Test utils to plan and build
--

basedir :: FilePath
basedir = "tests" </> "IntegrationTests2"

planProject :: FilePath -> ProjectConfig -> IO PlanDetails
planProject testdir cliConfig = do
cabalDir <- defaultCabalDir
Expand Down Expand Up @@ -259,3 +286,20 @@ expectPlanPackage plan pkgid =
"expected to find only one instance of " ++ display pkgid
++ " in the install plan but there's several"

expectBuildFailed :: BuildFailure -> IO ()
expectBuildFailed (BuildFailed _str) = return ()
expectBuildFailed failure = assertFailure $ "expected BuildFailed, got "
++ show failure

---------------------------------------
-- Other utils
--

-- | Allow altering a file during a test, but then restore it afterwards
--
withFileFinallyRestore :: FilePath -> IO a -> IO a
withFileFinallyRestore file action = do
copyFile file backup
action `finally` renameFile backup file
where
backup = file <.> "backup"
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cabal-version: >= 1.2

executable a
main-is: Main.hs
build-depends: haskell2010
build-depends: base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: p q
4 changes: 4 additions & 0 deletions cabal-install/tests/IntegrationTests2/regression/3324/p/P.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module P where

p :: Int
p = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: p
version: 0.1
build-type: Simple
cabal-version: >= 1.2

library
exposed-modules: P
build-depends: base
6 changes: 6 additions & 0 deletions cabal-install/tests/IntegrationTests2/regression/3324/q/Q.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Q where

import P

q :: Int
q = p
10 changes: 10 additions & 0 deletions cabal-install/tests/IntegrationTests2/regression/3324/q/q.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: q
version: 0.1
build-type: Simple
cabal-version: >= 1.2

library
exposed-modules: Q
build-depends: base
-- missing a dep on p here, so expect failure initially

0 comments on commit 336f85e

Please sign in to comment.