2016-05-03 11:13:07 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2016-05-03 11:27:10 +00:00
|
|
|
module FileSystem.FileOperations.GetDirsFilesSpec where
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
import Data.List
|
|
|
|
(
|
|
|
|
sort
|
|
|
|
)
|
|
|
|
import Data.Maybe
|
|
|
|
(
|
|
|
|
fromJust
|
|
|
|
)
|
|
|
|
import qualified HPath as P
|
|
|
|
import Test.Hspec
|
|
|
|
import System.IO.Error
|
|
|
|
(
|
|
|
|
ioeGetErrorType
|
|
|
|
)
|
|
|
|
import System.Posix.Env.ByteString
|
|
|
|
(
|
|
|
|
getEnv
|
|
|
|
)
|
|
|
|
import GHC.IO.Exception
|
|
|
|
(
|
|
|
|
IOErrorType(..)
|
|
|
|
)
|
|
|
|
import Utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDirsFilesSpec :: Spec
|
|
|
|
getDirsFilesSpec =
|
|
|
|
describe "HSFM.FileSystem.FileOperations.getDirsFiles" $ do
|
|
|
|
|
|
|
|
-- successes --
|
|
|
|
it "getDirsFiles, all fine" $ do
|
|
|
|
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
|
2016-05-03 11:27:10 +00:00
|
|
|
expectedFiles <- mapM P.parseRel ["test/FileSystem/FileOperations/getDirsFilesSpec/.hidden"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/Lala"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/dir"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/dirsym"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/file"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/noPerms"
|
|
|
|
,"test/FileSystem/FileOperations/getDirsFilesSpec/syml"]
|
|
|
|
(fmap sort $ getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec")
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldReturn` fmap (pwd P.</>) expectedFiles
|
|
|
|
|
|
|
|
-- posix failures --
|
|
|
|
it "getDirsFiles, nonexistent directory" $
|
2016-05-03 11:27:10 +00:00
|
|
|
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/nothingHere"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == NoSuchThing)
|
|
|
|
|
|
|
|
it "getDirsFiles, wrong file type (file)" $
|
2016-05-03 11:27:10 +00:00
|
|
|
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/file"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == InappropriateType)
|
|
|
|
|
|
|
|
it "getDirsFiles, wrong file type (symlink to file)" $
|
2016-05-03 11:27:10 +00:00
|
|
|
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/syml"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == InvalidArgument)
|
|
|
|
|
|
|
|
it "getDirsFiles, wrong file type (symlink to dir)" $
|
2016-05-03 11:27:10 +00:00
|
|
|
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/dirsym"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == InvalidArgument)
|
|
|
|
|
|
|
|
it "getDirsFiles, can't open directory" $
|
2016-05-03 11:27:10 +00:00
|
|
|
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/noPerms"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|