From f9c9ac676c4d642fe4915e6666225d4d59f1a9de Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Tue, 14 Jan 2014 15:24:10 +0900 Subject: [PATCH] Work around `canonicalizePath "/"` in GHC 7.2.2 --- test/CradleSpec.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/CradleSpec.hs b/test/CradleSpec.hs index 7e17296..42e3de2 100644 --- a/test/CradleSpec.hs +++ b/test/CradleSpec.hs @@ -1,10 +1,11 @@ module CradleSpec where import Control.Applicative +import Data.List (isSuffixOf) import Language.Haskell.GhcMod.Cradle import Language.Haskell.GhcMod.Types import System.Directory (canonicalizePath) -import System.FilePath (()) +import System.FilePath ((), pathSeparator) import Test.Hspec import Dir @@ -14,7 +15,7 @@ spec = do describe "findCradle" $ do it "returns the current directory" $ do withDirectory_ "/" $ do - curDir <- canonicalizePath "/" + curDir <- stripLastDot <$> canonicalizePath "/" res <- findCradle res `shouldBe` Cradle { cradleCurrentDir = curDir @@ -56,3 +57,9 @@ relativeCradle dir cradle = Cradle { , cradleCabalFile = toRelativeDir dir <$> cradleCabalFile cradle , cradlePackageDbOpts = cradlePackageDbOpts cradle } + +-- Work around GHC 7.2.2 where `canonicalizePath "/"` returns "/.". +stripLastDot :: FilePath -> FilePath +stripLastDot path + | (pathSeparator:'.':"") `isSuffixOf` path = init path + | otherwise = path