@@ -11,9 +11,6 @@ import System.Posix.IO
11
11
import Control.Exception as E
12
12
import Test.Tasty.HUnit
13
13
14
- dir :: FilePath
15
- dir = " dir"
16
-
17
14
emptyDirStream :: IO ()
18
15
emptyDirStream = do
19
16
cleanup
@@ -23,6 +20,11 @@ emptyDirStream = do
23
20
closeDirStream dir_p
24
21
cleanup
25
22
entries @?= []
23
+ where
24
+ dir = " emptyDirStream"
25
+
26
+ cleanup = do
27
+ ignoreIOExceptions $ removeDirectory dir
26
28
27
29
nonEmptyDirStream :: IO ()
28
30
nonEmptyDirStream = do
@@ -34,6 +36,12 @@ nonEmptyDirStream = do
34
36
closeDirStream dir_p
35
37
cleanup
36
38
entries @?= [" file" ]
39
+ where
40
+ dir = " nonEmptyDirStream"
41
+
42
+ cleanup = do
43
+ ignoreIOExceptions $ removeLink $ dir ++ " /file"
44
+ ignoreIOExceptions $ removeDirectory dir
37
45
38
46
dirStreamWithTypes :: IO ()
39
47
dirStreamWithTypes = do
@@ -46,6 +54,13 @@ dirStreamWithTypes = do
46
54
closeDirStream (fromDirStreamWithPath dir_p)
47
55
cleanup
48
56
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
49
64
50
65
readDirStreamEntries :: DirStream -> IO [FilePath ]
51
66
readDirStreamEntries dir_p = do
@@ -65,11 +80,6 @@ readDirStreamEntriesWithTypes dir_p = do
65
80
Just (" .." , _) -> readDirStreamEntriesWithTypes dir_p
66
81
Just ent -> (ent : ) <$> readDirStreamEntriesWithTypes dir_p
67
82
68
- cleanup :: IO ()
69
- cleanup = do
70
- ignoreIOExceptions $ removeLink $ dir ++ " /file"
71
- ignoreIOExceptions $ removeDirectory dir
72
-
73
83
ignoreIOExceptions :: IO () -> IO ()
74
84
ignoreIOExceptions io = io `E.catch`
75
85
((\ _ -> return () ) :: E. IOException -> IO () )
0 commit comments