Skip to content

Commit 66f6c58

Browse files
mmhathasufell
authored andcommitted
Fixed tests for ReadDirStream
1 parent b2793e1 commit 66f6c58

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/ReadDirStream.hs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import System.Posix.IO
1111
import Control.Exception as E
1212
import Test.Tasty.HUnit
1313

14-
dir :: FilePath
15-
dir = "dir"
16-
1714
emptyDirStream :: IO ()
1815
emptyDirStream = do
1916
cleanup
@@ -23,6 +20,11 @@ emptyDirStream = do
2320
closeDirStream dir_p
2421
cleanup
2522
entries @?= []
23+
where
24+
dir = "emptyDirStream"
25+
26+
cleanup = do
27+
ignoreIOExceptions $ removeDirectory dir
2628

2729
nonEmptyDirStream :: IO ()
2830
nonEmptyDirStream = do
@@ -34,6 +36,12 @@ nonEmptyDirStream = do
3436
closeDirStream dir_p
3537
cleanup
3638
entries @?= ["file"]
39+
where
40+
dir = "nonEmptyDirStream"
41+
42+
cleanup = do
43+
ignoreIOExceptions $ removeLink $ dir ++ "/file"
44+
ignoreIOExceptions $ removeDirectory dir
3745

3846
dirStreamWithTypes :: IO ()
3947
dirStreamWithTypes = do
@@ -46,6 +54,13 @@ dirStreamWithTypes = do
4654
closeDirStream (fromDirStreamWithPath dir_p)
4755
cleanup
4856
Data.List.sort entries @?= [("somedir", DirectoryType), ("somefile", RegularFileType)]
57+
where
58+
dir = "dirStreamWithTypes"
59+
60+
cleanup = do
61+
ignoreIOExceptions $ removeDirectory $ dir ++ "/somedir"
62+
ignoreIOExceptions $ removeLink $ dir ++ "/somefile"
63+
ignoreIOExceptions $ removeDirectory dir
4964

5065
readDirStreamEntries :: DirStream -> IO [FilePath]
5166
readDirStreamEntries dir_p = do
@@ -65,11 +80,6 @@ readDirStreamEntriesWithTypes dir_p = do
6580
Just ("..", _) -> readDirStreamEntriesWithTypes dir_p
6681
Just ent -> (ent :) <$> readDirStreamEntriesWithTypes dir_p
6782

68-
cleanup :: IO ()
69-
cleanup = do
70-
ignoreIOExceptions $ removeLink $ dir ++ "/file"
71-
ignoreIOExceptions $ removeDirectory dir
72-
7383
ignoreIOExceptions :: IO () -> IO ()
7484
ignoreIOExceptions io = io `E.catch`
7585
((\_ -> return ()) :: E.IOException -> IO ())

0 commit comments

Comments
 (0)