1 module UnitTests
.Distribution
.Compat
.Time
(tests
) where
3 import Control
.Concurrent
(threadDelay
)
6 import Distribution
.Simple
.Utils
(withTempDirectory
)
7 import Distribution
.Verbosity
9 import Distribution
.Compat
.Time
12 import Test
.Tasty
.HUnit
14 tests
:: Int -> [TestTree
]
16 [ testCase
"getModTime has sub-second resolution" $ getModTimeTest mtimeChange
17 , testCase
"getCurTime works as expected" $ getCurTimeTest mtimeChange
20 getModTimeTest
:: Int -> Assertion
21 getModTimeTest mtimeChange
=
22 withTempDirectory silent
"." "getmodtime-" $ \dir
-> do
23 let fileName
= dir
</> "foo"
24 writeFile fileName
"bar"
25 t0
<- getModTime fileName
26 threadDelay mtimeChange
27 writeFile fileName
"baz"
28 t1
<- getModTime fileName
29 assertBool
"expected different file mtimes" (t1
> t0
)
32 getCurTimeTest
:: Int -> Assertion
33 getCurTimeTest mtimeChange
=
34 withTempDirectory silent
"." "getmodtime-" $ \dir
-> do
35 let fileName
= dir
</> "foo"
36 writeFile fileName
"bar"
37 t0
<- getModTime fileName
38 threadDelay mtimeChange
40 assertBool
("expected file mtime (" ++ show t0
41 ++ ") to be earlier than current time (" ++ show t1
++ ")")
44 threadDelay mtimeChange
45 writeFile fileName
"baz"
46 t2
<- getModTime fileName
47 assertBool
("expected current time (" ++ show t1
48 ++ ") to be earlier than file mtime (" ++ show t2
++ ")")