mirror of
https://github.com/barrucadu/dejafu.git
synced 2025-01-04 11:46:08 +03:00
Add test for DiscardTrace
This commit is contained in:
parent
c2a178bd86
commit
7f5680bcd1
@ -58,6 +58,7 @@ library
|
|||||||
, tasty-expected-failure
|
, tasty-expected-failure
|
||||||
, tasty-dejafu
|
, tasty-dejafu
|
||||||
, tasty-hedgehog
|
, tasty-hedgehog
|
||||||
|
, tasty-hunit
|
||||||
, vector
|
, vector
|
||||||
if impl(ghc < 8.0.1)
|
if impl(ghc < 8.0.1)
|
||||||
build-depends: transformers
|
build-depends: transformers
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
module Integration.Discard where
|
module Integration.Discard where
|
||||||
|
|
||||||
import Control.Concurrent.Classy hiding (check)
|
import Control.Concurrent.Classy hiding (check)
|
||||||
|
import Data.Foldable (for_)
|
||||||
import Test.DejaFu (gives')
|
import Test.DejaFu (gives')
|
||||||
|
import Test.DejaFu.Conc (ConcIO)
|
||||||
|
import Test.DejaFu.SCT
|
||||||
|
import Test.DejaFu.Types (Failure)
|
||||||
|
import Test.Tasty.HUnit
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
|
|
||||||
@ -13,11 +18,26 @@ tests = toTestList
|
|||||||
const (Just DiscardResultAndTrace)
|
const (Just DiscardResultAndTrace)
|
||||||
, check "Results failing the test are not present" [1, 2] $
|
, check "Results failing the test are not present" [1, 2] $
|
||||||
\x -> if x == Right 3 then Just DiscardResultAndTrace else Nothing
|
\x -> if x == Right 3 then Just DiscardResultAndTrace else Nothing
|
||||||
|
, testCase "No traces kept when they get discared" $ testDiscardTrace discarder testAction
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
check name xs f = testDejafuDiscard f defaultWay defaultMemType name (gives' xs) $ do
|
check name xs f = testDejafuDiscard f defaultWay defaultMemType name (gives' xs) testAction
|
||||||
|
testAction = do
|
||||||
mvar <- newEmptyMVarInt
|
mvar <- newEmptyMVarInt
|
||||||
_ <- fork $ putMVar mvar 1
|
_ <- fork $ putMVar mvar 1
|
||||||
_ <- fork $ putMVar mvar 2
|
_ <- fork $ putMVar mvar 2
|
||||||
_ <- fork $ putMVar mvar 3
|
_ <- fork $ putMVar mvar 3
|
||||||
readMVar mvar
|
readMVar mvar
|
||||||
|
discarder (Right 2) = Just DiscardTrace
|
||||||
|
discarder (Right 3) = Just DiscardResultAndTrace
|
||||||
|
discarder _ = Nothing
|
||||||
|
|
||||||
|
testDiscardTrace :: (Either Failure a -> Maybe Discard) -> ConcIO a -> Assertion
|
||||||
|
testDiscardTrace discarder action = do
|
||||||
|
results <- runSCTDiscard discarder defaultWay defaultMemType action
|
||||||
|
for_ results $ \(efa, trace) -> case discarder efa of
|
||||||
|
Just DiscardResultAndTrace -> assertFailure "expected result to be discarded"
|
||||||
|
Just DiscardTrace
|
||||||
|
| null trace -> pure ()
|
||||||
|
| otherwise -> assertFailure "expected trace to be discarded"
|
||||||
|
Nothing -> pure ()
|
||||||
|
Loading…
Reference in New Issue
Block a user