$HOME/.cabal is not a cabal file

This commit is contained in:
Daniel Gröber 2014-11-03 00:04:15 +01:00
parent 94a60350c8
commit 833d9ce058
2 changed files with 16 additions and 2 deletions

View File

@ -30,7 +30,7 @@ type FileName = String
-- or 'GMETooManyCabalFiles'
findCabalFiles :: FilePath -> IO (Maybe FilePath)
findCabalFiles directory = do
-- Look for cabal files in all parent directories of @dir@
-- Look for cabal files in @dir@ and all it's parent directories
dcs <- getCabalFiles `zipMapM` parents directory
-- Extract first non-empty list, which represents a directory with cabal
-- files.
@ -42,7 +42,16 @@ findCabalFiles directory = do
-- | @getCabalFiles dir@. Find all files ending in @.cabal@ in @dir@.
getCabalFiles :: DirPath -> IO [FileName]
getCabalFiles dir =
filter ((==) ".cabal" . takeExtension) <$> getDirectoryContents dir
filterM isCabalFile =<< getDirectoryContents dir
where
isCabalFile f = do
exists <- doesFileExist f
return (exists && takeExtension' f == ".cabal")
takeExtension' p = if takeFileName p == takeExtension p
then ""
else takeExtension p
makeAbsolute :: DirPath -> [FileName] -> [FilePath]
makeAbsolute dir fs = (dir </>) `map` fs

View File

@ -8,6 +8,7 @@ import Language.Haskell.GhcMod.GhcPkg
#endif
import System.Directory
import System.Environment
import System.FilePath ((</>))
import Test.Hspec
@ -28,3 +29,7 @@ spec = do
it "returns Nothing if the sandbox config file is broken" $ do
getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing
describe "getCabalFiles" $ do
it "doesn't think $HOME/.cabal is a cabal file" $ do
(getCabalFiles =<< getEnv "HOME") `shouldReturn` []