$HOME/.cabal is not a cabal file
This commit is contained in:
parent
94a60350c8
commit
833d9ce058
@ -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
|
||||
|
@ -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` []
|
||||
|
Loading…
Reference in New Issue
Block a user