diff --git a/hsfm.cabal b/hsfm.cabal index 7d46d46..d479e1c 100644 --- a/hsfm.cabal +++ b/hsfm.cabal @@ -119,8 +119,9 @@ Test-Suite spec Type: exitcode-stdio-1.0 Default-Language: Haskell2010 Hs-Source-Dirs: test - Main-Is: Spec.hs + Main-Is: Main.hs other-modules: + Spec FileSystem.FileOperations.CopyDirRecursiveSpec FileSystem.FileOperations.CopyDirRecursiveOverwriteSpec FileSystem.FileOperations.CopyFileSpec diff --git a/test/FileSystem/FileOperations/CopyDirRecursiveOverwriteSpec.hs b/test/FileSystem/FileOperations/CopyDirRecursiveOverwriteSpec.hs index fc1b446..eba2b36 100644 --- a/test/FileSystem/FileOperations/CopyDirRecursiveOverwriteSpec.hs +++ b/test/FileSystem/FileOperations/CopyDirRecursiveOverwriteSpec.hs @@ -19,8 +19,8 @@ import Utils -copyDirRecursiveOverwriteSpec :: Spec -copyDirRecursiveOverwriteSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.copyDirRecursiveOverwrite" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs b/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs index 00cd977..37781ed 100644 --- a/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs +++ b/test/FileSystem/FileOperations/CopyDirRecursiveSpec.hs @@ -19,8 +19,8 @@ import Utils -copyDirRecursiveSpec :: Spec -copyDirRecursiveSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.copyDirRecursive" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/CopyFileOverwriteSpec.hs b/test/FileSystem/FileOperations/CopyFileOverwriteSpec.hs index cdc093f..f91f928 100644 --- a/test/FileSystem/FileOperations/CopyFileOverwriteSpec.hs +++ b/test/FileSystem/FileOperations/CopyFileOverwriteSpec.hs @@ -19,8 +19,8 @@ import Utils -copyFileOverwriteSpec :: Spec -copyFileOverwriteSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.copyFileOverwrite" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/CopyFileSpec.hs b/test/FileSystem/FileOperations/CopyFileSpec.hs index 38948a3..676aed5 100644 --- a/test/FileSystem/FileOperations/CopyFileSpec.hs +++ b/test/FileSystem/FileOperations/CopyFileSpec.hs @@ -19,8 +19,8 @@ import Utils -copyFileSpec :: Spec -copyFileSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.copyFile" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/CreateDirSpec.hs b/test/FileSystem/FileOperations/CreateDirSpec.hs index d1326cc..4d0e409 100644 --- a/test/FileSystem/FileOperations/CreateDirSpec.hs +++ b/test/FileSystem/FileOperations/CreateDirSpec.hs @@ -15,8 +15,8 @@ import GHC.IO.Exception import Utils -createDirSpec :: Spec -createDirSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.createDir" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/CreateRegularFileSpec.hs b/test/FileSystem/FileOperations/CreateRegularFileSpec.hs index 26c004a..721e43f 100644 --- a/test/FileSystem/FileOperations/CreateRegularFileSpec.hs +++ b/test/FileSystem/FileOperations/CreateRegularFileSpec.hs @@ -15,8 +15,8 @@ import GHC.IO.Exception import Utils -createRegularFileSpec :: Spec -createRegularFileSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.createRegularFile" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs b/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs index 75e9d7b..6ee1e76 100644 --- a/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs +++ b/test/FileSystem/FileOperations/DeleteDirRecursiveSpec.hs @@ -20,8 +20,8 @@ import Utils -deleteDirRecursiveSpec :: Spec -deleteDirRecursiveSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.deleteDirRecursive" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/DeleteDirSpec.hs b/test/FileSystem/FileOperations/DeleteDirSpec.hs index 2767cc1..5b7d909 100644 --- a/test/FileSystem/FileOperations/DeleteDirSpec.hs +++ b/test/FileSystem/FileOperations/DeleteDirSpec.hs @@ -19,8 +19,8 @@ import GHC.IO.Exception import Utils -deleteDirSpec :: Spec -deleteDirSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.deleteDir" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/DeleteFileSpec.hs b/test/FileSystem/FileOperations/DeleteFileSpec.hs index 37d4e71..d404aa3 100644 --- a/test/FileSystem/FileOperations/DeleteFileSpec.hs +++ b/test/FileSystem/FileOperations/DeleteFileSpec.hs @@ -19,8 +19,8 @@ import GHC.IO.Exception import Utils -deleteFileSpec :: Spec -deleteFileSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.deleteFile" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/GetDirsFilesSpec.hs b/test/FileSystem/FileOperations/GetDirsFilesSpec.hs index 19e4b77..a0e5a13 100644 --- a/test/FileSystem/FileOperations/GetDirsFilesSpec.hs +++ b/test/FileSystem/FileOperations/GetDirsFilesSpec.hs @@ -29,8 +29,8 @@ import Utils -getDirsFilesSpec :: Spec -getDirsFilesSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.getDirsFiles" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/GetFileTypeSpec.hs b/test/FileSystem/FileOperations/GetFileTypeSpec.hs index 16b9c12..98c2acd 100644 --- a/test/FileSystem/FileOperations/GetFileTypeSpec.hs +++ b/test/FileSystem/FileOperations/GetFileTypeSpec.hs @@ -17,8 +17,8 @@ import Utils -getFileTypeSpec :: Spec -getFileTypeSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.getFileType" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/MoveFileOverwriteSpec.hs b/test/FileSystem/FileOperations/MoveFileOverwriteSpec.hs index 489883c..60083b6 100644 --- a/test/FileSystem/FileOperations/MoveFileOverwriteSpec.hs +++ b/test/FileSystem/FileOperations/MoveFileOverwriteSpec.hs @@ -16,8 +16,8 @@ import GHC.IO.Exception import Utils -moveFileOverwriteSpec :: Spec -moveFileOverwriteSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.moveFileOverwrite" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/MoveFileSpec.hs b/test/FileSystem/FileOperations/MoveFileSpec.hs index 338dc78..a07512f 100644 --- a/test/FileSystem/FileOperations/MoveFileSpec.hs +++ b/test/FileSystem/FileOperations/MoveFileSpec.hs @@ -16,8 +16,8 @@ import GHC.IO.Exception import Utils -moveFileSpec :: Spec -moveFileSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.moveFile" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs b/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs index 4641a9e..6da6cb4 100644 --- a/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs +++ b/test/FileSystem/FileOperations/RecreateSymlinkSpec.hs @@ -16,8 +16,8 @@ import GHC.IO.Exception import Utils -recreateSymlinkSpec :: Spec -recreateSymlinkSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.recreateSymlink" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/RenameFileSpec.hs b/test/FileSystem/FileOperations/RenameFileSpec.hs index 9dc955f..d773662 100644 --- a/test/FileSystem/FileOperations/RenameFileSpec.hs +++ b/test/FileSystem/FileOperations/RenameFileSpec.hs @@ -16,8 +16,8 @@ import GHC.IO.Exception import Utils -renameFileSpec :: Spec -renameFileSpec = +spec :: Spec +spec = describe "HSFM.FileSystem.FileOperations.renameFile" $ do -- successes -- diff --git a/test/FileSystem/FileOperations/moveFileOverwriteSpec/alreadyExistsD/.keep b/test/FileSystem/FileOperations/moveFileOverwriteSpec/alreadyExistsD/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..e729f88 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,53 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Test.Hspec +import Test.Hspec.Runner +import Test.Hspec.Formatters +import qualified Spec +import Utils + + +-- TODO: chardev, blockdev, namedpipe, socket + + +main :: IO () +main = + hspecWith + defaultConfig { configFormatter = Just progress } + $ before_ fixPermissions + $ after_ revertPermissions + $ Spec.spec >> Spec.spec + where + noWriteDirs = ["test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite" + ,"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputDirNoWrite" + ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm" + ,"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noWritePerm" + ,"test/FileSystem/FileOperations/createDirSpec/noWritePerms" + ,"test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms" + ,"test/FileSystem/FileOperations/renameFileSpec/noWritePerm" + ,"test/FileSystem/FileOperations/moveFileSpec/noWritePerm" + ,"test/FileSystem/FileOperations/moveFileOverwriteSpec/noWritePerm" + ,"test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm" + ] + noPermsDirs = ["test/FileSystem/FileOperations/copyFileSpec/noPerms" + ,"test/FileSystem/FileOperations/copyFileOverwriteSpec/noPerms" + ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms" + ,"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noPerms" + ,"test/FileSystem/FileOperations/createDirSpec/noPerms" + ,"test/FileSystem/FileOperations/createRegularFileSpec/noPerms" + ,"test/FileSystem/FileOperations/renameFileSpec/noPerms" + ,"test/FileSystem/FileOperations/moveFileSpec/noPerms" + ,"test/FileSystem/FileOperations/moveFileOverwriteSpec/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 + sequence_ $ fmap noPerms noPermsDirs + revertPermissions = do + sequence_ $ fmap normalDirPerms noWriteDirs + sequence_ $ fmap normalDirPerms noPermsDirs + + diff --git a/test/Spec.hs b/test/Spec.hs index 6e25b02..939c0ff 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,83 +1,2 @@ -{-# LANGUAGE OverloadedStrings #-} - -import Test.Hspec - -import FileSystem.FileOperations.CopyDirRecursiveSpec -import FileSystem.FileOperations.CopyDirRecursiveOverwriteSpec -import FileSystem.FileOperations.CopyFileOverwriteSpec -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.MoveFileOverwriteSpec -import FileSystem.FileOperations.RecreateSymlinkSpec -import FileSystem.FileOperations.RenameFileSpec -import Utils - - --- TODO: chardev, blockdev, namedpipe, socket - - -main :: IO () -main = hspec $ before_ fixPermissions $ after_ revertPermissions $ do - let tests = [copyFileSpec - ,copyFileOverwriteSpec - ,copyDirRecursiveSpec - ,copyDirRecursiveOverwriteSpec - ,createDirSpec - ,createRegularFileSpec - ,renameFileSpec - ,moveFileSpec - ,moveFileOverwriteSpec - ,recreateSymlinkSpec - ,deleteFileSpec - ,deleteDirSpec - ,deleteDirRecursiveSpec - ] - - -- run all stateful tests twice to catch missing cleanups or state skew - sequence_ tests - sequence_ tests - - -- stateless tests - getFileTypeSpec - getDirsFilesSpec - - where - noWriteDirs = ["test/FileSystem/FileOperations/copyFileSpec/outputDirNoWrite" - ,"test/FileSystem/FileOperations/copyFileOverwriteSpec/outputDirNoWrite" - ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noWritePerm" - ,"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noWritePerm" - ,"test/FileSystem/FileOperations/createDirSpec/noWritePerms" - ,"test/FileSystem/FileOperations/createRegularFileSpec/noWritePerms" - ,"test/FileSystem/FileOperations/renameFileSpec/noWritePerm" - ,"test/FileSystem/FileOperations/moveFileSpec/noWritePerm" - ,"test/FileSystem/FileOperations/moveFileOverwriteSpec/noWritePerm" - ,"test/FileSystem/FileOperations/recreateSymlinkSpec/noWritePerm" - ] - noPermsDirs = ["test/FileSystem/FileOperations/copyFileSpec/noPerms" - ,"test/FileSystem/FileOperations/copyFileOverwriteSpec/noPerms" - ,"test/FileSystem/FileOperations/copyDirRecursiveSpec/noPerms" - ,"test/FileSystem/FileOperations/copyDirRecursiveOverwriteSpec/noPerms" - ,"test/FileSystem/FileOperations/createDirSpec/noPerms" - ,"test/FileSystem/FileOperations/createRegularFileSpec/noPerms" - ,"test/FileSystem/FileOperations/renameFileSpec/noPerms" - ,"test/FileSystem/FileOperations/moveFileSpec/noPerms" - ,"test/FileSystem/FileOperations/moveFileOverwriteSpec/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 - sequence_ $ fmap noPerms noPermsDirs - revertPermissions = do - sequence_ $ fmap normalDirPerms noWriteDirs - sequence_ $ fmap normalDirPerms noPermsDirs - +-- file test/Spec.hs +{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}