hpath/hpath-io/test/HPath/IO/CreateRegularFileSpec.hs

71 lines
1.6 KiB
Haskell
Raw Normal View History

2016-05-09 14:53:31 +00:00
{-# LANGUAGE OverloadedStrings #-}
module HPath.IO.CreateRegularFileSpec where
import Test.Hspec
import System.IO.Error
(
ioeGetErrorType
)
import GHC.IO.Exception
(
IOErrorType(..)
)
import Utils
2016-06-05 12:33:53 +00:00
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CreateRegularFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "alreadyExists"
createDir' "noPerms"
createDir' "noWritePerms"
noPerms "noPerms"
noWritableDirPerms "noWritePerms"
2016-05-09 14:53:31 +00:00
cleanupFiles :: IO ()
cleanupFiles = do
normalDirPerms "noPerms"
normalDirPerms "noWritePerms"
deleteFile' "alreadyExists"
deleteDir' "noPerms"
deleteDir' "noWritePerms"
2016-05-09 14:53:31 +00:00
spec :: Spec
2016-06-05 13:25:57 +00:00
spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
2016-05-09 14:53:31 +00:00
describe "HPath.IO.createRegularFile" $ do
-- successes --
it "createRegularFile, all fine" $ do
createRegularFile' "newDir"
removeFileIfExists "newDir"
2016-05-09 14:53:31 +00:00
-- posix failures --
it "createRegularFile, parent directories do not exist" $
createRegularFile' "some/thing/dada"
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
2016-05-09 14:53:31 +00:00
it "createRegularFile, can't write to destination directory" $
createRegularFile' "noWritePerms/newDir"
2016-05-09 14:53:31 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createRegularFile, can't write to destination directory" $
createRegularFile' "noPerms/newDir"
2016-05-09 14:53:31 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createRegularFile, destination file already exists" $
createRegularFile' "alreadyExists"
2016-05-09 14:53:31 +00:00
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)