TESTS: add getDirsFilesSpec
This commit is contained in:
parent
7e8d465d81
commit
9a11e35be0
@ -519,7 +519,7 @@ createDir dest = createDirectory (P.fromAbs dest) newDirPerms
|
||||
--
|
||||
-- - `NoSuchThing` if source file does not exist
|
||||
-- - `PermissionDenied` if output directory cannot be written to
|
||||
-- - `PermissionDenied` if source driectory cannot be opened
|
||||
-- - `PermissionDenied` if source directory cannot be opened
|
||||
-- - `UnsupportedOperation` if source and destination are on different devices
|
||||
-- - `FileDoesExist` if destination file already exists
|
||||
-- - `DirDoesExist` if destination directory already exists
|
||||
@ -547,7 +547,7 @@ renameFile fromf tof = do
|
||||
--
|
||||
-- - `NoSuchThing` if source file does not exist
|
||||
-- - `PermissionDenied` if output directory cannot be written to
|
||||
-- - `PermissionDenied` if source driectory cannot be opened
|
||||
-- - `PermissionDenied` if source directory cannot be opened
|
||||
-- - `FileDoesExist` if destination file already exists
|
||||
-- - `DirDoesExist` if destination directory already exists
|
||||
-- - `SameFile` if destination and source are the same file
|
||||
@ -599,6 +599,14 @@ newDirPerms
|
||||
|
||||
-- |Gets all filenames of the given directory. This excludes "." and "..".
|
||||
-- This version does not follow symbolic links.
|
||||
--
|
||||
-- Throws:
|
||||
--
|
||||
-- - `NoSuchThing` if directory does not exist
|
||||
-- - `InappropriateType` if file type is wrong (file)
|
||||
-- - `InappropriateType` if file type is wrong (symlink to file)
|
||||
-- - `InappropriateType` if file type is wrong (symlink to dir)
|
||||
-- - `PermissionDenied` if directory cannot be opened
|
||||
getDirsFiles :: Path Abs -- ^ dir to read
|
||||
-> IO [Path Abs]
|
||||
getDirsFiles p =
|
||||
|
60
test/Spec.hs
60
test/Spec.hs
@ -39,6 +39,10 @@ import System.Posix.Files.ByteString
|
||||
, setFileMode
|
||||
, unionFileModes
|
||||
)
|
||||
import Data.List
|
||||
(
|
||||
sort
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -55,13 +59,16 @@ main = hspec $ before_ fixPermissions $ after_ revertPermissions $ do
|
||||
, renameFileSpec
|
||||
, moveFileSpec
|
||||
, recreateSymlinkSpec
|
||||
, getFileTypeSpec
|
||||
]
|
||||
|
||||
-- run all stateful tests twice to catch missing cleanups or state skew
|
||||
sequence_ tests
|
||||
sequence_ tests
|
||||
|
||||
-- stateless tests
|
||||
getFileTypeSpec
|
||||
getDirsFilesSpec
|
||||
|
||||
-- TODO: deleteFile, deleteDir, deleteDirRecursive, getDirsFiles, getFileType
|
||||
where
|
||||
noWriteDirs = ["test/copyFileSpec/outputDirNoWrite"
|
||||
@ -80,6 +87,7 @@ main = hspec $ before_ fixPermissions $ after_ revertPermissions $ do
|
||||
,"test/moveFile/noPerms"
|
||||
,"test/recreateSymlinkSpec/noPerms"
|
||||
,"test/getFileTypeSpec/noPerms"
|
||||
,"test/getDirsFilesSpec/noPerms"
|
||||
]
|
||||
fixPermissions = do
|
||||
sequence_ $ fmap noWritableDirPerms noWriteDirs
|
||||
@ -533,6 +541,48 @@ getFileTypeSpec =
|
||||
(\e -> ioeGetErrorType e == PermissionDenied)
|
||||
|
||||
|
||||
getDirsFilesSpec :: Spec
|
||||
getDirsFilesSpec =
|
||||
describe "HSFM.FileSystem.FileOperations.getDirsFiles" $ do
|
||||
|
||||
-- successes --
|
||||
it "getDirsFiles, all fine" $ do
|
||||
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
|
||||
expectedFiles <- mapM P.parseRel ["test/getDirsFilesSpec/.hidden"
|
||||
,"test/getDirsFilesSpec/Lala"
|
||||
,"test/getDirsFilesSpec/dir"
|
||||
,"test/getDirsFilesSpec/dirsym"
|
||||
,"test/getDirsFilesSpec/file"
|
||||
,"test/getDirsFilesSpec/noPerms"
|
||||
,"test/getDirsFilesSpec/syml"]
|
||||
(fmap sort $ getDirsFiles' "test/getDirsFilesSpec")
|
||||
`shouldReturn` fmap (pwd P.</>) expectedFiles
|
||||
|
||||
-- posix failures --
|
||||
it "getDirsFiles, nonexistent directory" $
|
||||
getDirsFiles' "test/getDirsFilesSpec/nothingHere"
|
||||
`shouldThrow`
|
||||
(\e -> ioeGetErrorType e == NoSuchThing)
|
||||
|
||||
it "getDirsFiles, wrong file type (file)" $
|
||||
getDirsFiles' "test/getDirsFilesSpec/file"
|
||||
`shouldThrow`
|
||||
(\e -> ioeGetErrorType e == InappropriateType)
|
||||
|
||||
it "getDirsFiles, wrong file type (symlink to file)" $
|
||||
getDirsFiles' "test/getDirsFilesSpec/syml"
|
||||
`shouldThrow`
|
||||
(\e -> ioeGetErrorType e == InvalidArgument)
|
||||
|
||||
it "getDirsFiles, wrong file type (symlink to dir)" $
|
||||
getDirsFiles' "test/getDirsFilesSpec/dirsym"
|
||||
`shouldThrow`
|
||||
(\e -> ioeGetErrorType e == InvalidArgument)
|
||||
|
||||
it "getDirsFiles, can't open directory" $
|
||||
getDirsFiles' "test/getDirsFilesSpec/noPerms"
|
||||
`shouldThrow`
|
||||
(\e -> ioeGetErrorType e == PermissionDenied)
|
||||
|
||||
|
||||
|
||||
@ -649,3 +699,11 @@ getFileType' path = do
|
||||
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
|
||||
file <- (pwd P.</>) <$> P.parseRel path
|
||||
getFileType file
|
||||
|
||||
|
||||
getDirsFiles' :: ByteString -> IO [P.Path P.Abs]
|
||||
getDirsFiles' path = do
|
||||
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
|
||||
file <- (pwd P.</>) <$> P.parseRel path
|
||||
getDirsFiles file
|
||||
|
||||
|
0
test/getDirsFilesSpec/.hidden
Normal file
0
test/getDirsFilesSpec/.hidden
Normal file
0
test/getDirsFilesSpec/Lala
Normal file
0
test/getDirsFilesSpec/Lala
Normal file
1
test/getDirsFilesSpec/dirsym
Symbolic link
1
test/getDirsFilesSpec/dirsym
Symbolic link
@ -0,0 +1 @@
|
||||
dir
|
0
test/getDirsFilesSpec/file
Normal file
0
test/getDirsFilesSpec/file
Normal file
0
test/getDirsFilesSpec/noPerms/.keep
Normal file
0
test/getDirsFilesSpec/noPerms/.keep
Normal file
1
test/getDirsFilesSpec/syml
Symbolic link
1
test/getDirsFilesSpec/syml
Symbolic link
@ -0,0 +1 @@
|
||||
Lala
|
Loading…
Reference in New Issue
Block a user