dejafu 1.5.0.0 → 1.5.1.0
raw patch · 3 files changed
+87/−22 lines, 3 filesdep +contravariantPVP ok
version bump matches the API change (PVP)
Dependencies added: contravariant
API changes (from Hackage documentation)
+ Test.DejaFu.Types: Strengthen :: (Either Failure a -> Maybe Discard) -> Strengthen a
+ Test.DejaFu.Types: Weaken :: (Either Failure a -> Maybe Discard) -> Weaken a
+ Test.DejaFu.Types: [getStrongDiscarder] :: Strengthen a -> Either Failure a -> Maybe Discard
+ Test.DejaFu.Types: [getWeakDiscarder] :: Weaken a -> Either Failure a -> Maybe Discard
+ Test.DejaFu.Types: instance Data.Functor.Contravariant.Contravariant Test.DejaFu.Types.Strengthen
+ Test.DejaFu.Types: instance Data.Functor.Contravariant.Contravariant Test.DejaFu.Types.Weaken
+ Test.DejaFu.Types: instance Data.Functor.Contravariant.Divisible.Divisible Test.DejaFu.Types.Strengthen
+ Test.DejaFu.Types: instance Data.Functor.Contravariant.Divisible.Divisible Test.DejaFu.Types.Weaken
+ Test.DejaFu.Types: instance Data.Semigroup.Semigroup (Test.DejaFu.Types.Strengthen a)
+ Test.DejaFu.Types: instance Data.Semigroup.Semigroup (Test.DejaFu.Types.Weaken a)
+ Test.DejaFu.Types: instance GHC.Base.Monoid (Test.DejaFu.Types.Strengthen a)
+ Test.DejaFu.Types: instance GHC.Base.Monoid (Test.DejaFu.Types.Weaken a)
+ Test.DejaFu.Types: newtype Strengthen a
+ Test.DejaFu.Types: newtype Weaken a
Files
- CHANGELOG.rst +15/−0
- Test/DejaFu/Types.hs +69/−20
- dejafu.cabal +3/−2
CHANGELOG.rst view
@@ -7,6 +7,21 @@ .. _PVP: https://pvp.haskell.org/ +1.5.1.0 (2018-03-29)+--------------------++* Git: :tag:`dejafu-1.5.1.0`+* Hackage: :hackage:`dejafu-1.5.1.0`++Added+~~~~~++- (:issue:`210`) ``Test.DejaFu.Types.Weaken`` and ``Strengthen``+ newtype wrappers around discard functions, with ``Semigroup``,+ ``Monoid``, ``Contravariant``, and ``Divisible`` instances+ corresponding to ``weakenDiscard`` and ``strengthenDiscard``.++ 1.5.0.0 - No More 7.10 (2018-03-28) -----------------------------------
Test/DejaFu/Types.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE StandaloneDeriving #-} -- |@@ -8,16 +9,20 @@ -- License : MIT -- Maintainer : Michael Walker <mike@barrucadu.co.uk> -- Stability : experimental--- Portability : DeriveGeneric, GeneralizedNewtypeDeriving, StandaloneDeriving+-- Portability : DeriveGeneric, GeneralizedNewtypeDeriving, LambdaCase, StandaloneDeriving -- -- Common types and functions used throughout DejaFu. module Test.DejaFu.Types where -import Control.DeepSeq (NFData(..))-import Control.Exception (Exception(..), MaskingState(..),- SomeException)-import Data.Function (on)-import GHC.Generics (Generic)+import Control.DeepSeq (NFData(..))+import Control.Exception (Exception(..),+ MaskingState(..),+ SomeException)+import Data.Function (on)+import Data.Functor.Contravariant (Contravariant(..))+import Data.Functor.Contravariant.Divisible (Divisible(..))+import Data.Semigroup (Semigroup(..))+import GHC.Generics (Generic) ------------------------------------------------------------------------------- -- * Identifiers@@ -625,41 +630,85 @@ instance NFData Discard --- | Combine two discard values, keeping the weaker.+-- | A monoid for discard functions: combines two functions, keeping+-- the weaker. -- -- @Nothing@ is weaker than @Just DiscardTrace@, which is weaker than -- @Just DiscardResultAndTrace@. This forms a commutative monoid -- where the unit is @const (Just DiscardResultAndTrace)@. --+-- @since 1.5.1.0+newtype Weaken a = Weaken+ { getWeakDiscarder :: Either Failure a -> Maybe Discard }++instance Semigroup (Weaken a) where+ (<>) = divide (\efa -> (efa, efa))++instance Monoid (Weaken a) where+ mempty = conquer+ mappend = (<>)++instance Contravariant Weaken where+ contramap f (Weaken d) = Weaken (d . fmap f)++instance Divisible Weaken where+ divide f (Weaken d1) (Weaken d2) = Weaken $ \case+ Right a ->+ let (b, c) = f a+ in min (d1 (Right b)) (d2 (Right c))+ Left e -> min (d1 (Left e)) (d2 (Left e))++ conquer = Weaken (const (Just DiscardResultAndTrace))++-- | Combine two discard functions, keeping the weaker.+-- -- @since 1.0.0.0 weakenDiscard :: (Either Failure a -> Maybe Discard) -> (Either Failure a -> Maybe Discard) -> Either Failure a -> Maybe Discard-weakenDiscard d1 d2 efa = case (d1 efa, d2 efa) of- (Nothing, _) -> Nothing- (_, Nothing) -> Nothing- (Just DiscardTrace, _) -> Just DiscardTrace- (_, Just DiscardTrace) -> Just DiscardTrace- _ -> Just DiscardResultAndTrace+weakenDiscard d1 d2 =+ getWeakDiscarder (Weaken d1 <> Weaken d2) --- | Combine two discard functions, keeping the stronger.+-- | A monoid for discard functions: combines two functions, keeping+-- the stronger. -- -- @Just DiscardResultAndTrace@ is stronger than @Just DiscardTrace@, -- which is stronger than @Nothing@. This forms a commutative monoid -- where the unit is @const Nothing@. --+-- @since 1.5.1.0+newtype Strengthen a = Strengthen+ { getStrongDiscarder :: Either Failure a -> Maybe Discard }++instance Semigroup (Strengthen a) where+ (<>) = divide (\efa -> (efa, efa))++instance Monoid (Strengthen a) where+ mempty = conquer+ mappend = (<>)++instance Contravariant Strengthen where+ contramap f (Strengthen d) = Strengthen (d . fmap f)++instance Divisible Strengthen where+ divide f (Strengthen d1) (Strengthen d2) = Strengthen $ \case+ Right a ->+ let (b, c) = f a+ in max (d1 (Right b)) (d2 (Right c))+ Left e -> max (d1 (Left e)) (d2 (Left e))++ conquer = Strengthen (const Nothing)++-- | Combine two discard functions, keeping the stronger.+-- -- @since 1.0.0.0 strengthenDiscard :: (Either Failure a -> Maybe Discard) -> (Either Failure a -> Maybe Discard) -> Either Failure a -> Maybe Discard-strengthenDiscard d1 d2 efa = case (d1 efa, d2 efa) of- (Just DiscardResultAndTrace, _) -> Just DiscardResultAndTrace- (_, Just DiscardResultAndTrace) -> Just DiscardResultAndTrace- (Just DiscardTrace, _) -> Just DiscardTrace- (_, Just DiscardTrace) -> Just DiscardTrace- _ -> Nothing+strengthenDiscard d1 d2 =+ getStrongDiscarder (Strengthen d1 <> Strengthen d2) ------------------------------------------------------------------------------- -- * Memory Models
dejafu.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: dejafu-version: 1.5.0.0+version: 1.5.1.0 synopsis: A library for unit-testing concurrent programs. description:@@ -33,7 +33,7 @@ source-repository this type: git location: https://github.com/barrucadu/dejafu.git- tag: dejafu-1.5.0.0+ tag: dejafu-1.5.1.0 library exposed-modules: Test.DejaFu@@ -61,6 +61,7 @@ build-depends: base >=4.9 && <5 , concurrency >=1.5 && <1.6 , containers >=0.5 && <0.6+ , contravariant >=1.2 && <1.5 , deepseq >=1.1 && <2 , exceptions >=0.7 && <0.11 , leancheck >=0.6 && <0.8