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 ...@@ -5,8 +5,10 @@ module UnitTests.Distribution.Simple.Utils
import Distribution.Simple.Utils import Distribution.Simple.Utils
import Distribution.Verbosity import Distribution.Verbosity
import System.Directory (getTemporaryDirectory, removeDirectoryRecursive import Data.IORef
,removeFile) import System.Directory ( doesDirectoryExist, doesFileExist
, getTemporaryDirectory
, removeDirectoryRecursive, removeFile )
import System.IO (hClose) import System.IO (hClose)
import Test.Tasty import Test.Tasty
...@@ -14,6 +16,15 @@ import Test.Tasty.HUnit ...@@ -14,6 +16,15 @@ import Test.Tasty.HUnit
withTempFileTest :: Assertion withTempFileTest :: Assertion
withTempFileTest = do 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 tempDir <- getTemporaryDirectory
withTempFile tempDir ".foo" $ \fileName handle -> do withTempFile tempDir ".foo" $ \fileName handle -> do
hClose handle hClose handle
...@@ -21,14 +32,28 @@ withTempFileTest = do ...@@ -21,14 +32,28 @@ withTempFileTest = do
withTempDirTest :: Assertion withTempDirTest :: Assertion
withTempDirTest = do 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 tempDir <- getTemporaryDirectory
withTempDirectory normal tempDir "foo" $ \dirPath -> do withTempDirectory normal tempDir "foo" $ \dirPath -> do
removeDirectoryRecursive dirPath removeDirectoryRecursive dirPath
tests :: [TestTree] tests :: [TestTree]
tests = tests =
[ testCase "withTempFile can handle removed files" $ [ testCase "withTempFile works as expected" $
withTempFileTest withTempFileTest
, testCase "withTempDirectory can handle removed directories" $ , testCase "withTempFile can handle removed files" $
withTempFileRemovedTest
, testCase "withTempDirectory works as expected" $
withTempDirTest 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