Commit dbeb9218 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Add more tests.

parent f3b1b808
......@@ -5,8 +5,10 @@ module UnitTests.Distribution.Simple.Utils
import Distribution.Simple.Utils
import Distribution.Verbosity
import System.Directory (getTemporaryDirectory, removeDirectoryRecursive
,removeFile)
import Data.IORef
import System.Directory ( doesDirectoryExist, doesFileExist
, getTemporaryDirectory
, removeDirectoryRecursive, removeFile )
import System.IO (hClose)
import Test.Tasty
......@@ -14,6 +16,15 @@ import Test.Tasty.HUnit
withTempFileTest :: Assertion
withTempFileTest = do
fileName <- newIORef ""
tempDir <- getTemporaryDirectory
withTempFile tempDir ".foo" $ \fileName' _handle -> do
writeIORef fileName fileName'
fileExists <- readIORef fileName >>= doesFileExist
assertBool "Temporary file not deleted by 'withTempFile'!" (not fileExists)
withTempFileRemovedTest :: Assertion
withTempFileRemovedTest = do
tempDir <- getTemporaryDirectory
withTempFile tempDir ".foo" $ \fileName handle -> do
hClose handle
......@@ -21,14 +32,28 @@ withTempFileTest = do
withTempDirTest :: Assertion
withTempDirTest = do
dirName <- newIORef ""
tempDir <- getTemporaryDirectory
withTempDirectory normal tempDir "foo" $ \dirName' -> do
writeIORef dirName dirName'
dirExists <- readIORef dirName >>= doesDirectoryExist
assertBool "Temporary directory not deleted by 'withTempDirectory'!"
(not dirExists)
withTempDirRemovedTest :: Assertion
withTempDirRemovedTest = do
tempDir <- getTemporaryDirectory
withTempDirectory normal tempDir "foo" $ \dirPath -> do
removeDirectoryRecursive dirPath
tests :: [TestTree]
tests =
[ testCase "withTempFile can handle removed files" $
[ testCase "withTempFile works as expected" $
withTempFileTest
, testCase "withTempDirectory can handle removed directories" $
, testCase "withTempFile can handle removed files" $
withTempFileRemovedTest
, testCase "withTempDirectory works as expected" $
withTempDirTest
, testCase "withTempDirectory can handle removed directories" $
withTempDirRemovedTest
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment