-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
module Main where | ||
|
||
import qualified Test.Control.Concurrent.Class.MonadMVar.Strict.Checked as Test.StrictMVar.Checked | ||
import qualified Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WHNF as Test.StrictTVar.Checked | ||
import qualified Test.Control.Concurrent.Class.MonadMVar.Strict.Checked | ||
import qualified Test.Control.Concurrent.Class.MonadMVar.Strict.Checked.WHNF | ||
import qualified Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked | ||
import qualified Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WHNF | ||
import Test.Tasty (defaultMain, testGroup) | ||
|
||
main :: IO () | ||
main = defaultMain $ testGroup "strict-checked-vars" [ | ||
Test.StrictMVar.Checked.tests | ||
, Test.StrictTVar.Checked.tests | ||
Test.Control.Concurrent.Class.MonadMVar.Strict.Checked.tests | ||
, Test.Control.Concurrent.Class.MonadMVar.Strict.Checked.WHNF.tests | ||
, Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.tests | ||
, Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked.WHNF.tests | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
strict-checked-vars/test/Test/Control/Concurrent/Class/MonadSTM/Strict/TVar/Checked.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
|
||
module Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked where | ||
|
||
import Control.Concurrent.Class.MonadSTM (MonadSTM, atomically) | ||
import Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked | ||
import Test.QuickCheck.Monadic | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import Test.Utils | ||
|
||
tests :: TestTree | ||
tests = testGroup "Test.Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked" [ | ||
testGroup "Checked" [ | ||
testGroup "IO" [ | ||
testProperty "prop_invariantShouldFail" $ | ||
once $ shouldFail $ monadicIO prop_invariantShouldFail | ||
, testProperty "prop_invariantShouldNotFail" $ | ||
once $ monadicIO prop_invariantShouldNotFail | ||
] | ||
, testGroup "IOSim" [ | ||
testProperty "prop_invariantShouldFail" $ | ||
once $ shouldFail $ monadicSim prop_invariantShouldFail | ||
, testProperty "prop_invariantShouldNotFail" $ | ||
once $ monadicSim prop_invariantShouldNotFail | ||
] | ||
] | ||
] | ||
|
||
-- | Invariant that checks whether an @Int@ is positive. | ||
invPositiveInt :: Int -> Maybe String | ||
invPositiveInt x | ||
| x >= 0 = Nothing | ||
| otherwise = Just $ "x<0 for x=" <> show x | ||
|
||
prop_invariantShouldNotFail :: MonadSTM m => PropertyM m () | ||
prop_invariantShouldNotFail = run $ atomically $ do | ||
v <- newTVarWithInvariant invPositiveInt 0 | ||
modifyTVar v (+ 1) | ||
|
||
prop_invariantShouldFail :: MonadSTM m => PropertyM m () | ||
prop_invariantShouldFail = run $ atomically $ do | ||
v <- newTVarWithInvariant invPositiveInt 0 | ||
modifyTVar v (subtract 1) | ||
|
||
shouldFail :: Property -> Property | ||
#if CHECK_TVAR_INVARIANTS | ||
shouldFail = expectFailure | ||
#else | ||
shouldFail = id | ||
#endif |