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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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