1 {-# LANGUAGE StandaloneDeriving #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module UnitTests
.Distribution
.Solver
.Modular
.RetryLog
8 import Distribution
.Solver
.Modular
.Message
9 import Distribution
.Solver
.Modular
.RetryLog
10 import Distribution
.Solver
.Types
.Progress
12 import Test
.Tasty
(TestTree
)
13 import Test
.Tasty
.HUnit
(testCase
, (@?
=))
14 import Test
.Tasty
.QuickCheck
23 type Log a
= Progress a
String String
27 [ testProperty
"'toProgress . fromProgress' is identity" $ \p
->
28 toProgress
(fromProgress p
) === (p
:: Log
Int)
29 , testProperty
"'mapFailure f' is like 'foldProgress Step (Fail . f) Done'" $
30 let mapFailureProgress f
= foldProgress Step
(Fail
. f
) Done
32 toProgress
(mapFailure f
(fromProgress p
))
33 === mapFailureProgress
(f
:: String -> Int) (p
:: Log
Int)
34 , testProperty
"'retry p f' is like 'foldProgress Step f Done p'" $
36 toProgress
(retry
(fromProgress p
) (fromProgress
. f
))
37 === (foldProgress Step f Done
(p
:: Log
Int) :: Log
Int)
38 , testProperty
"failWith" $ \step failure
->
39 toProgress
(failWith step failure
)
40 === (Step step
(Fail failure
) :: Log
Int)
41 , testProperty
"succeedWith" $ \step success
->
42 toProgress
(succeedWith step success
)
43 === (Step step
(Done success
) :: Log
Int)
44 , testProperty
"continueWith" $ \step p
->
45 toProgress
(continueWith step
(fromProgress p
))
46 === (Step step p
:: Log
Int)
47 , testCase
"tryWith with failure" $
48 let failure
= Fail
"Error"
50 in toProgress
(tryWith Success
$ fromProgress
(s
(s failure
)))
51 @?
= (s
(Step Enter
(s
(s
(Step Leave failure
)))) :: Log Message
)
52 , testCase
"tryWith with success" $
53 let done
= Done
"Done"
55 in toProgress
(tryWith Success
$ fromProgress
(s
(s done
)))
56 @?
= (s
(Step Enter
(s
(s done
))) :: Log Message
)
60 (Arbitrary step
, Arbitrary
fail, Arbitrary done
)
61 => Arbitrary
(Progress step
fail done
)
64 steps
<- listOf arbitrary
65 end
<- oneof
[Fail `
fmap` arbitrary
, Done `
fmap` arbitrary
]
66 return $ foldr Step end steps
68 deriving instance (Eq step
, Eq
fail, Eq done
) => Eq
(Progress step
fail done
)
71 (Show step
, Show fail, Show done
)
72 => Show (Progress step
fail done
)
74 deriving instance Eq Message
75 deriving instance Show Message