2016-05-09 14:53:31 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module HPath.IO.CreateDirSpec 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 "CreateDirSpec"
|
|
|
|
createTmpDir
|
|
|
|
|
2016-05-29 15:29:13 +00:00
|
|
|
setupFiles :: IO ()
|
|
|
|
setupFiles = do
|
|
|
|
createDir' "alreadyExists"
|
|
|
|
createDir' "noPerms"
|
|
|
|
createDir' "noWritePerms"
|
|
|
|
noPerms "noPerms"
|
|
|
|
noWritableDirPerms "noWritePerms"
|
2016-05-09 14:53:31 +00:00
|
|
|
|
|
|
|
|
2016-05-29 15:29:13 +00:00
|
|
|
|
|
|
|
cleanupFiles :: IO ()
|
|
|
|
cleanupFiles = do
|
|
|
|
normalDirPerms "noPerms"
|
|
|
|
normalDirPerms "noWritePerms"
|
|
|
|
deleteDir' "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.createDir" $ do
|
|
|
|
|
|
|
|
-- successes --
|
|
|
|
it "createDir, all fine" $ do
|
2016-05-29 15:29:13 +00:00
|
|
|
createDir' "newDir"
|
|
|
|
removeDirIfExists "newDir"
|
2016-05-09 14:53:31 +00:00
|
|
|
|
|
|
|
-- posix failures --
|
|
|
|
it "createDir, can't write to output directory" $
|
2016-05-29 15:29:13 +00:00
|
|
|
createDir' "noWritePerms/newDir"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createDir, can't open output directory" $
|
2016-05-29 15:29:13 +00:00
|
|
|
createDir' "noPerms/newDir"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createDir, destination directory already exists" $
|
2016-05-29 15:29:13 +00:00
|
|
|
createDir' "alreadyExists"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == AlreadyExists)
|
|
|
|
|