A test which I expect to fail (as witnessed by running it in IO) not failing when checked by DejaFu.
Last active
March 23, 2023 15:05
-
-
Save NicolasT/d2f456112221679ecac2680685627027 to your computer and use it in GitHub Desktop.
Non-failing test with DejaFu
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
dist-newstyle/ |
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
cabal-version: 3.0 | |
name: dejafu-test | |
version: 0.0.0.0 | |
license: MIT | |
license-file: LICENSE | |
author: Nicolas Trangez | |
maintainer: ikke@nicolast.be | |
category: Testing | |
build-type: Simple | |
common warnings | |
ghc-options: -Wall | |
test-suite dejafu-test-test | |
import: warnings | |
default-language: Haskell2010 | |
type: exitcode-stdio-1.0 | |
main-is: Main.hs | |
build-depends: | |
, base ^>=4.17.0.0 | |
, concurrency ^>=1.11.0.2 | |
, tasty ^>=1.4.3 | |
, tasty-dejafu ^>=2.1.0.0 | |
, tasty-hunit ^>=0.10.0.3 | |
ghc-options: -threaded -rtsopts -with-rtsopts=-N2 |
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
Copyright (c) 2023 Nicolas Trangez | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to | |
permit persons to whom the Software is furnished to do so, subject to | |
the following conditions: | |
The above copyright notice and this permission notice shall be included | |
in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
{-# LANGUAGE NoMonomorphismRestriction #-} | |
module Main (main) where | |
import Control.Concurrent.Classy.Async (wait, withAsync) | |
import Control.Concurrent.Classy.MVar (newEmptyMVar, putMVar, readMVar) | |
import Control.Concurrent.Classy.STM (readTVarConc, writeTVar) | |
import Control.Monad (forM_) | |
import Control.Monad.Conc.Class (MonadConc, atomically, newTVarConc) | |
import Test.Tasty (defaultMain, testGroup) | |
import Test.Tasty.DejaFu (testAuto) | |
import Test.Tasty.HUnit (testCase, (@?=)) | |
main :: IO () | |
main = | |
defaultMain $ | |
testGroup | |
"dejafu-test" | |
[ let act = runComputation (pure ()) pure pure | |
in testGroup | |
"Without MVar" | |
[ testCase "IO" $ forM_ [0 :: Int .. 1000] $ \_ -> do | |
v1 <- act | |
v2 <- act | |
v1 @?= v2, | |
testAuto "DejaFu" act | |
], | |
let act = runComputation newEmptyMVar (`putMVar` ()) readMVar | |
in testGroup | |
"With MVar" | |
[ testCase "IO" $ forM_ [0 :: Int .. 1000] $ \_ -> do | |
v1 <- act | |
v2 <- act | |
v1 @?= v2, | |
testAuto "DejaFu" act | |
] | |
] | |
runComputation :: (MonadConc m) => m a -> (a -> m ()) -> (a -> m ()) -> m Int | |
runComputation mkLock unLock waitLock = do | |
v <- newTVarConc 0 | |
l <- mkLock | |
let act n = do | |
waitLock l | |
atomically $ writeTVar v n | |
withAsync (act 1) $ \a -> | |
withAsync (act 2) $ \b -> do | |
unLock l | |
wait a | |
wait b | |
readTVarConc v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment