/
test004-modify-file.hs
55 lines (44 loc) · 1.07 KB
/
test004-modify-file.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module Main where
import Control.Exception
import Control.Monad
import System.Directory
import System.IO
import System.INotify as INotify
import Utils
file :: String
file = "hello"
write :: String -> IO ()
write path = do
writeFile (path ++ '/':file) ""
modify :: String -> IO ()
modify path = do
bracket
(openFile (path ++ '/':file) AppendMode)
(hClose)
(\h -> hPutStr h "yarr!")
remove :: String -> IO ()
remove path = do
removeFile (path ++ '/':file)
action :: String -> IO ()
action path = do
write path
modify path
remove path
main :: IO ()
main =
inTestEnviron [AllEvents] action $ \ events -> do
when (expected ~= events)
testSuccess
putStrLn $ explainFailure expected events
testFailure
expected :: [Event]
expected =
[ Created False file
, Opened False (Just file)
, Modified False (Just file)
, Closed False (Just file) True
, Opened False (Just file)
, Modified False (Just file)
, Closed False (Just file) True
, Deleted False file
]