Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdral committed Aug 7, 2023
1 parent 49b7d75 commit 03706a8
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE BangPatterns #-}

module Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WHNF where

Expand Down Expand Up @@ -37,11 +38,11 @@ tests = testGroup "Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WH
where
testIO name inv = testGroup name [
testProperty "prop_newTVarWithInvariant" $
monadicIO .: prop_newTVarWithInvariant inv
monadicIO .: runWithCounterexample .: prop_newTVarWithInvariant inv
, testProperty "prop_newTVarWithInvariantIO" $
monadicIO .: prop_newTVarWithInvariantIO inv
, testProperty "prop_writeTVar" $
monadicIO .: prop_writeTVar inv
monadicIO .: runWithCounterexample .: prop_writeTVar inv
, testProperty "prop_modifyTVar" $
monadicIO .: prop_modifyTVar inv
, testProperty "prop_stateTVar" $
Expand All @@ -52,11 +53,11 @@ tests = testGroup "Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WH

testIOSim name inv = testGroup name [
testProperty "prop_newTVarWithInvariant" $ \x f ->
monadicSim $ prop_newTVarWithInvariant inv x f
monadicSim $ runWithCounterexample $ prop_newTVarWithInvariant inv x f
, testProperty "prop_newTVarWithInvariantIO" $ \x f ->
monadicSim $ prop_newTVarWithInvariantIO inv x f
, testProperty "prop_writeTVar" $ \x f ->
monadicSim $ prop_writeTVar inv x f
monadicSim $ runWithCounterexample $ prop_writeTVar inv x f
, testProperty "prop_modifyTVar" $ \x f ->
monadicSim $ prop_modifyTVar inv x f
, testProperty "prop_stateTVar" $ \x f ->
Expand All @@ -82,6 +83,15 @@ isInWHNF v = do
Just tinfo -> monitor (counterexample $ "Not in WHNF: " ++ show tinfo)
>> pure False

isInWHNF' :: (MonadSTM m, Typeable a) => StrictTVar m a -> m (Maybe String)
isInWHNF' v = fmap show . unsafeNoThunks . OnlyCheckWhnf <$> readTVarIO v

runWithCounterexample :: Monad m => m (Maybe String) -> PropertyM m Bool
runWithCounterexample a = run a >>= \case
Nothing -> pure True
Just tinfo -> monitor (counterexample $ "Not in WHNF: " ++ show tinfo)
>> pure False

-- | Invariants
--
-- Testing with @'Invariant' (const Nothing)'@ is the same as testing with
Expand Down Expand Up @@ -131,10 +141,10 @@ prop_newTVarWithInvariant ::
=> Invariant Int
-> Int
-> Fun Int Int
-> PropertyM m Bool
-> m (Maybe String)
prop_newTVarWithInvariant inv x f = do
v <- run $ atomically $ newTVarWithInvariant inv (applyFun f x)
isInWHNF v
v <- atomically $ newTVarWithInvariant inv (applyFun f x)
isInWHNF' v

-- | Test 'newTVarWithInvariantIO', not to be confused with
-- 'Checked.newTVarWithInvariantIO'.
Expand All @@ -153,11 +163,11 @@ prop_writeTVar ::
=> Invariant Int
-> Int
-> Fun Int Int
-> PropertyM m Bool
-> m (Maybe String)
prop_writeTVar inv x f = do
v <- run $ newTVarWithInvariantIO inv x
run $ atomically $ writeTVar v (applyFun f x)
isInWHNF v
!v <- newTVarWithInvariantIO inv x
() <- atomically $ writeTVar v (applyFun f x)
isInWHNF' v

prop_modifyTVar ::
MonadSTM m
Expand Down

0 comments on commit 03706a8

Please sign in to comment.