TESTS: use hspec-discover

This commit is contained in:
Julian Ospald 2016-05-08 23:45:51 +02:00
parent 5b6a342a9e
commit c89d6b945c
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
19 changed files with 87 additions and 114 deletions

View File

@ -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

View File

@ -19,8 +19,8 @@ import Utils
copyDirRecursiveOverwriteSpec :: Spec
copyDirRecursiveOverwriteSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.copyDirRecursiveOverwrite" $ do
-- successes --

View File

@ -19,8 +19,8 @@ import Utils
copyDirRecursiveSpec :: Spec
copyDirRecursiveSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.copyDirRecursive" $ do
-- successes --

View File

@ -19,8 +19,8 @@ import Utils
copyFileOverwriteSpec :: Spec
copyFileOverwriteSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.copyFileOverwrite" $ do
-- successes --

View File

@ -19,8 +19,8 @@ import Utils
copyFileSpec :: Spec
copyFileSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.copyFile" $ do
-- successes --

View File

@ -15,8 +15,8 @@ import GHC.IO.Exception
import Utils
createDirSpec :: Spec
createDirSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.createDir" $ do
-- successes --

View File

@ -15,8 +15,8 @@ import GHC.IO.Exception
import Utils
createRegularFileSpec :: Spec
createRegularFileSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.createRegularFile" $ do
-- successes --

View File

@ -20,8 +20,8 @@ import Utils
deleteDirRecursiveSpec :: Spec
deleteDirRecursiveSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.deleteDirRecursive" $ do
-- successes --

View File

@ -19,8 +19,8 @@ import GHC.IO.Exception
import Utils
deleteDirSpec :: Spec
deleteDirSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.deleteDir" $ do
-- successes --

View File

@ -19,8 +19,8 @@ import GHC.IO.Exception
import Utils
deleteFileSpec :: Spec
deleteFileSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.deleteFile" $ do
-- successes --

View File

@ -29,8 +29,8 @@ import Utils
getDirsFilesSpec :: Spec
getDirsFilesSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.getDirsFiles" $ do
-- successes --

View File

@ -17,8 +17,8 @@ import Utils
getFileTypeSpec :: Spec
getFileTypeSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.getFileType" $ do
-- successes --

View File

@ -16,8 +16,8 @@ import GHC.IO.Exception
import Utils
moveFileOverwriteSpec :: Spec
moveFileOverwriteSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.moveFileOverwrite" $ do
-- successes --

View File

@ -16,8 +16,8 @@ import GHC.IO.Exception
import Utils
moveFileSpec :: Spec
moveFileSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.moveFile" $ do
-- successes --

View File

@ -16,8 +16,8 @@ import GHC.IO.Exception
import Utils
recreateSymlinkSpec :: Spec
recreateSymlinkSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.recreateSymlink" $ do
-- successes --

View File

@ -16,8 +16,8 @@ import GHC.IO.Exception
import Utils
renameFileSpec :: Spec
renameFileSpec =
spec :: Spec
spec =
describe "HSFM.FileSystem.FileOperations.renameFile" $ do
-- successes --

53
test/Main.hs Normal file
View File

@ -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

View File

@ -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 #-}