TESTS: use specDir to refer to the test directories

This commit is contained in:
Julian Ospald 2016-05-09 00:16:26 +02:00
parent a91b4859d0
commit 29f4dc67b6
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
15 changed files with 458 additions and 286 deletions

View File

@ -16,8 +16,19 @@ import GHC.IO.Exception
import System.Exit
import System.Process
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -25,75 +36,75 @@ spec =
-- successes --
it "copyDirRecursiveOverwrite, all fine" $ do
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "outputDir")
removeDirIfExists $ specDir `ba` "outputDir"
it "copyDirRecursiveOverwrite, all fine and compare" $ do
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "outputDir")
(system $ "diff -r --no-dereference "
++ "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir" ++ " "
++ "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir")
++ specDir' ++ "inputDir" ++ " "
++ specDir' ++ "outputDir")
`shouldReturn` ExitSuccess
removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
removeDirIfExists $ specDir `ba` "outputDir"
it "copyDirRecursiveOverwrite, destination dir already exists" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/alreadyExistsD"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "alreadyExistsD")
-- posix failures --
it "copyDirRecursiveOverwrite, source directory does not exist" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/doesNotExist"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
copyDirRecursiveOverwrite' (specDir `ba` "doesNotExist")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "copyDirRecursiveOverwrite, no write permission on output dir" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noWritePerm/foo"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "noWritePerm/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursiveOverwrite, cannot open output dir" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noPerms/foo"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "noPerms/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursiveOverwrite, cannot open source dir" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noPerms/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/foo"
copyDirRecursiveOverwrite' (specDir `ba` "noPerms/inputDir")
(specDir `ba` "foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursiveOverwrite, destination already exists and is a file" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/alreadyExists"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "copyDirRecursiveOverwrite, wrong input (regular file)" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/wrongInput"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
copyDirRecursiveOverwrite' (specDir `ba` "wrongInput")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "copyDirRecursiveOverwrite, wrong input (symlink to directory)" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/wrongInputSymL"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/outputDir"
copyDirRecursiveOverwrite' (specDir `ba` "wrongInputSymL")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
-- custom failures
it "copyDirRecursiveOverwrite, destination in source" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir/foo"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "inputDir/foo")
`shouldThrow`
isDestinationInSource
it "copyDirRecursiveOverwrite, destination and source same directory" $
copyDirRecursiveOverwrite' "test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/inputDir"
copyDirRecursiveOverwrite' (specDir `ba` "inputDir")
(specDir `ba` "inputDir")
`shouldThrow`
isSameFile

View File

@ -16,8 +16,19 @@ import GHC.IO.Exception
import System.Exit
import System.Process
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/copyDirRecursiveSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -25,77 +36,77 @@ spec =
-- successes --
it "copyDirRecursive, all fine" $ do
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "outputDir")
removeDirIfExists (specDir `ba` "outputDir")
it "copyDirRecursive, all fine and compare" $ do
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "outputDir")
(system $ "diff -r --no-dereference "
++ "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" ++ " "
++ "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir")
++ specDir' ++ "inputDir" ++ " "
++ specDir' ++ "outputDir")
`shouldReturn` ExitSuccess
removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
removeDirIfExists (specDir `ba` "outputDir")
-- posix failures --
it "copyDirRecursive, source directory does not exist" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/doesNotExist"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
copyDirRecursive' (specDir `ba` "doesNotExist")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "copyDirRecursive, no write permission on output dir" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm/foo"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "noWritePerm/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursive, cannot open output dir" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/foo"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "noPerms/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursive, cannot open source dir" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/foo"
copyDirRecursive' (specDir `ba` "noPerms/inputDir")
(specDir `ba` "foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyDirRecursive, destination dir already exists" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExistsD"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
it "copyDirRecursive, destination already exists and is a file" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExists"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
it "copyDirRecursive, wrong input (regular file)" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInput"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
copyDirRecursive' (specDir `ba` "wrongInput")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "copyDirRecursive, wrong input (symlink to directory)" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInputSymL"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir"
copyDirRecursive' (specDir `ba` "wrongInputSymL")
(specDir `ba` "outputDir")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
-- custom failures
it "copyDirRecursive, destination in source" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/foo"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "inputDir/foo")
`shouldThrow`
isDestinationInSource
it "copyDirRecursive, destination and source same directory" $
copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
"test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir"
copyDirRecursive' (specDir `ba` "inputDir")
(specDir `ba` "inputDir")
`shouldThrow`
isSameFile

View File

@ -16,8 +16,19 @@ import GHC.IO.Exception
import System.Exit
import System.Process
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/copyFileOverwriteSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -25,67 +36,67 @@ spec =
-- successes --
it "copyFileOverwrite, everything clear" $ do
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
removeFileIfExists "test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "outputFile")
removeFileIfExists (specDir `ba` "outputFile")
it "copyFileOverwrite, output file already exists, all clear" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/alreadyExists"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "alreadyExists")
it "copyFileOverwrite, and compare" $ do
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
(system $ "cmp -s " ++ "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile" ++ " "
++ "test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile")
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "outputFile")
(system $ "cmp -s " ++ specDir' ++ "inputFile" ++ " "
++ specDir' ++ "outputFile")
`shouldReturn` ExitSuccess
removeFileIfExists "test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
removeFileIfExists (specDir `ba` "outputFile")
-- posix failures --
it "copyFileOverwrite, input file does not exist" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/noSuchFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
copyFileOverwrite' (specDir `ba` "noSuchFile")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "copyFileOverwrite, no permission to write to output directory" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputDirNoWrite/outputFile"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "outputDirNoWrite/outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFileOverwrite, cannot open output directory" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/noPerms/outputFile"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "noPerms/outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFileOverwrite, cannot open source directory" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/noPerms/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
copyFileOverwrite' (specDir `ba` "noPerms/inputFile")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFileOverwrite, wrong input type (symlink)" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFileSymL"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
copyFileOverwrite' (specDir `ba` "inputFileSymL")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "copyFileOverwrite, wrong input type (directory)" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/wrongInput"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputFile"
copyFileOverwrite' (specDir `ba` "wrongInput")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "copyFileOverwrite, output file already exists and is a dir" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/alreadyExistsD"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
-- custom failures --
it "copyFileOverwrite, output and input are same file" $
copyFileOverwrite' "test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
"test/FileSystem/FileOperations/copyFileOverwriteSpec/inputFile"
copyFileOverwrite' (specDir `ba` "inputFile")
(specDir `ba` "inputFile")
`shouldThrow` isSameFile

View File

@ -16,8 +16,19 @@ import GHC.IO.Exception
import System.Exit
import System.Process
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/copyFileSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -25,70 +36,70 @@ spec =
-- successes --
it "copyFile, everything clear" $ do
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
removeFileIfExists "test/FileSystem/FileOperations/copyFileSpec/outputFile"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "outputFile")
removeFileIfExists (specDir `ba` "outputFile")
it "copyFile, and compare" $ do
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
(system $ "cmp -s " ++ "test/FileSystem/FileOperations/copyFileSpec/inputFile" ++ " "
++ "test/FileSystem/FileOperations/copyFileSpec/outputFile")
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "outputFile")
(system $ "cmp -s " ++ specDir' ++ "inputFile" ++ " "
++ specDir' ++ "outputFile")
`shouldReturn` ExitSuccess
removeFileIfExists "test/FileSystem/FileOperations/copyFileSpec/outputFile"
removeFileIfExists (specDir `ba` "outputFile")
-- posix failures --
it "copyFile, input file does not exist" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/noSuchFile"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
copyFile' (specDir `ba` "noSuchFile")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "copyFile, no permission to write to output directory" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite/outputFile"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "outputDirNoWrite/outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFile, cannot open output directory" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/noPerms/outputFile"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "noPerms/outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFile, cannot open source directory" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/noPerms/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
copyFile' (specDir `ba` "noPerms/inputFile")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "copyFile, wrong input type (symlink)" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFileSymL"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
copyFile' (specDir `ba` "inputFileSymL")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "copyFile, wrong input type (directory)" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/wrongInput"
"test/FileSystem/FileOperations/copyFileSpec/outputFile"
copyFile' (specDir `ba` "wrongInput")
(specDir `ba` "outputFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "copyFile, output file already exists" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/alreadyExists"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
it "copyFile, output file already exists and is a dir" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/alreadyExistsD"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
-- custom failures --
it "copyFile, output and input are same file" $
copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile"
"test/FileSystem/FileOperations/copyFileSpec/inputFile"
copyFile' (specDir `ba` "inputFile")
(specDir `ba` "inputFile")
`shouldThrow`
isSameFile

View File

@ -13,6 +13,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/createDirSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -21,23 +33,22 @@ spec =
-- successes --
it "createDir, all fine" $ do
createDir' "test/FileSystem/FileOperations/createDirSpec/newDir"
removeDirIfExists "test/FileSystem/FileOperations/createDirSpec/newDir"
createDir' (specDir `ba` "newDir")
removeDirIfExists (specDir `ba` "newDir")
-- posix failures --
it "createDir, can't write to output directory" $
createDir' "test/FileSystem/FileOperations/createDirSpec/noWritePerms/newDir"
createDir' (specDir `ba` "noWritePerms/newDir")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createDir, can't open output directory" $
createDir' "test/FileSystem/FileOperations/createDirSpec/noPerms/newDir"
createDir' (specDir `ba` "noPerms/newDir")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createDir, destination directory already exists" $
createDir' "test/FileSystem/FileOperations/createDirSpec/alreadyExists"
createDir' (specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)

View File

@ -13,6 +13,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/createRegularFileSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -21,22 +33,22 @@ spec =
-- successes --
it "createRegularFile, all fine" $ do
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/newDir"
removeFileIfExists "test/FileSystem/FileOperations/createRegularFileSpec/newDir"
createRegularFile' (specDir `ba` "newDir")
removeFileIfExists (specDir `ba` "newDir")
-- posix failures --
it "createRegularFile, can't write to destination directory" $
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms/newDir"
createRegularFile' (specDir `ba` "noWritePerms/newDir")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createRegularFile, can't write to destination directory" $
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noPerms/newDir"
createRegularFile' (specDir `ba` "noPerms/newDir")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "createRegularFile, destination file already exists" $
createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/alreadyExists"
createRegularFile' (specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)

View File

@ -17,8 +17,19 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/deleteDirRecursiveSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -26,60 +37,60 @@ spec =
-- successes --
it "deleteDirRecursive, empty directory, all fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/testDir"
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/testDir"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteDirRecursiveSpec/testDir"
createDir' (specDir `ba` "testDir")
deleteDirRecursive' (specDir `ba` "testDir")
getSymbolicLinkStatus (specDir `ba` "testDir")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteDirRecursive, empty directory with null permissions, all fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/testDir"
noPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/testDir"
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/testDir"
createDir' (specDir `ba` "noPerms/testDir")
noPerms (specDir `ba` "noPerms/testDir")
deleteDirRecursive' (specDir `ba` "noPerms/testDir")
it "deleteDirRecursive, non-empty directory, all fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty"
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty/dir1"
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty/dir2"
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty/dir2/dir3"
createRegularFile' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty/file1"
createRegularFile' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty/dir1/file2"
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteDirRecursiveSpec/nonEmpty"
createDir' (specDir `ba` "nonEmpty")
createDir' (specDir `ba` "nonEmpty/dir1")
createDir' (specDir `ba` "nonEmpty/dir2")
createDir' (specDir `ba` "nonEmpty/dir2/dir3")
createRegularFile' (specDir `ba` "nonEmpty/file1")
createRegularFile' (specDir `ba` "nonEmpty/dir1/file2")
deleteDirRecursive' (specDir `ba` "nonEmpty")
getSymbolicLinkStatus (specDir `ba` "nonEmpty")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
-- posix failures --
it "deleteDirRecursive, can't open parent directory" $ do
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/foo"
noPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms"
(deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/foo"
createDir' (specDir `ba` "noPerms/foo")
noPerms (specDir `ba` "noPerms")
(deleteDirRecursive' (specDir `ba` "noPerms/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied))
>> normalDirPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms"
>> deleteDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/foo"
>> normalDirPerms (specDir `ba` "noPerms")
>> deleteDir' (specDir `ba` "noPerms/foo")
it "deleteDirRecursive, can't write to parent directory" $ do
createDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/foo"
noWritableDirPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable"
(deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/foo"
createDir' (specDir `ba` "noWritable/foo")
noWritableDirPerms (specDir `ba` "noWritable")
(deleteDirRecursive' (specDir `ba` "noWritable/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied))
normalDirPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable"
deleteDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/foo"
normalDirPerms (specDir `ba` "noWritable")
deleteDir' (specDir `ba` "noWritable/foo")
it "deleteDirRecursive, wrong file type (symlink to directory)" $
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/dirSym"
deleteDirRecursive' (specDir `ba` "dirSym")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDirRecursive, wrong file type (regular file)" $
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/file"
deleteDirRecursive' (specDir `ba` "file")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDirRecursive, directory does not exist" $
deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/doesNotExist"
deleteDirRecursive' (specDir `ba` "doesNotExist")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)

View File

@ -17,6 +17,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/deleteDirSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -25,58 +37,58 @@ spec =
-- successes --
it "deleteDir, empty directory, all fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirSpec/testDir"
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/testDir"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteDirSpec/testDir"
createDir' (specDir `ba` "testDir")
deleteDir' (specDir `ba` "testDir")
getSymbolicLinkStatus (specDir `ba` "testDir")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteDir, directory with null permissions, all fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirSpec/noPerms/testDir"
noPerms "test/FileSystem/FileOperations/deleteDirSpec/noPerms/testDir"
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noPerms/testDir"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteDirSpec/testDir"
createDir' (specDir `ba` "noPerms/testDir")
noPerms (specDir `ba` "noPerms/testDir")
deleteDir' (specDir `ba` "noPerms/testDir")
getSymbolicLinkStatus (specDir `ba` "testDir")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
-- posix failures --
it "deleteDir, wrong file type (symlink to directory)" $
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/dirSym"
deleteDir' (specDir `ba` "dirSym")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDir, wrong file type (regular file)" $
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/file"
deleteDir' (specDir `ba` "file")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteDir, directory does not exist" $
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/doesNotExist"
deleteDir' (specDir `ba` "doesNotExist")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteDir, directory not empty" $
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/dir"
deleteDir' (specDir `ba` "dir")
`shouldThrow`
(\e -> ioeGetErrorType e == UnsatisfiedConstraints)
it "deleteDir, can't open parent directory" $ do
createDir' "test/FileSystem/FileOperations/deleteDirSpec/noPerms/foo"
noPerms "test/FileSystem/FileOperations/deleteDirSpec/noPerms"
(deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noPerms/foo"
createDir' (specDir `ba` "noPerms/foo")
noPerms (specDir `ba` "noPerms")
(deleteDir' (specDir `ba` "noPerms/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied))
>> normalDirPerms "test/FileSystem/FileOperations/deleteDirSpec/noPerms"
>> deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noPerms/foo"
>> normalDirPerms (specDir `ba` "noPerms")
>> deleteDir' (specDir `ba` "noPerms/foo")
it "deleteDir, can't write to parent directory, still fine" $ do
createDir' "test/FileSystem/FileOperations/deleteDirSpec/noWritable/foo"
noWritableDirPerms "test/FileSystem/FileOperations/deleteDirSpec/noWritable"
(deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noWritable/foo"
createDir' (specDir `ba` "noWritable/foo")
noWritableDirPerms (specDir `ba` "noWritable")
(deleteDir' (specDir `ba` "noWritable/foo")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied))
normalDirPerms "test/FileSystem/FileOperations/deleteDirSpec/noWritable"
deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noWritable/foo"
normalDirPerms (specDir `ba` "noWritable")
deleteDir' (specDir `ba` "noWritable/foo")

View File

@ -17,6 +17,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/deleteFileSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -25,33 +37,33 @@ spec =
-- successes --
it "deleteFile, regular file, all fine" $ do
createRegularFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile"
createRegularFile' (specDir `ba` "testFile")
deleteFile' (specDir `ba` "testFile")
getSymbolicLinkStatus (specDir `ba` "testFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteFile, symlink, all fine" $ do
recreateSymlink' "test/FileSystem/FileOperations/deleteFileSpec/syml"
"test/FileSystem/FileOperations/deleteFileSpec/testFile"
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile"
getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile"
recreateSymlink' (specDir `ba` "syml")
(specDir `ba` "testFile")
deleteFile' (specDir `ba` "testFile")
getSymbolicLinkStatus (specDir `ba` "testFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
-- posix failures --
it "deleteFile, wrong file type (directory)" $
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/dir"
deleteFile' (specDir `ba` "dir")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "deleteFile, file does not exist" $
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/doesNotExist"
deleteFile' (specDir `ba` "doesNotExist")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "deleteFile, can't read directory" $
deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/noPerms/blah"
deleteFile' (specDir `ba` "noPerms/blah")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)

View File

@ -26,8 +26,19 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/getDirsFilesSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -36,39 +47,39 @@ spec =
-- successes --
it "getDirsFiles, all fine" $ do
pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs
expectedFiles <- mapM P.parseRel ["test/FileSystem/FileOperations/getDirsFilesSpec/.hidden"
,"test/FileSystem/FileOperations/getDirsFilesSpec/Lala"
,"test/FileSystem/FileOperations/getDirsFilesSpec/dir"
,"test/FileSystem/FileOperations/getDirsFilesSpec/dirsym"
,"test/FileSystem/FileOperations/getDirsFilesSpec/file"
,"test/FileSystem/FileOperations/getDirsFilesSpec/noPerms"
,"test/FileSystem/FileOperations/getDirsFilesSpec/syml"]
(fmap sort $ getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec")
expectedFiles <- mapM P.parseRel [(specDir `ba ` ".hidden")
,(specDir `ba ` "Lala")
,(specDir `ba ` "dir")
,(specDir `ba ` "dirsym")
,(specDir `ba ` "file")
,(specDir `ba ` "noPerms")
,(specDir `ba ` "syml")]
(fmap sort $ getDirsFiles' specDir)
`shouldReturn` fmap (pwd P.</>) expectedFiles
-- posix failures --
it "getDirsFiles, nonexistent directory" $
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/nothingHere"
getDirsFiles' (specDir `ba ` "nothingHere")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "getDirsFiles, wrong file type (file)" $
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/file"
getDirsFiles' (specDir `ba ` "file")
`shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType)
it "getDirsFiles, wrong file type (symlink to file)" $
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/syml"
getDirsFiles' (specDir `ba ` "syml")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "getDirsFiles, wrong file type (symlink to dir)" $
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/dirsym"
getDirsFiles' (specDir `ba ` "dirsym")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "getDirsFiles, can't open directory" $
getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/noPerms"
getDirsFiles' (specDir `ba ` "noPerms")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)

View File

@ -14,8 +14,19 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/getFileTypeSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
spec =
@ -23,37 +34,37 @@ spec =
-- successes --
it "getFileType, regular file" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/regularfile"
getFileType' (specDir `ba` "regularfile")
`shouldReturn` RegularFile
it "getFileType, directory" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/directory"
getFileType' (specDir `ba` "directory")
`shouldReturn` Directory
it "getFileType, directory with null permissions" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/noPerms"
getFileType' (specDir `ba` "noPerms")
`shouldReturn` Directory
it "getFileType, symlink to file" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/symlink"
getFileType' (specDir `ba` "symlink")
`shouldReturn` SymbolicLink
it "getFileType, symlink to directory" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/symlinkD"
getFileType' (specDir `ba` "symlinkD")
`shouldReturn` SymbolicLink
it "getFileType, broken symlink" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/brokenSymlink"
getFileType' (specDir `ba` "brokenSymlink")
`shouldReturn` SymbolicLink
-- posix failures --
it "getFileType, file does not exist" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/nothingHere"
getFileType' (specDir `ba` "nothingHere")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "getFileType, can't open directory" $
getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/noPerms/forz"
getFileType' (specDir `ba` "noPerms/forz")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)

View File

@ -14,6 +14,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/moveFileOverwriteSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -22,60 +34,60 @@ spec =
-- successes --
it "moveFileOverwrite, all fine" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/movedFile"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "movedFile")
it "moveFileOverwrite, all fine" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/dir/movedFile"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "dir/movedFile")
it "moveFileOverwrite, all fine on symlink" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFileL"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/movedFile"
moveFileOverwrite' (specDir `ba` "myFileL")
(specDir `ba` "movedFile")
it "moveFileOverwrite, all fine on directory" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/dir"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/movedFile"
moveFileOverwrite' (specDir `ba` "dir")
(specDir `ba` "movedFile")
it "moveFileOverwrite, destination file already exists" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/alreadyExists"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "alreadyExists")
-- posix failures --
it "moveFileOverwrite, source file does not exist" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/fileDoesNotExist"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/movedFile"
moveFileOverwrite' (specDir `ba` "fileDoesNotExist")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "moveFileOverwrite, can't write to destination directory" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/noWritePerm/movedFile"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "noWritePerm/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "moveFileOverwrite, can't open destination directory" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/noPerms/movedFile"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "noPerms/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "moveFileOverwrite, can't open source directory" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/noPerms/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/movedFile"
moveFileOverwrite' (specDir `ba` "noPerms/myFile")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
-- custom failures --
it "moveFileOverwrite, move from file to dir" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/alreadyExistsD"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
isDirDoesExist
it "moveFileOverwrite, source and dest are same file" $
moveFileOverwrite' "test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
"test/FileSystem/FileOperations/moveFileOverwriteSpec/myFile"
moveFileOverwrite' (specDir `ba` "myFile")
(specDir `ba` "myFile")
`shouldThrow`
isSameFile

View File

@ -14,6 +14,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/moveFileSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -22,62 +34,62 @@ spec =
-- successes --
it "moveFile, all fine" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/movedFile"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "movedFile")
it "moveFile, all fine" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/dir/movedFile"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "dir/movedFile")
it "moveFile, all fine on symlink" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFileL"
"test/FileSystem/FileOperations/moveFileSpec/movedFile"
moveFile' (specDir `ba` "myFileL")
(specDir `ba` "movedFile")
it "moveFile, all fine on directory" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/dir"
"test/FileSystem/FileOperations/moveFileSpec/movedFile"
moveFile' (specDir `ba` "dir")
(specDir `ba` "movedFile")
-- posix failures --
it "moveFile, source file does not exist" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/fileDoesNotExist"
"test/FileSystem/FileOperations/moveFileSpec/movedFile"
moveFile' (specDir `ba` "fileDoesNotExist")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "moveFile, can't write to destination directory" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/noWritePerm/movedFile"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "noWritePerm/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "moveFile, can't open destination directory" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/noPerms/movedFile"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "noPerms/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "moveFile, can't open source directory" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/noPerms/myFile"
"test/FileSystem/FileOperations/moveFileSpec/movedFile"
moveFile' (specDir `ba` "noPerms/myFile")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
-- custom failures --
it "moveFile, destination file already exists" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/alreadyExists"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "alreadyExists")
`shouldThrow`
isFileDoesExist
it "moveFile, move from file to dir" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/alreadyExistsD"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
isDirDoesExist
it "moveFile, source and dest are same file" $
moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile"
"test/FileSystem/FileOperations/moveFileSpec/myFile"
moveFile' (specDir `ba` "myFile")
(specDir `ba` "myFile")
`shouldThrow`
isSameFile

View File

@ -14,6 +14,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/recreateSymlinkSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -22,62 +34,62 @@ spec =
-- successes --
it "recreateSymLink, all fine" $ do
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile"
removeFileIfExists "test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "movedFile")
removeFileIfExists (specDir `ba` "movedFile")
it "recreateSymLink, all fine" $ do
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/dir/movedFile"
removeFileIfExists "test/FileSystem/FileOperations/recreateSymlinkSpec/dir/movedFile"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "dir/movedFile")
removeFileIfExists (specDir `ba` "dir/movedFile")
-- posix failures --
it "recreateSymLink, wrong input type (file)" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFile"
"test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile"
recreateSymlink' (specDir `ba` "myFile")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "recreateSymLink, wrong input type (directory)" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/dir"
"test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile"
recreateSymlink' (specDir `ba` "dir")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == InvalidArgument)
it "recreateSymLink, can't write to destination directory" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm/movedFile"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "noWritePerm/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "recreateSymLink, can't open destination directory" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/movedFile"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "noPerms/movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "recreateSymLink, can't open source directory" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile"
recreateSymlink' (specDir `ba` "noPerms/myFileL")
(specDir `ba` "movedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "recreateSymLink, destination file already exists" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExists"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "alreadyExists")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
it "recreateSymLink, destination already exists and is a dir" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExistsD"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
(\e -> ioeGetErrorType e == AlreadyExists)
-- custom failures --
it "recreateSymLink, source and destination are the same file" $
recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
"test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL"
recreateSymlink' (specDir `ba` "myFileL")
(specDir `ba` "myFileL")
`shouldThrow`
isSameFile

View File

@ -14,6 +14,18 @@ import GHC.IO.Exception
IOErrorType(..)
)
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
ba :: BS.ByteString -> BS.ByteString -> BS.ByteString
ba = BS.append
specDir :: BS.ByteString
specDir = "test/FileSystem/FileOperations/renameFileSpec/"
specDir' :: String
specDir' = toString specDir
spec :: Spec
@ -22,62 +34,62 @@ spec =
-- successes --
it "renameFile, all fine" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/renamedFile"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "renamedFile")
it "renameFile, all fine" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/dir/renamedFile"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "dir/renamedFile")
it "renameFile, all fine on symlink" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFileL"
"test/FileSystem/FileOperations/renameFileSpec/renamedFile"
renameFile' (specDir `ba` "myFileL")
(specDir `ba` "renamedFile")
it "renameFile, all fine on directory" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/dir"
"test/FileSystem/FileOperations/renameFileSpec/renamedFile"
renameFile' (specDir `ba` "dir")
(specDir `ba` "renamedFile")
-- posix failures --
it "renameFile, source file does not exist" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/fileDoesNotExist"
"test/FileSystem/FileOperations/renameFileSpec/renamedFile"
renameFile' (specDir `ba` "fileDoesNotExist")
(specDir `ba` "renamedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "renameFile, can't write to output directory" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/noWritePerm/renamedFile"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "noWritePerm/renamedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "renameFile, can't open output directory" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/noPerms/renamedFile"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "noPerms/renamedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
it "renameFile, can't open source directory" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/noPerms/myFile"
"test/FileSystem/FileOperations/renameFileSpec/renamedFile"
renameFile' (specDir `ba` "noPerms/myFile")
(specDir `ba` "renamedFile")
`shouldThrow`
(\e -> ioeGetErrorType e == PermissionDenied)
-- custom failures --
it "renameFile, destination file already exists" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/alreadyExists"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "alreadyExists")
`shouldThrow`
isFileDoesExist
it "renameFile, move from file to dir" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/alreadyExistsD"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "alreadyExistsD")
`shouldThrow`
isDirDoesExist
it "renameFile, source and dest are same file" $
renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile"
"test/FileSystem/FileOperations/renameFileSpec/myFile"
renameFile' (specDir `ba` "myFile")
(specDir `ba` "myFile")
`shouldThrow`
isSameFile