diff --git a/hsfm.cabal b/hsfm.cabal index cc27bbf..ec54d8a 100644 --- a/hsfm.cabal +++ b/hsfm.cabal @@ -119,18 +119,18 @@ Test-Suite spec Hs-Source-Dirs: test Main-Is: Spec.hs other-modules: - CopyDirRecursiveSpec - CopyFileSpec - CreateDirSpec - CreateRegularFileSpec - DeleteDirRecursiveSpec - DeleteDirSpec - DeleteFileSpec - GetDirsFilesSpec - GetFileTypeSpec - MoveFileSpec - RecreateSymlinkSpec - RenameFileSpec + FileSystem.FileOperations.CopyDirRecursiveSpec + FileSystem.FileOperations.CopyFileSpec + FileSystem.FileOperations.CreateDirSpec + FileSystem.FileOperations.CreateRegularFileSpec + FileSystem.FileOperations.DeleteDirRecursiveSpec + FileSystem.FileOperations.DeleteDirSpec + FileSystem.FileOperations.DeleteFileSpec + FileSystem.FileOperations.GetDirsFilesSpec + FileSystem.FileOperations.GetFileTypeSpec + FileSystem.FileOperations.MoveFileSpec + FileSystem.FileOperations.RecreateSymlinkSpec + FileSystem.FileOperations.RenameFileSpec Utils GHC-Options: -Wall Build-Depends: base diff --git a/test/CopyDirRecursiveSpec.hs b/test/CopyDirRecursiveSpec.hs deleted file mode 100644 index daac6e4..0000000 --- a/test/CopyDirRecursiveSpec.hs +++ /dev/null @@ -1,102 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module CopyDirRecursiveSpec where - - -import Test.Hspec -import HSFM.FileSystem.Errors -import System.IO.Error - ( - ioeGetErrorType - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import System.Exit -import System.Process -import Utils - - - -copyDirRecursiveSpec :: Spec -copyDirRecursiveSpec = - describe "HSFM.FileSystem.FileOperations.copyDirRecursive" $ do - - -- successes -- - it "copyDirRecursive, all fine" $ do - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/outputDir" - removeDirIfExists "test/copyDirRecursiveSpec/outputDir" - - it "copyDirRecursive, all fine and compare" $ do - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/outputDir" - (system $ "diff -r --no-dereference " - ++ "test/copyDirRecursiveSpec/inputDir" ++ " " - ++ "test/copyDirRecursiveSpec/outputDir") - `shouldReturn` ExitSuccess - removeDirIfExists "test/copyDirRecursiveSpec/outputDir" - - -- posix failures -- - it "copyDirRecursive, source directory does not exist" $ - copyDirRecursive' "test/copyDirRecursiveSpec/doesNotExist" - "test/copyDirRecursiveSpec/outputDir" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "copyDirRecursive, no write permission on output dir" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/noWritePerm/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyDirRecursive, cannot open output dir" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/noPerms/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyDirRecursive, cannot open source dir" $ - copyDirRecursive' "test/copyDirRecursiveSpec/noPerms/inputDir" - "test/copyDirRecursiveSpec/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyDirRecursive, destination dir already exists" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/alreadyExistsD" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "copyDirRecursive, destination already exists and is a file" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/alreadyExists" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "copyDirRecursive, destination and source same directory" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/inputDir" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "copyDirRecursive, wrong input (regular file)" $ - copyDirRecursive' "test/copyDirRecursiveSpec/wrongInput" - "test/copyDirRecursiveSpec/outputDir" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "copyDirRecursive, wrong input (symlink to directory)" $ - copyDirRecursive' "test/copyDirRecursiveSpec/wrongInputSymL" - "test/copyDirRecursiveSpec/outputDir" - `shouldThrow` - (\e -> ioeGetErrorType e == InvalidArgument) - - -- custom failures - it "copyDirRecursive, destination in source" $ - copyDirRecursive' "test/copyDirRecursiveSpec/inputDir" - "test/copyDirRecursiveSpec/inputDir/foo" - `shouldThrow` - isDestinationInSource - diff --git a/test/CopyFileSpec.hs b/test/CopyFileSpec.hs deleted file mode 100644 index fa36695..0000000 --- a/test/CopyFileSpec.hs +++ /dev/null @@ -1,93 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module CopyFileSpec where - - -import Test.Hspec -import System.IO.Error - ( - ioeGetErrorType - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import System.Exit -import System.Process -import Utils - - - -copyFileSpec :: Spec -copyFileSpec = - describe "HSFM.FileSystem.FileOperations.copyFile" $ do - - -- successes -- - it "copyFile, everything clear" $ do - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/outputFile" - removeFileIfExists "test/copyFileSpec/outputFile" - - it "copyFile, and compare" $ do - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/outputFile" - (system $ "cmp -s " ++ "test/copyFileSpec/inputFile" ++ " " - ++ "test/copyFileSpec/outputFile") - `shouldReturn` ExitSuccess - removeFileIfExists "test/copyFileSpec/outputFile" - - -- posix failures -- - it "copyFile, input file does not exist" $ - copyFile' "test/copyFileSpec/noSuchFile" - "test/copyFileSpec/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "copyFile, no permission to write to output directory" $ - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/outputDirNoWrite/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyFile, cannot open output directory" $ - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/noPerms/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyFile, cannot open source directory" $ - copyFile' "test/copyFileSpec/noPerms/inputFile" - "test/copyFileSpec/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "copyFile, wrong input type (symlink)" $ - copyFile' "test/copyFileSpec/inputFileSymL" - "test/copyFileSpec/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == InvalidArgument) - - it "copyFile, wrong input type (directory)" $ - copyFile' "test/copyFileSpec/wrongInput" - "test/copyFileSpec/outputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "copyFile, output and input are same file" $ - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/inputFile" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "copyFile, output file already exists" $ - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/alreadyExists" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "copyFile, output file already exists and is a dir" $ - copyFile' "test/copyFileSpec/inputFile" - "test/copyFileSpec/alreadyExistsD" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - diff --git a/test/DeleteDirRecursiveSpec.hs b/test/DeleteDirRecursiveSpec.hs deleted file mode 100644 index f8d6e51..0000000 --- a/test/DeleteDirRecursiveSpec.hs +++ /dev/null @@ -1,85 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module DeleteDirRecursiveSpec where - - -import Test.Hspec -import System.IO.Error - ( - ioeGetErrorType - ) -import System.Posix.Files.ByteString - ( - getSymbolicLinkStatus - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import Utils - - -deleteDirRecursiveSpec :: Spec -deleteDirRecursiveSpec = - describe "HSFM.FileSystem.FileOperations.deleteDirRecursive" $ do - - -- successes -- - it "deleteDirRecursive, empty directory, all fine" $ do - createDir' "test/deleteDirRecursiveSpec/testDir" - deleteDirRecursive' "test/deleteDirRecursiveSpec/testDir" - getSymbolicLinkStatus "test/deleteDirRecursiveSpec/testDir" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "deleteDirRecursive, empty directory with null permissions, all fine" $ do - createDir' "test/deleteDirRecursiveSpec/noPerms/testDir" - noPerms "test/deleteDirRecursiveSpec/noPerms/testDir" - deleteDirRecursive' "test/deleteDirRecursiveSpec/noPerms/testDir" - - it "deleteDirRecursive, non-empty directory, all fine" $ do - createDir' "test/deleteDirRecursiveSpec/nonEmpty" - createDir' "test/deleteDirRecursiveSpec/nonEmpty/dir1" - createDir' "test/deleteDirRecursiveSpec/nonEmpty/dir2" - createDir' "test/deleteDirRecursiveSpec/nonEmpty/dir2/dir3" - createRegularFile' "test/deleteDirRecursiveSpec/nonEmpty/file1" - createRegularFile' "test/deleteDirRecursiveSpec/nonEmpty/dir1/file2" - deleteDirRecursive' "test/deleteDirRecursiveSpec/nonEmpty" - getSymbolicLinkStatus "test/deleteDirRecursiveSpec/nonEmpty" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - -- posix failures -- - it "deleteDirRecursive, can't open parent directory" $ do - createDir' "test/deleteDirRecursiveSpec/noPerms/foo" - noPerms "test/deleteDirRecursiveSpec/noPerms" - (deleteDirRecursive' "test/deleteDirRecursiveSpec/noPerms/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied)) - >> normalDirPerms "test/deleteDirRecursiveSpec/noPerms" - >> deleteDir' "test/deleteDirRecursiveSpec/noPerms/foo" - - it "deleteDirRecursive, can't write to parent directory" $ do - createDir' "test/deleteDirRecursiveSpec/noWritable/foo" - noWritableDirPerms "test/deleteDirRecursiveSpec/noWritable" - (deleteDirRecursive' "test/deleteDirRecursiveSpec/noWritable/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied)) - normalDirPerms "test/deleteDirRecursiveSpec/noWritable" - deleteDir' "test/deleteDirRecursiveSpec/noWritable/foo" - - it "deleteDirRecursive, wrong file type (symlink to directory)" $ - deleteDirRecursive' "test/deleteDirRecursiveSpec/dirSym" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "deleteDirRecursive, wrong file type (regular file)" $ - deleteDirRecursive' "test/deleteDirRecursiveSpec/file" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "deleteDirRecursive, directory does not exist" $ - deleteDirRecursive' "test/deleteDirRecursiveSpec/doesNotExist" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - diff --git a/test/DeleteDirSpec.hs b/test/DeleteDirSpec.hs deleted file mode 100644 index 5651232..0000000 --- a/test/DeleteDirSpec.hs +++ /dev/null @@ -1,82 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module DeleteDirSpec where - - -import Test.Hspec -import System.IO.Error - ( - ioeGetErrorType - ) -import System.Posix.Files.ByteString - ( - getSymbolicLinkStatus - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import Utils - - -deleteDirSpec :: Spec -deleteDirSpec = - describe "HSFM.FileSystem.FileOperations.deleteDir" $ do - - -- successes -- - it "deleteDir, empty directory, all fine" $ do - createDir' "test/deleteDirSpec/testDir" - deleteDir' "test/deleteDirSpec/testDir" - getSymbolicLinkStatus "test/deleteDirSpec/testDir" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "deleteDir, directory with null permissions, all fine" $ do - createDir' "test/deleteDirSpec/noPerms/testDir" - noPerms "test/deleteDirSpec/noPerms/testDir" - deleteDir' "test/deleteDirSpec/noPerms/testDir" - getSymbolicLinkStatus "test/deleteDirSpec/testDir" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - -- posix failures -- - it "deleteDir, wrong file type (symlink to directory)" $ - deleteDir' "test/deleteDirSpec/dirSym" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "deleteDir, wrong file type (regular file)" $ - deleteDir' "test/deleteDirSpec/file" - `shouldThrow` - (\e -> ioeGetErrorType e == InappropriateType) - - it "deleteDir, directory does not exist" $ - deleteDir' "test/deleteDirSpec/doesNotExist" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "deleteDir, directory not empty" $ - deleteDir' "test/deleteDirSpec/dir" - `shouldThrow` - (\e -> ioeGetErrorType e == UnsatisfiedConstraints) - - it "deleteDir, can't open parent directory" $ do - createDir' "test/deleteDirSpec/noPerms/foo" - noPerms "test/deleteDirSpec/noPerms" - (deleteDir' "test/deleteDirSpec/noPerms/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied)) - >> normalDirPerms "test/deleteDirSpec/noPerms" - >> deleteDir' "test/deleteDirSpec/noPerms/foo" - - it "deleteDir, can't write to parent directory, still fine" $ do - createDir' "test/deleteDirSpec/noWritable/foo" - noWritableDirPerms "test/deleteDirSpec/noWritable" - (deleteDir' "test/deleteDirSpec/noWritable/foo" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied)) - normalDirPerms "test/deleteDirSpec/noWritable" - deleteDir' "test/deleteDirSpec/noWritable/foo" - - - diff --git a/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs b/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs new file mode 100644 index 0000000..6c35c69 --- /dev/null +++ b/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs @@ -0,0 +1,102 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.CopyDirRecursiveSpec where + + +import Test.Hspec +import HSFM.FileSystem.Errors +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import System.Exit +import System.Process +import Utils + + + +copyDirRecursiveSpec :: Spec +copyDirRecursiveSpec = + describe "HSFM.FileSystem.FileOperations.copyDirRecursive" $ do + + -- successes -- + it "copyDirRecursive, all fine" $ do + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir" + removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir" + + it "copyDirRecursive, all fine and compare" $ do + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir" + (system $ "diff -r --no-dereference " + ++ "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" ++ " " + ++ "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir") + `shouldReturn` ExitSuccess + removeDirIfExists "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir" + + -- posix failures -- + it "copyDirRecursive, source directory does not exist" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/doesNotExist" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "copyDirRecursive, cannot open output dir" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "copyDirRecursive, destination dir already exists" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + + it "copyDirRecursive, destination and source same directory" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + + it "copyDirRecursive, wrong input (regular file)" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInput" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/outputDir" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "copyDirRecursive, wrong input (symlink to directory)" $ + copyDirRecursive' "test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInputSymL" + "test/FileSystem/FileOperations/copyDirRecursiveSpec/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" + `shouldThrow` + isDestinationInSource + diff --git a/test/FileSystem/FileOperations/CopyFileSpec.hs b/test/FileSystem/FileOperations/CopyFileSpec.hs new file mode 100644 index 0000000..39b2859 --- /dev/null +++ b/test/FileSystem/FileOperations/CopyFileSpec.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.CopyFileSpec where + + +import Test.Hspec +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import System.Exit +import System.Process +import Utils + + + +copyFileSpec :: Spec +copyFileSpec = + describe "HSFM.FileSystem.FileOperations.copyFile" $ do + + -- successes -- + it "copyFile, everything clear" $ do + copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile" + "test/FileSystem/FileOperations/copyFileSpec/outputFile" + removeFileIfExists "test/FileSystem/FileOperations/copyFileSpec/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") + `shouldReturn` ExitSuccess + removeFileIfExists "test/FileSystem/FileOperations/copyFileSpec/outputFile" + + -- posix failures -- + it "copyFile, input file does not exist" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/noSuchFile" + "test/FileSystem/FileOperations/copyFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "copyFile, cannot open output directory" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile" + "test/FileSystem/FileOperations/copyFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "copyFile, wrong input type (symlink)" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFileSymL" + "test/FileSystem/FileOperations/copyFileSpec/outputFile" + `shouldThrow` + (\e -> ioeGetErrorType e == InvalidArgument) + + it "copyFile, wrong input type (directory)" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/wrongInput" + "test/FileSystem/FileOperations/copyFileSpec/outputFile" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "copyFile, output and input are same file" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile" + "test/FileSystem/FileOperations/copyFileSpec/inputFile" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + + it "copyFile, output file already exists" $ + copyFile' "test/FileSystem/FileOperations/copyFileSpec/inputFile" + "test/FileSystem/FileOperations/copyFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + diff --git a/test/CreateDirSpec.hs b/test/FileSystem/FileOperations/CreateDirSpec.hs similarity index 62% rename from test/CreateDirSpec.hs rename to test/FileSystem/FileOperations/CreateDirSpec.hs index a31e250..d1326cc 100644 --- a/test/CreateDirSpec.hs +++ b/test/FileSystem/FileOperations/CreateDirSpec.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module CreateDirSpec where +module FileSystem.FileOperations.CreateDirSpec where import Test.Hspec @@ -21,22 +21,22 @@ createDirSpec = -- successes -- it "createDir, all fine" $ do - createDir' "test/createDirSpec/newDir" - removeDirIfExists "test/createDirSpec/newDir" + createDir' "test/FileSystem/FileOperations/createDirSpec/newDir" + removeDirIfExists "test/FileSystem/FileOperations/createDirSpec/newDir" -- posix failures -- it "createDir, can't write to output directory" $ - createDir' "test/createDirSpec/noWritePerms/newDir" + createDir' "test/FileSystem/FileOperations/createDirSpec/noWritePerms/newDir" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) it "createDir, can't open output directory" $ - createDir' "test/createDirSpec/noPerms/newDir" + createDir' "test/FileSystem/FileOperations/createDirSpec/noPerms/newDir" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) it "createDir, destination directory already exists" $ - createDir' "test/createDirSpec/alreadyExists" + createDir' "test/FileSystem/FileOperations/createDirSpec/alreadyExists" `shouldThrow` (\e -> ioeGetErrorType e == AlreadyExists) diff --git a/test/CreateRegularFileSpec.hs b/test/FileSystem/FileOperations/CreateRegularFileSpec.hs similarity index 60% rename from test/CreateRegularFileSpec.hs rename to test/FileSystem/FileOperations/CreateRegularFileSpec.hs index 76117e1..26c004a 100644 --- a/test/CreateRegularFileSpec.hs +++ b/test/FileSystem/FileOperations/CreateRegularFileSpec.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module CreateRegularFileSpec where +module FileSystem.FileOperations.CreateRegularFileSpec where import Test.Hspec @@ -21,22 +21,22 @@ createRegularFileSpec = -- successes -- it "createRegularFile, all fine" $ do - createRegularFile' "test/createRegularFileSpec/newDir" - removeFileIfExists "test/createRegularFileSpec/newDir" + createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/newDir" + removeFileIfExists "test/FileSystem/FileOperations/createRegularFileSpec/newDir" -- posix failures -- it "createRegularFile, can't write to destination directory" $ - createRegularFile' "test/createRegularFileSpec/noWritePerms/newDir" + createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms/newDir" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) it "createRegularFile, can't write to destination directory" $ - createRegularFile' "test/createRegularFileSpec/noPerms/newDir" + createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/noPerms/newDir" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) it "createRegularFile, destination file already exists" $ - createRegularFile' "test/createRegularFileSpec/alreadyExists" + createRegularFile' "test/FileSystem/FileOperations/createRegularFileSpec/alreadyExists" `shouldThrow` (\e -> ioeGetErrorType e == AlreadyExists) diff --git a/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs b/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs new file mode 100644 index 0000000..75e9d7b --- /dev/null +++ b/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs @@ -0,0 +1,86 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.DeleteDirRecursiveSpec where + + +import Test.Hspec +import System.IO.Error + ( + ioeGetErrorType + ) +import System.Posix.Files.ByteString + ( + getSymbolicLinkStatus + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils + + + +deleteDirRecursiveSpec :: Spec +deleteDirRecursiveSpec = + describe "HSFM.FileSystem.FileOperations.deleteDirRecursive" $ do + + -- 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" + `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" + + 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" + `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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied)) + >> normalDirPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms" + >> deleteDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied)) + normalDirPerms "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable" + deleteDir' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/foo" + + it "deleteDirRecursive, wrong file type (symlink to directory)" $ + deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/dirSym" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "deleteDirRecursive, wrong file type (regular file)" $ + deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/file" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "deleteDirRecursive, directory does not exist" $ + deleteDirRecursive' "test/FileSystem/FileOperations/deleteDirRecursiveSpec/doesNotExist" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + + diff --git a/test/FileSystem/FileOperations/DeleteDirSpec.hs b/test/FileSystem/FileOperations/DeleteDirSpec.hs new file mode 100644 index 0000000..2767cc1 --- /dev/null +++ b/test/FileSystem/FileOperations/DeleteDirSpec.hs @@ -0,0 +1,82 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.DeleteDirSpec where + + +import Test.Hspec +import System.IO.Error + ( + ioeGetErrorType + ) +import System.Posix.Files.ByteString + ( + getSymbolicLinkStatus + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils + + +deleteDirSpec :: Spec +deleteDirSpec = + describe "HSFM.FileSystem.FileOperations.deleteDir" $ do + + -- 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" + `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" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + + -- posix failures -- + it "deleteDir, wrong file type (symlink to directory)" $ + deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/dirSym" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "deleteDir, wrong file type (regular file)" $ + deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/file" + `shouldThrow` + (\e -> ioeGetErrorType e == InappropriateType) + + it "deleteDir, directory does not exist" $ + deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/doesNotExist" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + + it "deleteDir, directory not empty" $ + deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied)) + >> normalDirPerms "test/FileSystem/FileOperations/deleteDirSpec/noPerms" + >> deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied)) + normalDirPerms "test/FileSystem/FileOperations/deleteDirSpec/noWritable" + deleteDir' "test/FileSystem/FileOperations/deleteDirSpec/noWritable/foo" + + + diff --git a/test/DeleteFileSpec.hs b/test/FileSystem/FileOperations/DeleteFileSpec.hs similarity index 54% rename from test/DeleteFileSpec.hs rename to test/FileSystem/FileOperations/DeleteFileSpec.hs index 84a9c63..37d4e71 100644 --- a/test/DeleteFileSpec.hs +++ b/test/FileSystem/FileOperations/DeleteFileSpec.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module DeleteFileSpec where +module FileSystem.FileOperations.DeleteFileSpec where import Test.Hspec @@ -25,33 +25,33 @@ deleteFileSpec = -- successes -- it "deleteFile, regular file, all fine" $ do - createRegularFile' "test/deleteFileSpec/testFile" - deleteFile' "test/deleteFileSpec/testFile" - getSymbolicLinkStatus "test/deleteFileSpec/testFile" + createRegularFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile" + deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile" + getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing) it "deleteFile, symlink, all fine" $ do - recreateSymlink' "test/deleteFileSpec/syml" - "test/deleteFileSpec/testFile" - deleteFile' "test/deleteFileSpec/testFile" - getSymbolicLinkStatus "test/deleteFileSpec/testFile" + recreateSymlink' "test/FileSystem/FileOperations/deleteFileSpec/syml" + "test/FileSystem/FileOperations/deleteFileSpec/testFile" + deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/testFile" + getSymbolicLinkStatus "test/FileSystem/FileOperations/deleteFileSpec/testFile" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing) -- posix failures -- it "deleteFile, wrong file type (directory)" $ - deleteFile' "test/deleteFileSpec/dir" + deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/dir" `shouldThrow` (\e -> ioeGetErrorType e == InappropriateType) it "deleteFile, file does not exist" $ - deleteFile' "test/deleteFileSpec/doesNotExist" + deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/doesNotExist" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing) it "deleteFile, can't read directory" $ - deleteFile' "test/deleteFileSpec/noPerms/blah" + deleteFile' "test/FileSystem/FileOperations/deleteFileSpec/noPerms/blah" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) diff --git a/test/GetDirsFilesSpec.hs b/test/FileSystem/FileOperations/GetDirsFilesSpec.hs similarity index 51% rename from test/GetDirsFilesSpec.hs rename to test/FileSystem/FileOperations/GetDirsFilesSpec.hs index 5c2cd54..19e4b77 100644 --- a/test/GetDirsFilesSpec.hs +++ b/test/FileSystem/FileOperations/GetDirsFilesSpec.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module GetDirsFilesSpec where +module FileSystem.FileOperations.GetDirsFilesSpec where import Data.List @@ -36,39 +36,39 @@ getDirsFilesSpec = -- successes -- it "getDirsFiles, all fine" $ do pwd <- fromJust <$> getEnv "PWD" >>= P.parseAbs - expectedFiles <- mapM P.parseRel ["test/getDirsFilesSpec/.hidden" - ,"test/getDirsFilesSpec/Lala" - ,"test/getDirsFilesSpec/dir" - ,"test/getDirsFilesSpec/dirsym" - ,"test/getDirsFilesSpec/file" - ,"test/getDirsFilesSpec/noPerms" - ,"test/getDirsFilesSpec/syml"] - (fmap sort $ getDirsFiles' "test/getDirsFilesSpec") + 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") `shouldReturn` fmap (pwd P.) expectedFiles -- posix failures -- it "getDirsFiles, nonexistent directory" $ - getDirsFiles' "test/getDirsFilesSpec/nothingHere" + getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/nothingHere" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing) it "getDirsFiles, wrong file type (file)" $ - getDirsFiles' "test/getDirsFilesSpec/file" + getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/file" `shouldThrow` (\e -> ioeGetErrorType e == InappropriateType) it "getDirsFiles, wrong file type (symlink to file)" $ - getDirsFiles' "test/getDirsFilesSpec/syml" + getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/syml" `shouldThrow` (\e -> ioeGetErrorType e == InvalidArgument) it "getDirsFiles, wrong file type (symlink to dir)" $ - getDirsFiles' "test/getDirsFilesSpec/dirsym" + getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/dirsym" `shouldThrow` (\e -> ioeGetErrorType e == InvalidArgument) it "getDirsFiles, can't open directory" $ - getDirsFiles' "test/getDirsFilesSpec/noPerms" + getDirsFiles' "test/FileSystem/FileOperations/getDirsFilesSpec/noPerms" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) diff --git a/test/GetFileTypeSpec.hs b/test/FileSystem/FileOperations/GetFileTypeSpec.hs similarity index 60% rename from test/GetFileTypeSpec.hs rename to test/FileSystem/FileOperations/GetFileTypeSpec.hs index 554b700..16b9c12 100644 --- a/test/GetFileTypeSpec.hs +++ b/test/FileSystem/FileOperations/GetFileTypeSpec.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module GetFileTypeSpec where +module FileSystem.FileOperations.GetFileTypeSpec where import HSFM.FileSystem.FileOperations @@ -23,37 +23,37 @@ getFileTypeSpec = -- successes -- it "getFileType, regular file" $ - getFileType' "test/getFileTypeSpec/regularfile" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/regularfile" `shouldReturn` RegularFile it "getFileType, directory" $ - getFileType' "test/getFileTypeSpec/directory" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/directory" `shouldReturn` Directory it "getFileType, directory with null permissions" $ - getFileType' "test/getFileTypeSpec/noPerms" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/noPerms" `shouldReturn` Directory it "getFileType, symlink to file" $ - getFileType' "test/getFileTypeSpec/symlink" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/symlink" `shouldReturn` SymbolicLink it "getFileType, symlink to directory" $ - getFileType' "test/getFileTypeSpec/symlinkD" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/symlinkD" `shouldReturn` SymbolicLink it "getFileType, broken symlink" $ - getFileType' "test/getFileTypeSpec/brokenSymlink" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/brokenSymlink" `shouldReturn` SymbolicLink -- posix failures -- it "getFileType, file does not exist" $ - getFileType' "test/getFileTypeSpec/nothingHere" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/nothingHere" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing) it "getFileType, can't open directory" $ - getFileType' "test/getFileTypeSpec/noPerms/forz" + getFileType' "test/FileSystem/FileOperations/getFileTypeSpec/noPerms/forz" `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied) diff --git a/test/FileSystem/FileOperations/MoveFileSpec.hs b/test/FileSystem/FileOperations/MoveFileSpec.hs new file mode 100644 index 0000000..338dc78 --- /dev/null +++ b/test/FileSystem/FileOperations/MoveFileSpec.hs @@ -0,0 +1,83 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.MoveFileSpec where + + +import Test.Hspec +import HSFM.FileSystem.Errors +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils + + +moveFileSpec :: Spec +moveFileSpec = + describe "HSFM.FileSystem.FileOperations.moveFile" $ do + + -- successes -- + it "moveFile, all fine" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/movedFile" + + it "moveFile, all fine" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/dir/movedFile" + + it "moveFile, all fine on symlink" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFileL" + "test/FileSystem/FileOperations/moveFileSpec/movedFile" + + it "moveFile, all fine on directory" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/dir" + "test/FileSystem/FileOperations/moveFileSpec/movedFile" + + -- posix failures -- + it "moveFile, source file does not exist" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/fileDoesNotExist" + "test/FileSystem/FileOperations/moveFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "moveFile, can't open destination directory" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + -- custom failures -- + it "moveFile, destination file already exists" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/alreadyExists" + `shouldThrow` + isFileDoesExist + + it "moveFile, move from file to dir" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/alreadyExistsD" + `shouldThrow` + isDirDoesExist + + it "moveFile, source and dest are same file" $ + moveFile' "test/FileSystem/FileOperations/moveFileSpec/myFile" + "test/FileSystem/FileOperations/moveFileSpec/myFile" + `shouldThrow` + isSameFile + diff --git a/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs b/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs new file mode 100644 index 0000000..e236033 --- /dev/null +++ b/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs @@ -0,0 +1,81 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.RecreateSymlinkSpec where + + +import Test.Hspec +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils + + +recreateSymlinkSpec :: Spec +recreateSymlinkSpec = + describe "HSFM.FileSystem.FileOperations.recreateSymlink" $ do + + -- successes -- + it "recreateSymLink, all fine" $ do + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL" + "test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile" + removeFileIfExists "test/FileSystem/FileOperations/recreateSymlinkSpec/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" + + -- posix failures -- + it "recreateSymLink, wrong input type (file)" $ + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFile" + "test/FileSystem/FileOperations/recreateSymlinkSpec/movedFile" + `shouldThrow` + (\e -> ioeGetErrorType e == InvalidArgument) + + it "recreateSymLink, wrong input type (directory)" $ + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/dir" + "test/FileSystem/FileOperations/recreateSymlinkSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "recreateSymLink, can't open destination directory" $ + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL" + "test/FileSystem/FileOperations/recreateSymlinkSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "recreateSymLink, destination file already exists" $ + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL" + "test/FileSystem/FileOperations/recreateSymlinkSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + + it "recreateSymLink, source and destination are the same file" $ + recreateSymlink' "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL" + "test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) + diff --git a/test/FileSystem/FileOperations/RenameFileSpec.hs b/test/FileSystem/FileOperations/RenameFileSpec.hs new file mode 100644 index 0000000..9dc955f --- /dev/null +++ b/test/FileSystem/FileOperations/RenameFileSpec.hs @@ -0,0 +1,83 @@ +{-# LANGUAGE OverloadedStrings #-} + +module FileSystem.FileOperations.RenameFileSpec where + + +import Test.Hspec +import HSFM.FileSystem.Errors +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils + + +renameFileSpec :: Spec +renameFileSpec = + describe "HSFM.FileSystem.FileOperations.renameFile" $ do + + -- successes -- + it "renameFile, all fine" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/renamedFile" + + it "renameFile, all fine" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/dir/renamedFile" + + it "renameFile, all fine on symlink" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFileL" + "test/FileSystem/FileOperations/renameFileSpec/renamedFile" + + it "renameFile, all fine on directory" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/dir" + "test/FileSystem/FileOperations/renameFileSpec/renamedFile" + + -- posix failures -- + it "renameFile, source file does not exist" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/fileDoesNotExist" + "test/FileSystem/FileOperations/renameFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "renameFile, can't open output directory" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/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" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + -- custom failures -- + it "renameFile, destination file already exists" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/alreadyExists" + `shouldThrow` + isFileDoesExist + + it "renameFile, move from file to dir" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/alreadyExistsD" + `shouldThrow` + isDirDoesExist + + it "renameFile, source and dest are same file" $ + renameFile' "test/FileSystem/FileOperations/renameFileSpec/myFile" + "test/FileSystem/FileOperations/renameFileSpec/myFile" + `shouldThrow` + isSameFile + diff --git a/test/copyDirRecursiveSpec/alreadyExists b/test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExists similarity index 100% rename from test/copyDirRecursiveSpec/alreadyExists rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExists diff --git a/test/copyDirRecursiveSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExistsD/.keep similarity index 100% rename from test/copyDirRecursiveSpec/alreadyExistsD/.keep rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/alreadyExistsD/.keep diff --git a/test/copyDirRecursiveSpec/inputDir/bar/inputFile3 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/bar/inputFile3 similarity index 100% rename from test/copyDirRecursiveSpec/inputDir/bar/inputFile3 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/bar/inputFile3 diff --git a/test/copyDirRecursiveSpec/inputDir/foo/inputFile1 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/foo/inputFile1 similarity index 100% rename from test/copyDirRecursiveSpec/inputDir/foo/inputFile1 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/foo/inputFile1 diff --git a/test/copyDirRecursiveSpec/inputDir/inputFile2 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/inputFile2 similarity index 100% rename from test/copyDirRecursiveSpec/inputDir/inputFile2 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/inputDir/inputFile2 diff --git a/test/copyDirRecursiveSpec/noPerms/inputDir/bar/inputFile3 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/bar/inputFile3 similarity index 100% rename from test/copyDirRecursiveSpec/noPerms/inputDir/bar/inputFile3 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/bar/inputFile3 diff --git a/test/copyDirRecursiveSpec/noPerms/inputDir/foo/inputFile1 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/foo/inputFile1 similarity index 100% rename from test/copyDirRecursiveSpec/noPerms/inputDir/foo/inputFile1 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/foo/inputFile1 diff --git a/test/copyDirRecursiveSpec/noPerms/inputDir/inputFile2 b/test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/inputFile2 similarity index 100% rename from test/copyDirRecursiveSpec/noPerms/inputDir/inputFile2 rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms/inputDir/inputFile2 diff --git a/test/copyDirRecursiveSpec/noWritePerm/.keep b/test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm/.keep similarity index 100% rename from test/copyDirRecursiveSpec/noWritePerm/.keep rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm/.keep diff --git a/test/copyDirRecursiveSpec/wrongInput b/test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInput similarity index 100% rename from test/copyDirRecursiveSpec/wrongInput rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInput diff --git a/test/copyDirRecursiveSpec/wrongInputSymL b/test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInputSymL similarity index 100% rename from test/copyDirRecursiveSpec/wrongInputSymL rename to test/FileSystem/FileOperations/copyDirRecursiveSpec/wrongInputSymL diff --git a/test/copyFileSpec/alreadyExists b/test/FileSystem/FileOperations/copyFileSpec/alreadyExists similarity index 100% rename from test/copyFileSpec/alreadyExists rename to test/FileSystem/FileOperations/copyFileSpec/alreadyExists diff --git a/test/copyFileSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/copyFileSpec/alreadyExistsD/.keep similarity index 100% rename from test/copyFileSpec/alreadyExistsD/.keep rename to test/FileSystem/FileOperations/copyFileSpec/alreadyExistsD/.keep diff --git a/test/copyFileSpec/inputFile b/test/FileSystem/FileOperations/copyFileSpec/inputFile similarity index 100% rename from test/copyFileSpec/inputFile rename to test/FileSystem/FileOperations/copyFileSpec/inputFile diff --git a/test/copyFileSpec/inputFileSymL b/test/FileSystem/FileOperations/copyFileSpec/inputFileSymL similarity index 100% rename from test/copyFileSpec/inputFileSymL rename to test/FileSystem/FileOperations/copyFileSpec/inputFileSymL diff --git a/test/copyFileSpec/noPerms/inputFile b/test/FileSystem/FileOperations/copyFileSpec/noPerms/inputFile similarity index 100% rename from test/copyFileSpec/noPerms/inputFile rename to test/FileSystem/FileOperations/copyFileSpec/noPerms/inputFile diff --git a/test/copyFileSpec/outputDirNoWrite/.keep b/test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite/.keep similarity index 100% rename from test/copyFileSpec/outputDirNoWrite/.keep rename to test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite/.keep diff --git a/test/copyFileSpec/wrongInput/.keep b/test/FileSystem/FileOperations/copyFileSpec/wrongInput/.keep similarity index 100% rename from test/copyFileSpec/wrongInput/.keep rename to test/FileSystem/FileOperations/copyFileSpec/wrongInput/.keep diff --git a/test/createDirSpec/.keep b/test/FileSystem/FileOperations/createDirSpec/.keep similarity index 100% rename from test/createDirSpec/.keep rename to test/FileSystem/FileOperations/createDirSpec/.keep diff --git a/test/createDirSpec/alreadyExists/.keep b/test/FileSystem/FileOperations/createDirSpec/alreadyExists/.keep similarity index 100% rename from test/createDirSpec/alreadyExists/.keep rename to test/FileSystem/FileOperations/createDirSpec/alreadyExists/.keep diff --git a/test/createDirSpec/noPerms/.keep b/test/FileSystem/FileOperations/createDirSpec/noPerms/.keep similarity index 100% rename from test/createDirSpec/noPerms/.keep rename to test/FileSystem/FileOperations/createDirSpec/noPerms/.keep diff --git a/test/createDirSpec/noWritePerms/.keep b/test/FileSystem/FileOperations/createDirSpec/noWritePerms/.keep similarity index 100% rename from test/createDirSpec/noWritePerms/.keep rename to test/FileSystem/FileOperations/createDirSpec/noWritePerms/.keep diff --git a/test/createRegularFileSpec/alreadyExists b/test/FileSystem/FileOperations/createRegularFileSpec/alreadyExists similarity index 100% rename from test/createRegularFileSpec/alreadyExists rename to test/FileSystem/FileOperations/createRegularFileSpec/alreadyExists diff --git a/test/createRegularFileSpec/noPerms/.keep b/test/FileSystem/FileOperations/createRegularFileSpec/noPerms/.keep similarity index 100% rename from test/createRegularFileSpec/noPerms/.keep rename to test/FileSystem/FileOperations/createRegularFileSpec/noPerms/.keep diff --git a/test/createRegularFileSpec/noWritePerms/.keep b/test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms/.keep similarity index 100% rename from test/createRegularFileSpec/noWritePerms/.keep rename to test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms/.keep diff --git a/test/deleteDirRecursiveSpec/.keep b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/.keep similarity index 100% rename from test/deleteDirRecursiveSpec/.keep rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/.keep diff --git a/test/deleteDirRecursiveSpec/dir/.keep b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/dir/.keep similarity index 100% rename from test/deleteDirRecursiveSpec/dir/.keep rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/dir/.keep diff --git a/test/deleteDirRecursiveSpec/dirSym b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/dirSym similarity index 100% rename from test/deleteDirRecursiveSpec/dirSym rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/dirSym diff --git a/test/deleteDirRecursiveSpec/file b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/file similarity index 100% rename from test/deleteDirRecursiveSpec/file rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/file diff --git a/test/deleteDirRecursiveSpec/noPerms/.keep b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/.keep similarity index 100% rename from test/deleteDirRecursiveSpec/noPerms/.keep rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/noPerms/.keep diff --git a/test/deleteDirRecursiveSpec/noWritable/.keep b/test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/.keep similarity index 100% rename from test/deleteDirRecursiveSpec/noWritable/.keep rename to test/FileSystem/FileOperations/deleteDirRecursiveSpec/noWritable/.keep diff --git a/test/deleteDirSpec/.keep b/test/FileSystem/FileOperations/deleteDirSpec/.keep similarity index 100% rename from test/deleteDirSpec/.keep rename to test/FileSystem/FileOperations/deleteDirSpec/.keep diff --git a/test/deleteDirSpec/dir/.keep b/test/FileSystem/FileOperations/deleteDirSpec/dir/.keep similarity index 100% rename from test/deleteDirSpec/dir/.keep rename to test/FileSystem/FileOperations/deleteDirSpec/dir/.keep diff --git a/test/deleteDirSpec/dirSym b/test/FileSystem/FileOperations/deleteDirSpec/dirSym similarity index 100% rename from test/deleteDirSpec/dirSym rename to test/FileSystem/FileOperations/deleteDirSpec/dirSym diff --git a/test/deleteDirSpec/file b/test/FileSystem/FileOperations/deleteDirSpec/file similarity index 100% rename from test/deleteDirSpec/file rename to test/FileSystem/FileOperations/deleteDirSpec/file diff --git a/test/deleteDirSpec/noPerms/.keep b/test/FileSystem/FileOperations/deleteDirSpec/noPerms/.keep similarity index 100% rename from test/deleteDirSpec/noPerms/.keep rename to test/FileSystem/FileOperations/deleteDirSpec/noPerms/.keep diff --git a/test/deleteDirSpec/noWritable/.keep b/test/FileSystem/FileOperations/deleteDirSpec/noWritable/.keep similarity index 100% rename from test/deleteDirSpec/noWritable/.keep rename to test/FileSystem/FileOperations/deleteDirSpec/noWritable/.keep diff --git a/test/deleteFileSpec/dir/.keep b/test/FileSystem/FileOperations/deleteFileSpec/dir/.keep similarity index 100% rename from test/deleteFileSpec/dir/.keep rename to test/FileSystem/FileOperations/deleteFileSpec/dir/.keep diff --git a/test/deleteFileSpec/foo b/test/FileSystem/FileOperations/deleteFileSpec/foo similarity index 100% rename from test/deleteFileSpec/foo rename to test/FileSystem/FileOperations/deleteFileSpec/foo diff --git a/test/deleteFileSpec/noPerms/blah b/test/FileSystem/FileOperations/deleteFileSpec/noPerms/blah similarity index 100% rename from test/deleteFileSpec/noPerms/blah rename to test/FileSystem/FileOperations/deleteFileSpec/noPerms/blah diff --git a/test/deleteFileSpec/syml b/test/FileSystem/FileOperations/deleteFileSpec/syml similarity index 100% rename from test/deleteFileSpec/syml rename to test/FileSystem/FileOperations/deleteFileSpec/syml diff --git a/test/getDirsFilesSpec/.hidden b/test/FileSystem/FileOperations/getDirsFilesSpec/.hidden similarity index 100% rename from test/getDirsFilesSpec/.hidden rename to test/FileSystem/FileOperations/getDirsFilesSpec/.hidden diff --git a/test/getDirsFilesSpec/Lala b/test/FileSystem/FileOperations/getDirsFilesSpec/Lala similarity index 100% rename from test/getDirsFilesSpec/Lala rename to test/FileSystem/FileOperations/getDirsFilesSpec/Lala diff --git a/test/getDirsFilesSpec/dirsym b/test/FileSystem/FileOperations/getDirsFilesSpec/dirsym similarity index 100% rename from test/getDirsFilesSpec/dirsym rename to test/FileSystem/FileOperations/getDirsFilesSpec/dirsym diff --git a/test/getDirsFilesSpec/file b/test/FileSystem/FileOperations/getDirsFilesSpec/file similarity index 100% rename from test/getDirsFilesSpec/file rename to test/FileSystem/FileOperations/getDirsFilesSpec/file diff --git a/test/getDirsFilesSpec/noPerms/.keep b/test/FileSystem/FileOperations/getDirsFilesSpec/noPerms/.keep similarity index 100% rename from test/getDirsFilesSpec/noPerms/.keep rename to test/FileSystem/FileOperations/getDirsFilesSpec/noPerms/.keep diff --git a/test/getDirsFilesSpec/syml b/test/FileSystem/FileOperations/getDirsFilesSpec/syml similarity index 100% rename from test/getDirsFilesSpec/syml rename to test/FileSystem/FileOperations/getDirsFilesSpec/syml diff --git a/test/getFileTypeSpec/brokenSymlink b/test/FileSystem/FileOperations/getFileTypeSpec/brokenSymlink similarity index 100% rename from test/getFileTypeSpec/brokenSymlink rename to test/FileSystem/FileOperations/getFileTypeSpec/brokenSymlink diff --git a/test/getFileTypeSpec/directory/.keep b/test/FileSystem/FileOperations/getFileTypeSpec/directory/.keep similarity index 100% rename from test/getFileTypeSpec/directory/.keep rename to test/FileSystem/FileOperations/getFileTypeSpec/directory/.keep diff --git a/test/getFileTypeSpec/noPerms/.keep b/test/FileSystem/FileOperations/getFileTypeSpec/noPerms/.keep similarity index 100% rename from test/getFileTypeSpec/noPerms/.keep rename to test/FileSystem/FileOperations/getFileTypeSpec/noPerms/.keep diff --git a/test/getFileTypeSpec/regularfile b/test/FileSystem/FileOperations/getFileTypeSpec/regularfile similarity index 100% rename from test/getFileTypeSpec/regularfile rename to test/FileSystem/FileOperations/getFileTypeSpec/regularfile diff --git a/test/getFileTypeSpec/symlink b/test/FileSystem/FileOperations/getFileTypeSpec/symlink similarity index 100% rename from test/getFileTypeSpec/symlink rename to test/FileSystem/FileOperations/getFileTypeSpec/symlink diff --git a/test/getFileTypeSpec/symlinkD b/test/FileSystem/FileOperations/getFileTypeSpec/symlinkD similarity index 100% rename from test/getFileTypeSpec/symlinkD rename to test/FileSystem/FileOperations/getFileTypeSpec/symlinkD diff --git a/test/moveFileSpec/alreadyExists b/test/FileSystem/FileOperations/moveFileSpec/alreadyExists similarity index 100% rename from test/moveFileSpec/alreadyExists rename to test/FileSystem/FileOperations/moveFileSpec/alreadyExists diff --git a/test/moveFileSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/moveFileSpec/alreadyExistsD/.keep similarity index 100% rename from test/moveFileSpec/alreadyExistsD/.keep rename to test/FileSystem/FileOperations/moveFileSpec/alreadyExistsD/.keep diff --git a/test/moveFileSpec/dir/.keep b/test/FileSystem/FileOperations/moveFileSpec/dir/.keep similarity index 100% rename from test/moveFileSpec/dir/.keep rename to test/FileSystem/FileOperations/moveFileSpec/dir/.keep diff --git a/test/moveFileSpec/myFile b/test/FileSystem/FileOperations/moveFileSpec/myFile similarity index 100% rename from test/moveFileSpec/myFile rename to test/FileSystem/FileOperations/moveFileSpec/myFile diff --git a/test/moveFileSpec/myFileL b/test/FileSystem/FileOperations/moveFileSpec/myFileL similarity index 100% rename from test/moveFileSpec/myFileL rename to test/FileSystem/FileOperations/moveFileSpec/myFileL diff --git a/test/moveFileSpec/noPerms/myFile b/test/FileSystem/FileOperations/moveFileSpec/noPerms/myFile similarity index 100% rename from test/moveFileSpec/noPerms/myFile rename to test/FileSystem/FileOperations/moveFileSpec/noPerms/myFile diff --git a/test/moveFileSpec/noWritePerm/.keep b/test/FileSystem/FileOperations/moveFileSpec/noWritePerm/.keep similarity index 100% rename from test/moveFileSpec/noWritePerm/.keep rename to test/FileSystem/FileOperations/moveFileSpec/noWritePerm/.keep diff --git a/test/recreateSymlinkSpec/alreadyExists b/test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExists similarity index 100% rename from test/recreateSymlinkSpec/alreadyExists rename to test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExists diff --git a/test/recreateSymlinkSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExistsD/.keep similarity index 100% rename from test/recreateSymlinkSpec/alreadyExistsD/.keep rename to test/FileSystem/FileOperations/recreateSymlinkSpec/alreadyExistsD/.keep diff --git a/test/recreateSymlinkSpec/dir/.keep b/test/FileSystem/FileOperations/recreateSymlinkSpec/dir/.keep similarity index 100% rename from test/recreateSymlinkSpec/dir/.keep rename to test/FileSystem/FileOperations/recreateSymlinkSpec/dir/.keep diff --git a/test/recreateSymlinkSpec/myFile b/test/FileSystem/FileOperations/recreateSymlinkSpec/myFile similarity index 100% rename from test/recreateSymlinkSpec/myFile rename to test/FileSystem/FileOperations/recreateSymlinkSpec/myFile diff --git a/test/recreateSymlinkSpec/myFileL b/test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL similarity index 100% rename from test/recreateSymlinkSpec/myFileL rename to test/FileSystem/FileOperations/recreateSymlinkSpec/myFileL diff --git a/test/recreateSymlinkSpec/noPerms/myFile b/test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/myFile similarity index 100% rename from test/recreateSymlinkSpec/noPerms/myFile rename to test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/myFile diff --git a/test/recreateSymlinkSpec/noPerms/myFileL b/test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/myFileL similarity index 100% rename from test/recreateSymlinkSpec/noPerms/myFileL rename to test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms/myFileL diff --git a/test/recreateSymlinkSpec/noWritePerm/.keep b/test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm/.keep similarity index 100% rename from test/recreateSymlinkSpec/noWritePerm/.keep rename to test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm/.keep diff --git a/test/renameFileSpec/alreadyExists b/test/FileSystem/FileOperations/renameFileSpec/alreadyExists similarity index 100% rename from test/renameFileSpec/alreadyExists rename to test/FileSystem/FileOperations/renameFileSpec/alreadyExists diff --git a/test/renameFileSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/renameFileSpec/alreadyExistsD/.keep similarity index 100% rename from test/renameFileSpec/alreadyExistsD/.keep rename to test/FileSystem/FileOperations/renameFileSpec/alreadyExistsD/.keep diff --git a/test/renameFileSpec/dir/.keep b/test/FileSystem/FileOperations/renameFileSpec/dir/.keep similarity index 100% rename from test/renameFileSpec/dir/.keep rename to test/FileSystem/FileOperations/renameFileSpec/dir/.keep diff --git a/test/renameFileSpec/myFile b/test/FileSystem/FileOperations/renameFileSpec/myFile similarity index 100% rename from test/renameFileSpec/myFile rename to test/FileSystem/FileOperations/renameFileSpec/myFile diff --git a/test/renameFileSpec/myFileL b/test/FileSystem/FileOperations/renameFileSpec/myFileL similarity index 100% rename from test/renameFileSpec/myFileL rename to test/FileSystem/FileOperations/renameFileSpec/myFileL diff --git a/test/renameFileSpec/noPerms/myFile b/test/FileSystem/FileOperations/renameFileSpec/noPerms/myFile similarity index 100% rename from test/renameFileSpec/noPerms/myFile rename to test/FileSystem/FileOperations/renameFileSpec/noPerms/myFile diff --git a/test/renameFileSpec/noWritePerm/.keep b/test/FileSystem/FileOperations/renameFileSpec/noWritePerm/.keep similarity index 100% rename from test/renameFileSpec/noWritePerm/.keep rename to test/FileSystem/FileOperations/renameFileSpec/noWritePerm/.keep diff --git a/test/MoveFileSpec.hs b/test/MoveFileSpec.hs deleted file mode 100644 index d570926..0000000 --- a/test/MoveFileSpec.hs +++ /dev/null @@ -1,83 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module MoveFileSpec where - - -import Test.Hspec -import HSFM.FileSystem.Errors -import System.IO.Error - ( - ioeGetErrorType - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import Utils - - -moveFileSpec :: Spec -moveFileSpec = - describe "HSFM.FileSystem.FileOperations.moveFile" $ do - - -- successes -- - it "moveFile, all fine" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/movedFile" - - it "moveFile, all fine" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/dir/movedFile" - - it "moveFile, all fine on symlink" $ - moveFile' "test/moveFileSpec/myFileL" - "test/moveFileSpec/movedFile" - - it "moveFile, all fine on directory" $ - moveFile' "test/moveFileSpec/dir" - "test/moveFileSpec/movedFile" - - -- posix failures -- - it "moveFile, source file does not exist" $ - moveFile' "test/moveFileSpec/fileDoesNotExist" - "test/moveFileSpec/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "moveFile, can't write to destination directory" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/noWritePerm/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "moveFile, can't open destination directory" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/noPerms/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "moveFile, can't open source directory" $ - moveFile' "test/moveFileSpec/noPerms/myFile" - "test/moveFileSpec/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - -- custom failures -- - it "moveFile, destination file already exists" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/alreadyExists" - `shouldThrow` - isFileDoesExist - - it "moveFile, move from file to dir" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/alreadyExistsD" - `shouldThrow` - isDirDoesExist - - it "moveFile, source and dest are same file" $ - moveFile' "test/moveFileSpec/myFile" - "test/moveFileSpec/myFile" - `shouldThrow` - isSameFile - diff --git a/test/RecreateSymlinkSpec.hs b/test/RecreateSymlinkSpec.hs deleted file mode 100644 index 289f70e..0000000 --- a/test/RecreateSymlinkSpec.hs +++ /dev/null @@ -1,81 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module RecreateSymlinkSpec where - - -import Test.Hspec -import System.IO.Error - ( - ioeGetErrorType - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import Utils - - -recreateSymlinkSpec :: Spec -recreateSymlinkSpec = - describe "HSFM.FileSystem.FileOperations.recreateSymlink" $ do - - -- successes -- - it "recreateSymLink, all fine" $ do - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/movedFile" - removeFileIfExists "test/recreateSymlinkSpec/movedFile" - - it "recreateSymLink, all fine" $ do - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/dir/movedFile" - removeFileIfExists "test/recreateSymlinkSpec/dir/movedFile" - - -- posix failures -- - it "recreateSymLink, wrong input type (file)" $ - recreateSymlink' "test/recreateSymlinkSpec/myFile" - "test/recreateSymlinkSpec/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == InvalidArgument) - - it "recreateSymLink, wrong input type (directory)" $ - recreateSymlink' "test/recreateSymlinkSpec/dir" - "test/recreateSymlinkSpec/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == InvalidArgument) - - it "recreateSymLink, can't write to destination directory" $ - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/noWritePerm/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "recreateSymLink, can't open destination directory" $ - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/noPerms/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "recreateSymLink, can't open source directory" $ - recreateSymlink' "test/recreateSymlinkSpec/noPerms/myFileL" - "test/recreateSymlinkSpec/movedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "recreateSymLink, destination file already exists" $ - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/alreadyExists" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "recreateSymLink, destination already exists and is a dir" $ - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/alreadyExistsD" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - - it "recreateSymLink, source and destination are the same file" $ - recreateSymlink' "test/recreateSymlinkSpec/myFileL" - "test/recreateSymlinkSpec/myFileL" - `shouldThrow` - (\e -> ioeGetErrorType e == AlreadyExists) - diff --git a/test/RenameFileSpec.hs b/test/RenameFileSpec.hs deleted file mode 100644 index 506b598..0000000 --- a/test/RenameFileSpec.hs +++ /dev/null @@ -1,83 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module RenameFileSpec where - - -import Test.Hspec -import HSFM.FileSystem.Errors -import System.IO.Error - ( - ioeGetErrorType - ) -import GHC.IO.Exception - ( - IOErrorType(..) - ) -import Utils - - -renameFileSpec :: Spec -renameFileSpec = - describe "HSFM.FileSystem.FileOperations.renameFile" $ do - - -- successes -- - it "renameFile, all fine" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/renamedFile" - - it "renameFile, all fine" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/dir/renamedFile" - - it "renameFile, all fine on symlink" $ - renameFile' "test/renameFileSpec/myFileL" - "test/renameFileSpec/renamedFile" - - it "renameFile, all fine on directory" $ - renameFile' "test/renameFileSpec/dir" - "test/renameFileSpec/renamedFile" - - -- posix failures -- - it "renameFile, source file does not exist" $ - renameFile' "test/renameFileSpec/fileDoesNotExist" - "test/renameFileSpec/renamedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == NoSuchThing) - - it "renameFile, can't write to output directory" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/noWritePerm/renamedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "renameFile, can't open output directory" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/noPerms/renamedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - it "renameFile, can't open source directory" $ - renameFile' "test/renameFileSpec/noPerms/myFile" - "test/renameFileSpec/renamedFile" - `shouldThrow` - (\e -> ioeGetErrorType e == PermissionDenied) - - -- custom failures -- - it "renameFile, destination file already exists" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/alreadyExists" - `shouldThrow` - isFileDoesExist - - it "renameFile, move from file to dir" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/alreadyExistsD" - `shouldThrow` - isDirDoesExist - - it "renameFile, source and dest are same file" $ - renameFile' "test/renameFileSpec/myFile" - "test/renameFileSpec/myFile" - `shouldThrow` - isSameFile - diff --git a/test/Spec.hs b/test/Spec.hs index fb6acc6..51abb76 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -2,22 +2,21 @@ import Test.Hspec -import CopyDirRecursiveSpec -import CopyFileSpec -import CreateDirSpec -import CreateRegularFileSpec -import DeleteDirRecursiveSpec -import DeleteDirSpec -import DeleteFileSpec -import GetDirsFilesSpec -import GetFileTypeSpec -import MoveFileSpec -import RecreateSymlinkSpec -import RenameFileSpec +import FileSystem.FileOperations.CopyDirRecursiveSpec +import FileSystem.FileOperations.CopyFileSpec +import FileSystem.FileOperations.CreateDirSpec +import FileSystem.FileOperations.CreateRegularFileSpec +import FileSystem.FileOperations.DeleteDirRecursiveSpec +import FileSystem.FileOperations.DeleteDirSpec +import FileSystem.FileOperations.DeleteFileSpec +import FileSystem.FileOperations.GetDirsFilesSpec +import FileSystem.FileOperations.GetFileTypeSpec +import FileSystem.FileOperations.MoveFileSpec +import FileSystem.FileOperations.RecreateSymlinkSpec +import FileSystem.FileOperations.RenameFileSpec import Utils - -- TODO: chardev, blockdev, namedpipe, socket @@ -44,24 +43,24 @@ main = hspec $ before_ fixPermissions $ after_ revertPermissions $ do getDirsFilesSpec where - noWriteDirs = ["test/copyFileSpec/outputDirNoWrite" - ,"test/copyDirRecursiveSpec/noWritePerm" - ,"test/createDirSpec/noWritePerms" - ,"test/createRegularFileSpec/noWritePerms" - ,"test/renameFileSpec/noWritePerm" - ,"test/moveFileSpec/noWritePerm" - ,"test/recreateSymlinkSpec/noWritePerm" + noWriteDirs = ["test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite" + ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm" + ,"test/FileSystem/FileOperations/createDirSpec/noWritePerms" + ,"test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms" + ,"test/FileSystem/FileOperations/renameFileSpec/noWritePerm" + ,"test/FileSystem/FileOperations/moveFileSpec/noWritePerm" + ,"test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm" ] - noPermsDirs = ["test/copyFileSpec/noPerms" - ,"test/copyDirRecursiveSpec/noPerms" - ,"test/createDirSpec/noPerms" - ,"test/createRegularFileSpec/noPerms" - ,"test/renameFileSpec/noPerms" - ,"test/moveFileSpec/noPerms" - ,"test/recreateSymlinkSpec/noPerms" - ,"test/getFileTypeSpec/noPerms" - ,"test/getDirsFilesSpec/noPerms" - ,"test/deleteFileSpec/noPerms" + noPermsDirs = ["test/FileSystem/FileOperations/copyFileSpec/noPerms" + ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms" + ,"test/FileSystem/FileOperations/createDirSpec/noPerms" + ,"test/FileSystem/FileOperations/createRegularFileSpec/noPerms" + ,"test/FileSystem/FileOperations/renameFileSpec/noPerms" + ,"test/FileSystem/FileOperations/moveFileSpec/noPerms" + ,"test/FileSystem/FileOperations/recreateSymlinkSpec/noPerms" + ,"test/FileSystem/FileOperations/getFileTypeSpec/noPerms" + ,"test/FileSystem/FileOperations/getDirsFilesSpec/noPerms" + ,"test/FileSystem/FileOperations/deleteFileSpec/noPerms" ] fixPermissions = do sequence_ $ fmap noWritableDirPerms noWriteDirs