From 241c7946fccd455fc2bb81dd7c7bf3d24ca173fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Mon, 19 May 2014 01:20:58 +0200 Subject: [PATCH 1/2] Revert "Fix tests for Cabal <= 1.16" The problem the reverted commit tried to fix seems to have been just a symptom of another root cause that was later fixed as the problem does not seem to occur anymore even without this changeset also this changeset broke cabal sandboxes with ghc < 7.8. Fix #262 This reverts commit 8741323f5b9c5450c40205d0632f61a4b7e42125. Conflicts: Language/Haskell/GhcMod/GhcPkg.hs --- Language/Haskell/GhcMod/GhcPkg.hs | 16 +++------------- test/CabalApiSpec.hs | 8 +------- test/CradleSpec.hs | 5 ----- test/GhcPkgSpec.hs | 9 +-------- 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/Language/Haskell/GhcMod/GhcPkg.hs b/Language/Haskell/GhcMod/GhcPkg.hs index ca8a8ab..6c1f5b8 100644 --- a/Language/Haskell/GhcMod/GhcPkg.hs +++ b/Language/Haskell/GhcMod/GhcPkg.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP, BangPatterns, ScopedTypeVariables, TupleSections #-} +{-# LANGUAGE BangPatterns, ScopedTypeVariables, TupleSections #-} module Language.Haskell.GhcMod.GhcPkg ( ghcPkgDbOpt , ghcPkgDbStackOpts @@ -10,15 +10,10 @@ module Language.Haskell.GhcMod.GhcPkg ( , getPackageDbStack ) where -#ifndef MIN_VERSION_Cabal -#define MIN_VERSION_Cabal(x,y,z) 1 -#endif - import Config (cProjectVersionInt) import Control.Applicative ((<$>)) -#if MIN_VERSION_Cabal(1,18,0) +import Control.Exception (SomeException(..)) import qualified Control.Exception as E -#endif import Data.Char (isSpace) import Data.List (isPrefixOf, intercalate) import Data.List.Split (splitOn) @@ -55,14 +50,9 @@ getPackageDbStack :: FilePath -- ^ Project Directory (where the -- cabal.sandbox.config file would be if it -- exists) -> IO [GhcPkgDb] -#if MIN_VERSION_Cabal(1,18,0) getPackageDbStack cdir = (getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db]) - `E.catch` \(_ :: E.SomeException) -> return [GlobalDb, UserDb] -#else -getPackageDbStack _ = - return [GlobalDb, UserDb] -#endif + `E.catch` \(_ :: SomeException) -> return [GlobalDb, UserDb] fromInstalledPackageId' :: InstalledPackageId -> Maybe Package fromInstalledPackageId' pid = let diff --git a/test/CabalApiSpec.hs b/test/CabalApiSpec.hs index cd010dd..d7b1d13 100644 --- a/test/CabalApiSpec.hs +++ b/test/CabalApiSpec.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP, ScopedTypeVariables #-} +{-# LANGUAGE ScopedTypeVariables #-} module CabalApiSpec where @@ -36,15 +36,9 @@ spec = do ghcOptions = ghcOptions res , includeDirs = map (toRelativeDir dir) (includeDirs res) } -#if MIN_VERSION_Cabal(1,18,0) if ghcVersion < 706 then ghcOptions res' `shouldContain` ["-global-package-conf", "-no-user-package-conf","-package-conf",cwd "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"] else ghcOptions res' `shouldContain` ["-global-package-db", "-no-user-package-db","-package-db",cwd "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"] -#else - if ghcVersion < 706 - then ghcOptions res' `shouldContain` ["-global-package-conf", "-user-package-conf","-XHaskell98"] - else ghcOptions res' `shouldContain` ["-global-package-db", "-user-package-db","-XHaskell98"] -#endif includeDirs res' `shouldBe` ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"] (pkgName `map` depPackages res') `shouldContain` ["Cabal"] diff --git a/test/CradleSpec.hs b/test/CradleSpec.hs index 38fd869..2bf54e1 100644 --- a/test/CradleSpec.hs +++ b/test/CradleSpec.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} module CradleSpec where import Control.Applicative @@ -32,11 +31,7 @@ spec = do cradleCurrentDir = "test" "data" "subdir1" "subdir2" , cradleRootDir = "test" "data" , cradleCabalFile = Just ("test" "data" "cabalapi.cabal") -#if MIN_VERSION_Cabal(1,18,0) , cradlePkgDbStack = [GlobalDb, PackageDb (cwd "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")] -#else - , cradlePkgDbStack = [GlobalDb, UserDb] -#endif } it "works even if a sandbox config file is broken" $ do withDirectory "test/data/broken-sandbox" $ \dir -> do diff --git a/test/GhcPkgSpec.hs b/test/GhcPkgSpec.hs index 3c84177..1859829 100644 --- a/test/GhcPkgSpec.hs +++ b/test/GhcPkgSpec.hs @@ -1,8 +1,6 @@ -{-# LANGUAGE CPP #-} module GhcPkgSpec where import Language.Haskell.GhcMod.GhcPkg -import Language.Haskell.GhcMod.Types import System.Directory import System.FilePath (()) @@ -10,12 +8,7 @@ import Test.Hspec spec :: Spec spec = do - describe "getPackageDbStack" $ do -#if !MIN_VERSION_Cabal(1,18,0) - it "does not include a sandbox with Cabal < 1.18" $ do - cwd <- getCurrentDirectory - getPackageDbStack cwd `shouldReturn` [GlobalDb, UserDb] -#endif + describe "getSandboxDb" $ do it "parses a config file and extracts sandbox package db" $ do cwd <- getCurrentDirectory pkgDb <- getSandboxDb "test/data/" From eff77d1f3167a667232beb315613b526a40fab91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Mon, 19 May 2014 01:29:49 +0200 Subject: [PATCH 2/2] Add test for sandbox compatibility with ghc < 7.8 --- test/GhcPkgSpec.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/GhcPkgSpec.hs b/test/GhcPkgSpec.hs index 1859829..af39235 100644 --- a/test/GhcPkgSpec.hs +++ b/test/GhcPkgSpec.hs @@ -1,6 +1,8 @@ +{-# LANGUAGE CPP #-} module GhcPkgSpec where import Language.Haskell.GhcMod.GhcPkg +import Language.Haskell.GhcMod.Types import System.Directory import System.FilePath (()) @@ -9,6 +11,13 @@ import Test.Hspec spec :: Spec spec = do describe "getSandboxDb" $ do +-- ghc < 7.8 +#if !MIN_VERSION_ghc(7,8,0) + it "does include a sandbox with ghc < 7.8" $ do + cwd <- getCurrentDirectory + getPackageDbStack "test/data/" `shouldReturn` [GlobalDb, PackageDb $ cwd "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"] +#endif + it "parses a config file and extracts sandbox package db" $ do cwd <- getCurrentDirectory pkgDb <- getSandboxDb "test/data/"