2017-08-10 22:22:03 +03:00
|
|
|
module Cases.Discard where
|
|
|
|
|
|
|
|
import Control.Concurrent.Classy
|
|
|
|
import Test.DejaFu (gives')
|
|
|
|
import Test.HUnit.DejaFu (Discard(..), defaultMemType, defaultWay, testDejafuDiscard)
|
|
|
|
|
2017-09-20 01:40:38 +03:00
|
|
|
import Common
|
|
|
|
|
2017-08-10 22:22:03 +03:00
|
|
|
tests :: [Test]
|
2017-09-20 01:40:38 +03:00
|
|
|
tests = toTestList
|
|
|
|
[ check "All results are kept when none are discarded" [1, 2, 3] $
|
|
|
|
const Nothing
|
|
|
|
, check "No results are kept when all are discarded" [] $
|
|
|
|
const (Just DiscardResultAndTrace)
|
|
|
|
, check "Results failing the test are not present" [1, 2] $
|
|
|
|
\x -> if x == Right 3 then Just DiscardResultAndTrace else Nothing
|
2017-08-10 22:22:03 +03:00
|
|
|
]
|
|
|
|
where
|
|
|
|
check name xs f = testDejafuDiscard f defaultWay defaultMemType nondet name (gives' xs)
|
|
|
|
|
|
|
|
nondet :: MonadConc m => m Int
|
|
|
|
nondet = do
|
|
|
|
mvar <- newEmptyMVar
|
2017-09-20 01:40:38 +03:00
|
|
|
_ <- fork $ putMVar mvar 1
|
|
|
|
_ <- fork $ putMVar mvar 2
|
|
|
|
_ <- fork $ putMVar mvar 3
|
2017-08-10 22:22:03 +03:00
|
|
|
readMVar mvar
|