2016-05-03 11:13:07 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2016-05-03 11:27:10 +00:00
|
|
|
module FileSystem.FileOperations.CreateRegularFileSpec where
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
import System.IO.Error
|
|
|
|
(
|
|
|
|
ioeGetErrorType
|
|
|
|
)
|
|
|
|
import GHC.IO.Exception
|
|
|
|
(
|
|
|
|
IOErrorType(..)
|
|
|
|
)
|
|
|
|
import Utils
|
|
|
|
|
|
|
|
|
|
|
|
createRegularFileSpec :: Spec
|
|
|
|
createRegularFileSpec =
|
|
|
|
describe "HSFM.FileSystem.FileOperations.createRegularFile" $ do
|
|
|
|
|
|
|
|
-- successes --
|
|
|
|
it "createRegularFile, all fine" $ do
|
2016-05-03 11:27:10 +00:00
|
|
|
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/newDir"
|
|
|
|
removeFileIfExists "test/FileSystem/FileOperations/createRegularFileSpec/newDir"
|
2016-05-03 11:13:07 +00:00
|
|
|
|
|
|
|
-- posix failures --
|
|
|
|
it "createRegularFile, can't write to destination directory" $
|
2016-05-03 11:27:10 +00:00
|
|
|
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms/newDir"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createRegularFile, can't write to destination directory" $
|
2016-05-03 11:27:10 +00:00
|
|
|
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noPerms/newDir"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == PermissionDenied)
|
|
|
|
|
|
|
|
it "createRegularFile, destination file already exists" $
|
2016-05-03 11:27:10 +00:00
|
|
|
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/alreadyExists"
|
2016-05-03 11:13:07 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == AlreadyExists)
|
|
|
|
|