packages feed

hunit-dejafu 0.3.0.1 → 0.3.0.2

raw patch · 2 files changed

+58/−33 lines, 2 filesdep ~dejafuPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: dejafu

API changes (from Hackage documentation)

- Test.HUnit.DejaFu: instance Test.HUnit.Base.Assertable (Test.DejaFu.Deterministic.ConcIO ())
- Test.HUnit.DejaFu: instance Test.HUnit.Base.Assertable (Test.DejaFu.Deterministic.ConcST t ())
- Test.HUnit.DejaFu: instance Test.HUnit.Base.Testable (Test.DejaFu.Deterministic.ConcIO ())
- Test.HUnit.DejaFu: instance Test.HUnit.Base.Testable (Test.DejaFu.Deterministic.ConcST t ())
+ Test.HUnit.DejaFu: instance Test.HUnit.Base.Assertable (Test.DejaFu.Conc.ConcIO ())
+ Test.HUnit.DejaFu: instance Test.HUnit.Base.Assertable (Test.DejaFu.Conc.ConcST t ())
+ Test.HUnit.DejaFu: instance Test.HUnit.Base.Testable (Test.DejaFu.Conc.ConcIO ())
+ Test.HUnit.DejaFu: instance Test.HUnit.Base.Testable (Test.DejaFu.Conc.ConcST t ())

Files

Test/HUnit/DejaFu.hs view
@@ -10,8 +10,16 @@ {-# LANGUAGE ImpredicativeTypes #-} #endif --- | This module allows using Deja Fu predicates with HUnit to test--- the behaviour of concurrent systems.+-- |+-- Module      : Test.HUnit.DejaFu+-- Copyright   : (c) 2016 Michael Walker+-- License     : MIT+-- Maintainer  : Michael Walker <mike@barrucadu.co.uk>+-- Stability   : stable+-- Portability : CPP, FlexibleInstances, ImpredicativeTypes, RankNTypes, ScopedTypeVariables, TypeSynonymInstances+--+-- This module allows using Deja Fu predicates with HUnit to test the+-- behaviour of concurrent systems. module Test.HUnit.DejaFu   ( -- * Unit testing @@ -51,45 +59,62 @@   ) where  import Control.Monad.Catch (try)+import Control.Monad.ST (runST) import Data.List (intercalate, intersperse) import Test.DejaFu-import Test.DejaFu.Deterministic (ConcST, ConcIO, Trace, ThreadId, ThreadAction, Lookahead, showFail, showTrace)-import Test.DejaFu.SCT (sctBound, sctBoundIO)+import qualified Test.DejaFu.SCT as SCT import Test.HUnit (Assertable(..), Test(..), Testable(..), assertString) import Test.HUnit.Lang (HUnitFailure(..)) --- Can't put the necessary forall in the @Assertable ConcST t@+#if MIN_VERSION_dejafu(0,4,0)+import qualified Test.DejaFu.Conc as Conc+#else+import qualified Test.DejaFu.Deterministic as Conc+#endif++-- Can't put the necessary forall in the @Assertable Conc.ConcST t@ -- instance :( import Unsafe.Coerce (unsafeCoerce)  #if MIN_VERSION_dejafu(0,3,0)-type Trc = Trace ThreadId ThreadAction Lookahead+type Trc = Conc.Trace Conc.ThreadId Conc.ThreadAction Conc.Lookahead #else-type Trc = Trace+type Trc = Conc.Trace #endif +sctBoundST :: MemType -> Bounds -> (forall t. Conc.ConcST t a) -> [(Either Failure a, Trc)]+sctBoundIO :: MemType -> Bounds -> Conc.ConcIO a -> IO [(Either Failure a, Trc)]++#if MIN_VERSION_dejafu(0,4,0)+sctBoundST memtype cb conc = runST (SCT.sctBound memtype cb conc)+sctBoundIO = SCT.sctBound+#else+sctBoundST = SCT.sctBound+sctBoundIO = SCT.sctBoundIO+#endif+ -------------------------------------------------------------------------------- -- Unit testing -instance Testable (ConcST t ()) where+instance Testable (Conc.ConcST t ()) where   test conc = TestCase (assert conc) -instance Testable (ConcIO ()) where+instance Testable (Conc.ConcIO ()) where   test conc = TestCase (assert conc) -instance Assertable (ConcST t ()) where+instance Assertable (Conc.ConcST t ()) where   assert conc = do     let traces = sctBound' conc'     assertString . showErr $ assertableP traces      where-      conc' :: ConcST t (Either HUnitFailure ())+      conc' :: Conc.ConcST t (Either HUnitFailure ())       conc' = try conc -      sctBound' :: ConcST t (Either HUnitFailure ()) -> [(Either Failure (Either HUnitFailure ()), Trc)]-      sctBound' = unsafeCoerce $ sctBound defaultMemType defaultBounds+      sctBound' :: Conc.ConcST t (Either HUnitFailure ()) -> [(Either Failure (Either HUnitFailure ()), Trc)]+      sctBound' = unsafeCoerce $ sctBoundST defaultMemType defaultBounds -instance Assertable (ConcIO ()) where+instance Assertable (Conc.ConcIO ()) where   assert conc = do     traces <- sctBoundIO defaultMemType defaultBounds (try conc)     assertString . showErr $ assertableP traces@@ -104,12 +129,12 @@  -- | Automatically test a computation. In particular, look for -- deadlocks, uncaught exceptions, and multiple return values.--- +-- -- This uses the 'Conc' monad for testing, which is an instance of -- 'MonadConc'. If you need to test something which also uses -- 'MonadIO', use 'testAutoIO'. testAuto :: (Eq a, Show a)-  => (forall t. ConcST t a)+  => (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> Test testAuto = testAuto' defaultMemType@@ -119,17 +144,17 @@ testAuto' :: (Eq a, Show a)   => MemType   -- ^ The memory model to use for non-synchronised @CRef@ operations.-  -> (forall t. ConcST t a)+  -> (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> Test testAuto' memtype conc = testDejafus' memtype defaultBounds conc autocheckCases  -- | Variant of 'testAuto' for computations which do 'IO'.-testAutoIO :: (Eq a, Show a) => ConcIO a -> Test+testAutoIO :: (Eq a, Show a) => Conc.ConcIO a -> Test testAutoIO = testAutoIO' defaultMemType  -- | Variant of 'testAuto'' for computations which do 'IO'.-testAutoIO' :: (Eq a, Show a) => MemType -> ConcIO a -> Test+testAutoIO' :: (Eq a, Show a) => MemType -> Conc.ConcIO a -> Test testAutoIO' memtype concio = testDejafusIO' memtype defaultBounds concio autocheckCases  -- | Predicates for the various autocheck functions.@@ -142,7 +167,7 @@  -- | Check that a predicate holds. testDejafu :: Show a-  => (forall t. ConcST t a)+  => (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> String   -- ^ The name of the test.@@ -158,7 +183,7 @@   -- ^ The memory model to use for non-synchronised @CRef@ operations.   -> Bounds   -- ^ The schedule bound.-  -> (forall t. ConcST t a)+  -> (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> String   -- ^ The name of the test.@@ -171,7 +196,7 @@ -- test. This will share work between the predicates, rather than -- running the concurrent computation many times for each predicate. testDejafus :: Show a-  => (forall t. ConcST t a)+  => (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> [(String, Predicate a)]   -- ^ The list of predicates (with names) to check@@ -185,7 +210,7 @@   -- ^ The memory model to use for non-synchronised @CRef@ operations.   -> Bounds   -- ^ The schedule bounds-  -> (forall t. ConcST t a)+  -> (forall t. Conc.ConcST t a)   -- ^ The computation to test   -> [(String, Predicate a)]   -- ^ The list of predicates (with names) to check@@ -193,26 +218,26 @@ testDejafus' = testst  -- | Variant of 'testDejafu' for computations which do 'IO'.-testDejafuIO :: Show a => ConcIO a -> String -> Predicate a -> Test+testDejafuIO :: Show a => Conc.ConcIO a -> String -> Predicate a -> Test testDejafuIO = testDejafuIO' defaultMemType defaultBounds  -- | Variant of 'testDejafu'' for computations which do 'IO'.-testDejafuIO' :: Show a => MemType -> Bounds -> ConcIO a -> String -> Predicate a -> Test+testDejafuIO' :: Show a => MemType -> Bounds -> Conc.ConcIO a -> String -> Predicate a -> Test testDejafuIO' memtype cb concio name p = testDejafusIO' memtype cb concio [(name, p)]  -- | Variant of 'testDejafus' for computations which do 'IO'.-testDejafusIO :: Show a => ConcIO a -> [(String, Predicate a)] -> Test+testDejafusIO :: Show a => Conc.ConcIO a -> [(String, Predicate a)] -> Test testDejafusIO = testDejafusIO' defaultMemType defaultBounds  -- | Variant of 'dejafus'' for computations which do 'IO'.-testDejafusIO' :: Show a => MemType -> Bounds -> ConcIO a -> [(String, Predicate a)] -> Test+testDejafusIO' :: Show a => MemType -> Bounds -> Conc.ConcIO a -> [(String, Predicate a)] -> Test testDejafusIO' = testio  -------------------------------------------------------------------------------- -- HUnit integration  -- | Produce a HUnit 'Test' from a Deja Fu test.-testst :: Show a => MemType -> Bounds -> (forall t. ConcST t a) -> [(String, Predicate a)] -> Test+testst :: Show a => MemType -> Bounds -> (forall t. Conc.ConcST t a) -> [(String, Predicate a)] -> Test testst memtype cb conc tests = case map toTest tests of   [t] -> t   ts  -> TestList ts@@ -221,10 +246,10 @@     toTest (name, p) = TestLabel name . TestCase $       assertString . showErr $ p traces -    traces = sctBound memtype cb conc+    traces = sctBoundST memtype cb conc  -- | Produce a HUnit 'Test' from an IO-using Deja Fu test.-testio :: Show a => MemType -> Bounds -> ConcIO a -> [(String, Predicate a)] -> Test+testio :: Show a => MemType -> Bounds -> Conc.ConcIO a -> [(String, Predicate a)] -> Test testio memtype cb concio tests = case map toTest tests of   [t] -> t   ts  -> TestList ts@@ -252,7 +277,7 @@    failures = intersperse "" . map (indent . showres) . take 5 $ _failures res -  showres (r, t) = either showFail show r ++ " " ++ showTrace t+  showres (r, t) = either Conc.showFail show r ++ " " ++ Conc.showTrace t    rest = if moreThan (_failures res) 5 then "\n\t..." else "" 
hunit-dejafu.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                hunit-dejafu-version:             0.3.0.1+version:             0.3.0.2 synopsis:            Deja Fu support for the HUnit test framework.  description:@@ -41,7 +41,7 @@   -- other-extensions:       build-depends:       base       >=4.8 && <5                      , exceptions >=0.7 && <0.9-                     , dejafu     >=0.2 && <0.4+                     , dejafu     >=0.2 && <0.5                      , HUnit      >=1.2 && <1.4   -- hs-source-dirs:         default-language:    Haskell2010