hsfm/test/FileSystem/FileOperations/DeleteFileSpec.hs

58 lines
1.8 KiB
Haskell
Raw Normal View History

2016-05-03 11:13:07 +00:00
{-# LANGUAGE OverloadedStrings #-}
2016-05-03 11:27:10 +00:00
module FileSystem.FileOperations.DeleteFileSpec where
2016-05-03 11:13:07 +00:00
import Test.Hspec
import System.IO.Error
(
ioeGetErrorType
)
import System.Posix.Files.ByteString
(
getSymbolicLinkStatus
)
import GHC.IO.Exception
(
IOErrorType(..)
)
import Utils
2016-05-08 21:45:51 +00:00
spec :: Spec
spec =
2016-05-03 11:13:07 +00:00
describe "HSFM.FileSystem.FileOperations.deleteFile" $ do
-- successes --
it "deleteFile, regular file, all fine" $ do
2016-05-03 11:27:10 +00:00
createRegularFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile"
2016-05-03 11:13:07 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteFile, symlink, all fine" $ do
2016-05-03 11:27:10 +00:00
recreateSymlink' "test/FileSystem/FileOperations/deleteFileSpec/syml"
"test/FileSystem/FileOperations/deleteFileSpec/testFile"
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile"
2016-05-03 11:13:07 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
-- posix failures --
it "deleteFile, wrong file type (directory)" $
2016-05-03 11:27:10 +00:00
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/dir"
2016-05-03 11:13:07 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteFile, file does not exist" $
2016-05-03 11:27:10 +00:00
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/doesNotExist"
2016-05-03 11:13:07 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteFile, can't read directory" $
2016-05-03 11:27:10 +00:00
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/noPerms/blah"
2016-05-03 11:13:07 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)