From ba29a1738039a2d512ac1a78c1ca7eba76cf8aec Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Sat, 14 May 2016 17:59:51 +0100 Subject: [PATCH 1/2] Add a regression test for issue #3324 --- cabal-install/cabal-install.cabal | 5 ++ cabal-install/tests/IntegrationTests2.hs | 50 +++++++++++++++++-- .../regression/3324/cabal.project | 1 + .../IntegrationTests2/regression/3324/p/P.hs | 4 ++ .../regression/3324/p/p.cabal | 8 +++ .../IntegrationTests2/regression/3324/q/Q.hs | 6 +++ .../regression/3324/q/q.cabal | 10 ++++ 7 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 cabal-install/tests/IntegrationTests2/regression/3324/cabal.project create mode 100644 cabal-install/tests/IntegrationTests2/regression/3324/p/P.hs create mode 100644 cabal-install/tests/IntegrationTests2/regression/3324/p/p.cabal create mode 100644 cabal-install/tests/IntegrationTests2/regression/3324/q/Q.hs create mode 100644 cabal-install/tests/IntegrationTests2/regression/3324/q/q.cabal diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index b0d954baeb0..7a93d02135c 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -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 diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index 7e4fa76330e..d4f4549372f 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -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 @@ -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 +-- +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 @@ -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" diff --git a/cabal-install/tests/IntegrationTests2/regression/3324/cabal.project b/cabal-install/tests/IntegrationTests2/regression/3324/cabal.project new file mode 100644 index 00000000000..085b1161f41 --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/regression/3324/cabal.project @@ -0,0 +1 @@ +packages: p q diff --git a/cabal-install/tests/IntegrationTests2/regression/3324/p/P.hs b/cabal-install/tests/IntegrationTests2/regression/3324/p/P.hs new file mode 100644 index 00000000000..7fdc3231e40 --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/regression/3324/p/P.hs @@ -0,0 +1,4 @@ +module P where + +p :: Int +p = 42 diff --git a/cabal-install/tests/IntegrationTests2/regression/3324/p/p.cabal b/cabal-install/tests/IntegrationTests2/regression/3324/p/p.cabal new file mode 100644 index 00000000000..6a10e9f9985 --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/regression/3324/p/p.cabal @@ -0,0 +1,8 @@ +name: p +version: 0.1 +build-type: Simple +cabal-version: >= 1.2 + +library + exposed-modules: P + build-depends: base diff --git a/cabal-install/tests/IntegrationTests2/regression/3324/q/Q.hs b/cabal-install/tests/IntegrationTests2/regression/3324/q/Q.hs new file mode 100644 index 00000000000..7a66f6174e4 --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/regression/3324/q/Q.hs @@ -0,0 +1,6 @@ +module Q where + +import P + +q :: Int +q = p diff --git a/cabal-install/tests/IntegrationTests2/regression/3324/q/q.cabal b/cabal-install/tests/IntegrationTests2/regression/3324/q/q.cabal new file mode 100644 index 00000000000..a9051169c3b --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/regression/3324/q/q.cabal @@ -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 + From 6804037737b663e18542bd41fe037ae766cf381d Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Sun, 15 May 2016 20:54:22 +0100 Subject: [PATCH 2/2] Fix IntegrationTest2 on ghc-7.10+ Use base not haskell2010 package. --- cabal-install/tests/IntegrationTests2/exception/build/a.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/tests/IntegrationTests2/exception/build/a.cabal b/cabal-install/tests/IntegrationTests2/exception/build/a.cabal index a974090f235..1c44505cc85 100644 --- a/cabal-install/tests/IntegrationTests2/exception/build/a.cabal +++ b/cabal-install/tests/IntegrationTests2/exception/build/a.cabal @@ -5,4 +5,4 @@ cabal-version: >= 1.2 executable a main-is: Main.hs - build-depends: haskell2010 + build-depends: base