TESTS: less side effects plz

This commit is contained in:
2016-06-05 14:33:53 +02:00
parent 5d1c5cc2ce
commit bc348c7dd5
21 changed files with 262 additions and 54 deletions

View File

@@ -17,6 +17,11 @@ import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CanonicalizePathSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "file"
@@ -35,7 +40,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.canonicalizePath" $ do
-- successes --

View File

@@ -26,8 +26,16 @@ import System.Posix.Env.ByteString
import Utils
import qualified Data.ByteString as BS
import Data.ByteString.UTF8 (toString)
import Data.IORef
(
readIORef
)
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CopyDirRecursiveCollectFailuresSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
@@ -115,18 +123,19 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.copyDirRecursive" $ do
-- successes --
it "copyDirRecursive (Strict, CollectFailures), all fine and compare" $ do
tmpDir' <- getRawTmpDir
copyDirRecursive' "inputDir"
"outputDir"
Strict
CollectFailures
(system $ "diff -r --no-dereference "
++ toString tmpDir ++ "inputDir" ++ " "
++ toString tmpDir ++ "outputDir")
++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir")
`shouldReturn` ExitSuccess
removeDirIfExists "outputDir"
@@ -161,9 +170,8 @@ spec = before_ setupFiles $ after_ cleanupFiles $
normalDirPerms "outputDir1/foo2/foo4"
normalDirPerms "outputDir1/foo2/foo4/inputFile4"
c <- allDirectoryContents' "outputDir1"
pwd <- fromJust <$> getEnv "PWD"
let shouldC = (fmap (\x -> pwd `BS.append` "/" `BS.append`
tmpDir `BS.append` x)
tmpDir' <- getRawTmpDir
let shouldC = (fmap (\x -> tmpDir' `BS.append` x)
["outputDir1"
,"outputDir1/foo2"
,"outputDir1/foo2/inputFile1"

View File

@@ -19,8 +19,17 @@ import System.Exit
import System.Process
import Utils
import Data.ByteString.UTF8 (toString)
import Data.IORef
(
readIORef
)
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CopyDirRecursiveOverwriteSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
@@ -81,7 +90,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.copyDirRecursive" $ do
-- successes --
@@ -93,28 +102,30 @@ spec = before_ setupFiles $ after_ cleanupFiles $
removeDirIfExists "outputDir"
it "copyDirRecursive (Overwrite, FailEarly), all fine and compare" $ do
tmpDir' <- getRawTmpDir
copyDirRecursive' "inputDir"
"outputDir"
Overwrite
FailEarly
(system $ "diff -r --no-dereference "
++ toString tmpDir ++ "inputDir" ++ " "
++ toString tmpDir ++ "outputDir")
++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir")
`shouldReturn` ExitSuccess
removeDirIfExists "outputDir"
it "copyDirRecursive (Overwrite, FailEarly), destination dir already exists" $ do
tmpDir' <- getRawTmpDir
(system $ "diff -r --no-dereference "
++ toString tmpDir ++ "inputDir" ++ " "
++ toString tmpDir ++ "alreadyExistsD")
++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "alreadyExistsD")
`shouldReturn` (ExitFailure 1)
copyDirRecursive' "inputDir"
"alreadyExistsD"
Overwrite
FailEarly
(system $ "diff -r --no-dereference "
++ toString tmpDir ++ "inputDir" ++ " "
++ toString tmpDir ++ "alreadyExistsD")
++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "alreadyExistsD")
`shouldReturn` ExitSuccess
removeDirIfExists "outputDir"

View File

@@ -19,9 +19,18 @@ import System.Exit
import System.Process
import Utils
import Data.ByteString.UTF8 (toString)
import Data.IORef
(
readIORef
)
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CopyDirRecursiveSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "alreadyExists"
@@ -67,7 +76,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.copyDirRecursive" $ do
-- successes --
@@ -79,13 +88,14 @@ spec = before_ setupFiles $ after_ cleanupFiles $
removeDirIfExists "outputDir"
it "copyDirRecursive (Strict, FailEarly), all fine and compare" $ do
tmpDir' <- getRawTmpDir
copyDirRecursive' "inputDir"
"outputDir"
Strict
FailEarly
(system $ "diff -r --no-dereference "
++ toString tmpDir ++ "inputDir" ++ " "
++ toString tmpDir ++ "outputDir")
++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir")
`shouldReturn` ExitSuccess
removeDirIfExists "outputDir"

View File

@@ -18,6 +18,16 @@ import System.Exit
import System.Process
import Utils
import Data.ByteString.UTF8 (toString)
import Data.IORef
(
readIORef
)
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CopyFileOverwriteSpec"
createTmpDir
setupFiles :: IO ()
@@ -51,7 +61,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.copyFile" $ do
-- successes --
@@ -62,21 +72,23 @@ spec = before_ setupFiles $ after_ cleanupFiles $
removeFileIfExists "outputFile"
it "copyFile (Overwrite), output file already exists, all clear" $ do
tmpDir' <- getRawTmpDir
copyFile' "alreadyExists" "alreadyExists.bak" Strict
copyFile' "inputFile" "alreadyExists" Overwrite
(system $ "cmp -s " ++ toString tmpDir ++ "inputFile" ++ " "
++ toString tmpDir ++ "alreadyExists")
(system $ "cmp -s " ++ toString tmpDir' ++ "inputFile" ++ " "
++ toString tmpDir' ++ "alreadyExists")
`shouldReturn` ExitSuccess
removeFileIfExists "alreadyExists"
copyFile' "alreadyExists.bak" "alreadyExists" Strict
removeFileIfExists "alreadyExists.bak"
it "copyFile (Overwrite), and compare" $ do
tmpDir' <- getRawTmpDir
copyFile' "inputFile"
"outputFile"
Overwrite
(system $ "cmp -s " ++ toString tmpDir ++ "inputFile" ++ " "
++ toString tmpDir ++ "outputFile")
(system $ "cmp -s " ++ toString tmpDir' ++ "inputFile" ++ " "
++ toString tmpDir' ++ "outputFile")
`shouldReturn` ExitSuccess
removeFileIfExists "outputFile"

View File

@@ -19,8 +19,17 @@ import System.Exit
import System.Process
import Utils
import Data.ByteString.UTF8 (toString)
import Data.IORef
(
readIORef
)
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CopyFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "inputFile"
@@ -51,7 +60,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.copyFile" $ do
-- successes --
@@ -62,11 +71,12 @@ spec = before_ setupFiles $ after_ cleanupFiles $
removeFileIfExists "outputFile"
it "copyFile (Strict), and compare" $ do
tmpDir' <- getRawTmpDir
copyFile' "inputFile"
"outputFile"
Strict
(system $ "cmp -s " ++ toString tmpDir ++ "inputFile" ++ " "
++ toString tmpDir ++ "outputFile")
(system $ "cmp -s " ++ toString tmpDir' ++ "inputFile" ++ " "
++ toString tmpDir' ++ "outputFile")
`shouldReturn` ExitSuccess
removeFileIfExists "outputFile"

View File

@@ -15,6 +15,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CreateDirSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createDir' "alreadyExists"
@@ -35,7 +41,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.createDir" $ do
-- successes --

View File

@@ -15,6 +15,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CreateRegularFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "alreadyExists"
@@ -23,8 +29,6 @@ setupFiles = do
noPerms "noPerms"
noWritableDirPerms "noWritePerms"
cleanupFiles :: IO ()
cleanupFiles = do
normalDirPerms "noPerms"
@@ -35,7 +39,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.createRegularFile" $ do
-- successes --

View File

@@ -15,6 +15,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CreateSymlinkSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "alreadyExists"
@@ -34,7 +40,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.createSymlink" $ do
-- successes --

View File

@@ -19,6 +19,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "DeleteDirRecursiveSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "file"
@@ -44,7 +51,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.deleteDirRecursive" $ do
-- successes --

View File

@@ -19,6 +19,14 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "DeleteDirSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "file"
@@ -44,7 +52,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.deleteDir" $ do
-- successes --

View File

@@ -20,6 +20,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "DeleteFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "foo"
@@ -40,7 +46,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.deleteFile" $ do
-- successes --

View File

@@ -21,6 +21,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "GetDirsFilesSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "file"
@@ -47,7 +53,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.getDirsFiles" $ do
-- successes --

View File

@@ -16,6 +16,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "GetFileTypeSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "regularfile"
@@ -40,7 +47,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.getFileType" $ do
-- successes --

View File

@@ -17,6 +17,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "MoveFileOverwriteSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "myFile"
@@ -44,7 +51,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.moveFile" $ do
-- successes --

View File

@@ -17,6 +17,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "MoveFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "myFile"
@@ -46,7 +53,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.moveFile" $ do
-- successes --

View File

@@ -20,6 +20,12 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "RecreateSymlinkOverwriteSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "myFile"
@@ -52,7 +58,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.recreateSymlink" $ do
-- successes --

View File

@@ -19,6 +19,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "RecreateSymlinkSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "myFile"
@@ -47,7 +54,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.recreateSymlink" $ do
-- successes --

View File

@@ -16,6 +16,13 @@ import GHC.IO.Exception
import Utils
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "RenameFileSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "myFile"
@@ -44,7 +51,7 @@ cleanupFiles = do
spec :: Spec
spec = before_ setupFiles $ after_ cleanupFiles $
spec = beforeAll_ upTmpDir $ before_ setupFiles $ after_ cleanupFiles $
describe "HPath.IO.renameFile" $ do
-- successes --