Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- showsType :: forall t. Typeable t => ShowS
- showsArrayType :: forall r ix e. (Typeable r, Typeable ix, Typeable e) => ShowS
- assertException :: (Testable b, NFData a, Exception exc) => (exc -> b) -> a -> Property
- assertExceptionIO :: (Testable b, NFData a, Exception exc) => (exc -> b) -> IO a -> Property
- assertSomeException :: NFData a => a -> Property
- assertSomeExceptionIO :: NFData a => IO a -> Property
- toStringException :: Either SomeException a -> Either String a
- data ExpectedException = ExpectedException
- applyFun2Compat :: Fun (a, b) c -> a -> b -> c
- guard :: Alternative f => Bool -> f ()
- join :: Monad m => m (m a) -> m a
- class Applicative m => Monad (m :: Type -> Type) where
- class Functor (f :: Type -> Type) where
- fmap :: (a -> b) -> f a -> f b
- class Typeable (a :: k)
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- data RealWorld :: Type
- data TyCon
- data ST s a
- labelledExamplesWithResult :: Testable prop => Args -> prop -> IO Result
- labelledExamplesResult :: Testable prop => prop -> IO Result
- labelledExamplesWith :: Testable prop => Args -> prop -> IO ()
- labelledExamples :: Testable prop => prop -> IO ()
- verboseCheckAll :: Q Exp
- quickCheckAll :: Q Exp
- allProperties :: Q Exp
- forAllProperties :: Q Exp
- monomorphic :: Name -> ExpQ
- polyVerboseCheck :: Name -> ExpQ
- polyQuickCheck :: Name -> ExpQ
- runSTGen :: (forall s. Gen (ST s a)) -> Gen a
- monadicST :: Testable a => (forall s. PropertyM (ST s) a) -> Property
- monadicIO :: Testable a => PropertyM IO a -> Property
- monadic' :: (Testable a, Monad m) => PropertyM m a -> Gen (m Property)
- monadic :: (Testable a, Monad m) => (m Property -> Property) -> PropertyM m a -> Property
- monitor :: Monad m => (Property -> Property) -> PropertyM m ()
- forAllM :: (Monad m, Show a) => Gen a -> (a -> PropertyM m b) -> PropertyM m b
- wp :: Monad m => m a -> (a -> PropertyM m b) -> PropertyM m b
- pick :: (Monad m, Show a) => Gen a -> PropertyM m a
- run :: Monad m => m a -> PropertyM m a
- pre :: Monad m => Bool -> PropertyM m ()
- assert :: Monad m => Bool -> PropertyM m ()
- stop :: (Testable prop, Monad m) => prop -> PropertyM m a
- newtype PropertyM (m :: Type -> Type) a = MkPropertyM {
- unPropertyM :: (a -> Gen (m Property)) -> Gen (m Property)
- verboseCheckWithResult :: Testable prop => Args -> prop -> IO Result
- verboseCheckResult :: Testable prop => prop -> IO Result
- verboseCheckWith :: Testable prop => Args -> prop -> IO ()
- verboseCheck :: Testable prop => prop -> IO ()
- quickCheckWithResult :: Testable prop => Args -> prop -> IO Result
- quickCheckResult :: Testable prop => prop -> IO Result
- quickCheckWith :: Testable prop => Args -> prop -> IO ()
- quickCheck :: Testable prop => prop -> IO ()
- stdArgs :: Args
- isSuccess :: Result -> Bool
- data Args = Args {
- replay :: Maybe (QCGen, Int)
- maxSuccess :: Int
- maxDiscardRatio :: Int
- maxSize :: Int
- chatty :: Bool
- maxShrinks :: Int
- data Result
- = Success { }
- | GaveUp { }
- | Failure {
- numTests :: Int
- numDiscarded :: Int
- numShrinks :: Int
- numShrinkTries :: Int
- numShrinkFinal :: Int
- usedSeed :: QCGen
- usedSize :: Int
- reason :: String
- theException :: Maybe AnException
- output :: String
- failingTestCase :: [String]
- failingLabels :: [String]
- failingClasses :: Set String
- | NoExpectedFailure { }
- total :: NFData a => a -> Property
- (=/=) :: (Eq a, Show a) => a -> a -> Property
- (===) :: (Eq a, Show a) => a -> a -> Property
- disjoin :: Testable prop => [prop] -> Property
- (.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- conjoin :: Testable prop => [prop] -> Property
- (.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- forAllShrinkBlind :: Testable prop => Gen a -> (a -> [a]) -> (a -> prop) -> Property
- forAllShrinkShow :: Testable prop => Gen a -> (a -> [a]) -> (a -> String) -> (a -> prop) -> Property
- forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> Property
- forAllBlind :: Testable prop => Gen a -> (a -> prop) -> Property
- forAllShow :: Testable prop => Gen a -> (a -> String) -> (a -> prop) -> Property
- forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property
- within :: Testable prop => Int -> prop -> Property
- (==>) :: Testable prop => Bool -> prop -> Property
- coverTable :: Testable prop => String -> [(String, Double)] -> prop -> Property
- tabulate :: Testable prop => String -> [String] -> prop -> Property
- cover :: Testable prop => Double -> Bool -> String -> prop -> Property
- classify :: Testable prop => Bool -> String -> prop -> Property
- collect :: (Show a, Testable prop) => a -> prop -> Property
- label :: Testable prop => String -> prop -> Property
- stdConfidence :: Confidence
- checkCoverageWith :: Testable prop => Confidence -> prop -> Property
- checkCoverage :: Testable prop => prop -> Property
- withMaxSuccess :: Testable prop => Int -> prop -> Property
- again :: Testable prop => prop -> Property
- once :: Testable prop => prop -> Property
- expectFailure :: Testable prop => prop -> Property
- verboseShrinking :: Testable prop => prop -> Property
- verbose :: Testable prop => prop -> Property
- whenFail' :: Testable prop => IO () -> prop -> Property
- whenFail :: Testable prop => IO () -> prop -> Property
- printTestCase :: Testable prop => String -> prop -> Property
- counterexample :: Testable prop => String -> prop -> Property
- noShrinking :: Testable prop => prop -> Property
- shrinking :: Testable prop => (a -> [a]) -> a -> (a -> prop) -> Property
- mapSize :: Testable prop => (Int -> Int) -> prop -> Property
- idempotentIOProperty :: Testable prop => IO prop -> Property
- ioProperty :: Testable prop => IO prop -> Property
- data Property
- class Testable prop where
- data Discard = Discard
- data Confidence = Confidence {}
- applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d
- applyFun2 :: Fun (a, b) c -> a -> b -> c
- applyFun :: Fun a b -> a -> b
- apply :: Fun a b -> a -> b
- functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c
- functionVoid :: (forall b. void -> b) -> void :-> c
- functionShow :: (Show a, Read a) => (a -> c) -> a :-> c
- functionIntegral :: Integral a => (a -> b) -> a :-> b
- functionRealFrac :: RealFrac a => (a -> b) -> a :-> b
- functionBoundedEnum :: (Eq a, Bounded a, Enum a) => (a -> b) -> a :-> b
- pattern Fn :: forall a b. (a -> b) -> Fun a b
- pattern Fn2 :: forall a b c. (a -> b -> c) -> Fun (a, b) c
- pattern Fn3 :: forall a b c d. (a -> b -> c -> d) -> Fun (a, b, c) d
- data a :-> c
- class Function a where
- data Fun a b = Fun (a :-> b, b, Shrunk) (a -> b)
- newtype Blind a = Blind {
- getBlind :: a
- newtype Fixed a = Fixed {
- getFixed :: a
- newtype OrderedList a = Ordered {
- getOrdered :: [a]
- newtype NonEmptyList a = NonEmpty {
- getNonEmpty :: [a]
- data InfiniteList a = InfiniteList {
- getInfiniteList :: [a]
- infiniteListInternalData :: InfiniteListInternalData a
- newtype SortedList a = Sorted {
- getSorted :: [a]
- newtype Positive a = Positive {
- getPositive :: a
- newtype Negative a = Negative {
- getNegative :: a
- newtype NonZero a = NonZero {
- getNonZero :: a
- newtype NonNegative a = NonNegative {
- getNonNegative :: a
- newtype NonPositive a = NonPositive {
- getNonPositive :: a
- newtype Large a = Large {
- getLarge :: a
- newtype Small a = Small {
- getSmall :: a
- newtype Shrink2 a = Shrink2 {
- getShrink2 :: a
- data Smart a = Smart Int a
- data Shrinking s a = Shrinking s a
- class ShrinkState s a where
- shrinkInit :: a -> s
- shrinkState :: a -> s -> [(a, s)]
- newtype ASCIIString = ASCIIString {}
- newtype UnicodeString = UnicodeString {}
- newtype PrintableString = PrintableString {}
- infiniteList :: Arbitrary a => Gen [a]
- orderedList :: (Ord a, Arbitrary a) => Gen [a]
- vector :: Arbitrary a => Int -> Gen [a]
- coarbitraryEnum :: Enum a => a -> Gen b -> Gen b
- coarbitraryShow :: Show a => a -> Gen b -> Gen b
- coarbitraryReal :: Real a => a -> Gen b -> Gen b
- coarbitraryIntegral :: Integral a => a -> Gen b -> Gen b
- (><) :: (Gen a -> Gen a) -> (Gen a -> Gen a) -> Gen a -> Gen a
- genericCoarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b
- shrinkDecimal :: RealFrac a => a -> [a]
- shrinkRealFrac :: RealFrac a => a -> [a]
- shrinkIntegral :: Integral a => a -> [a]
- shrinkMapBy :: (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b]
- shrinkMap :: Arbitrary a => (a -> b) -> (b -> a) -> b -> [b]
- shrinkNothing :: a -> [a]
- arbitraryPrintableChar :: Gen Char
- arbitraryASCIIChar :: Gen Char
- arbitraryUnicodeChar :: Gen Char
- arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a
- arbitraryBoundedEnum :: (Bounded a, Enum a) => Gen a
- arbitraryBoundedRandom :: (Bounded a, Random a) => Gen a
- arbitraryBoundedIntegral :: (Bounded a, Integral a) => Gen a
- arbitrarySizedFractional :: Fractional a => Gen a
- arbitrarySizedNatural :: Integral a => Gen a
- arbitrarySizedIntegral :: Integral a => Gen a
- applyArbitrary4 :: (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => (a -> b -> c -> d -> r) -> Gen r
- applyArbitrary3 :: (Arbitrary a, Arbitrary b, Arbitrary c) => (a -> b -> c -> r) -> Gen r
- applyArbitrary2 :: (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r
- shrinkList :: (a -> [a]) -> [a] -> [[a]]
- subterms :: (Generic a, GSubterms (Rep a) a) => a -> [a]
- recursivelyShrink :: (Generic a, RecursivelyShrink (Rep a)) => a -> [a]
- genericShrink :: (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a]
- shrink2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => f a b -> [f a b]
- arbitrary2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => Gen (f a b)
- shrink1 :: (Arbitrary1 f, Arbitrary a) => f a -> [f a]
- arbitrary1 :: (Arbitrary1 f, Arbitrary a) => Gen (f a)
- class Arbitrary a where
- class Arbitrary1 (f :: Type -> Type) where
- liftArbitrary :: Gen a -> Gen (f a)
- liftShrink :: (a -> [a]) -> f a -> [f a]
- class Arbitrary2 (f :: Type -> Type -> Type) where
- liftArbitrary2 :: Gen a -> Gen b -> Gen (f a b)
- liftShrink2 :: (a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
- class CoArbitrary a where
- coarbitrary :: a -> Gen b -> Gen b
- infiniteListOf :: Gen a -> Gen [a]
- vectorOf :: Int -> Gen a -> Gen [a]
- listOf1 :: Gen a -> Gen [a]
- listOf :: Gen a -> Gen [a]
- growingElements :: [a] -> Gen a
- shuffle :: [a] -> Gen [a]
- sublistOf :: [a] -> Gen [a]
- elements :: [a] -> Gen a
- frequency :: [(Int, Gen a)] -> Gen a
- oneof :: [Gen a] -> Gen a
- suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)
- suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b
- suchThat :: Gen a -> (a -> Bool) -> Gen a
- sample :: Show a => Gen a -> IO ()
- sample' :: Gen a -> IO [a]
- generate :: Gen a -> IO a
- choose :: Random a => (a, a) -> Gen a
- scale :: (Int -> Int) -> Gen a -> Gen a
- resize :: Int -> Gen a -> Gen a
- getSize :: Gen Int
- sized :: (Int -> Gen a) -> Gen a
- variant :: Integral n => n -> Gen a -> Gen a
- data Gen a
- discard :: a
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- unless :: Applicative f => Bool -> f () -> f ()
- replicateM_ :: Applicative m => Int -> m a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- forever :: Applicative f => f a -> f b
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- fixST :: (a -> ST s a) -> ST s a
- stToIO :: ST RealWorld a -> IO a
- typeOf7 :: Typeable t => t a b c d e f g -> TypeRep
- typeOf6 :: Typeable t => t a b c d e f -> TypeRep
- typeOf5 :: Typeable t => t a b c d e -> TypeRep
- typeOf4 :: Typeable t => t a b c d -> TypeRep
- typeOf3 :: Typeable t => t a b c -> TypeRep
- typeOf2 :: Typeable t => t a b -> TypeRep
- typeOf1 :: Typeable t => t a -> TypeRep
- rnfTypeRep :: TypeRep -> ()
- typeRepFingerprint :: TypeRep -> Fingerprint
- typeRepTyCon :: TypeRep -> TyCon
- typeRepArgs :: TypeRep -> [TypeRep]
- splitTyConApp :: TypeRep -> (TyCon, [TypeRep])
- mkFunTy :: TypeRep -> TypeRep -> TypeRep
- funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
- gcast2 :: (Typeable t, Typeable t') => c (t a b) -> Maybe (c (t' a b))
- gcast1 :: (Typeable t, Typeable t') => c (t a) -> Maybe (c (t' a))
- gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b)
- eqT :: (Typeable a, Typeable b) => Maybe (a :~: b)
- cast :: (Typeable a, Typeable b) => a -> Maybe b
- showsTypeRep :: TypeRep -> ShowS
- typeRep :: Typeable a => proxy a -> TypeRep
- typeOf :: Typeable a => a -> TypeRep
- type TypeRep = SomeTypeRep
- rnfTyCon :: TyCon -> ()
- tyConFingerprint :: TyCon -> Fingerprint
- tyConName :: TyCon -> String
- tyConModule :: TyCon -> String
- tyConPackage :: TyCon -> String
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
- data (a :: k) :~: (b :: k) :: forall k. k -> k -> Type where
- data (a :: k1) :~~: (b :: k2) :: forall k1 k2. k1 -> k2 -> Type where
- runST :: (forall s. ST s a) -> a
- void :: Functor f => f a -> f ()
- fromMaybe :: a -> Maybe a -> a
- isNothing :: Maybe a -> Bool
- isJust :: Maybe a -> Bool
- ap :: Monad m => m (a -> b) -> m a -> m b
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- when :: Applicative f => Bool -> f () -> f ()
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- type HasCallStack = ?callStack :: CallStack
- deepseq :: NFData a => a -> b -> b
- class NFData a
- type Selector a = a -> Bool
- type Expectation = Assertion
- expectationFailure :: HasCallStack -> String -> Expectation
- shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation
- anyException :: Selector SomeException
- anyErrorCall :: Selector ErrorCall
- errorCall :: String -> Selector ErrorCall
- anyIOException :: Selector IOException
- anyArithException :: Selector ArithException
- prop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- example :: Expectation -> Expectation
- type ActionWith a = a -> IO ()
- class Example e where
- type SpecWith a = SpecM a ()
- type Spec = SpecWith ()
- runIO :: IO r -> SpecM a r
- before :: IO a -> SpecWith a -> Spec
- before_ :: IO () -> SpecWith a -> SpecWith a
- beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- beforeAll :: IO a -> SpecWith a -> Spec
- beforeAll_ :: IO () -> SpecWith a -> SpecWith a
- after :: ActionWith a -> SpecWith a -> SpecWith a
- after_ :: IO () -> SpecWith a -> SpecWith a
- around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec
- afterAll :: ActionWith a -> SpecWith a -> SpecWith a
- afterAll_ :: IO () -> SpecWith a -> SpecWith a
- around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a
- aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b
- describe :: HasCallStack => String -> SpecWith a -> SpecWith a
- context :: HasCallStack => String -> SpecWith a -> SpecWith a
- xdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- xcontext :: HasCallStack => String -> SpecWith a -> SpecWith a
- it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- specify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- focus :: SpecWith a -> SpecWith a
- fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- fcontext :: HasCallStack => String -> SpecWith a -> SpecWith a
- parallel :: SpecWith a -> SpecWith a
- pending :: HasCallStack -> Expectation
- pendingWith :: HasCallStack -> String -> Expectation
- modifyMaxSuccess :: (Int -> Int) -> SpecWith a -> SpecWith a
- modifyMaxDiscardRatio :: (Int -> Int) -> SpecWith a -> SpecWith a
- modifyMaxSize :: (Int -> Int) -> SpecWith a -> SpecWith a
- modifyMaxShrinks :: (Int -> Int) -> SpecWith a -> SpecWith a
- modifyArgs :: (Args -> Args) -> SpecWith a -> SpecWith a
- hspec :: Spec -> IO ()
Documentation
showsArrayType :: forall r ix e. (Typeable r, Typeable ix, Typeable e) => ShowS Source #
Use Typeable to show the array type
assertSomeException :: NFData a => a -> Property Source #
toStringException :: Either SomeException a -> Either String a Source #
data ExpectedException Source #
Instances
Eq ExpectedException Source # | |
Defined in Test.Massiv.Utils (==) :: ExpectedException -> ExpectedException -> Bool # (/=) :: ExpectedException -> ExpectedException -> Bool # | |
Show ExpectedException Source # | |
Defined in Test.Massiv.Utils showsPrec :: Int -> ExpectedException -> ShowS # show :: ExpectedException -> String # showList :: [ExpectedException] -> ShowS # | |
Exception ExpectedException Source # | |
Defined in Test.Massiv.Utils |
applyFun2Compat :: Fun (a, b) c -> a -> b -> c Source #
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative
computations. Defined by
guard True =pure
() guard False =empty
Examples
Common uses of guard
include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative
-based parser.
As an example of signaling an error in the error monad Maybe
,
consider a safe division function safeDiv x y
that returns
Nothing
when the denominator y
is zero and
otherwise. For example:Just
(x `div`
y)
>>> safeDiv 4 0 Nothing >>> safeDiv 4 2 Just 2
A definition of safeDiv
using guards, but not guard
:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y | y /= 0 = Just (x `div` y) | otherwise = Nothing
A definition of safeDiv
using guard
and Monad
do
-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
join :: Monad m => m (m a) -> m a #
The join
function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
Examples
A common use of join
is to run an IO
computation returned from
an STM
transaction, since STM
transactions
can't perform IO
directly. Recall that
atomically
:: STM a -> IO a
is used to run STM
transactions atomically. So, by
specializing the types of atomically
and join
to
atomically
:: STM (IO b) -> IO (IO b)join
:: IO (IO b) -> IO b
we can compose them as
join
.atomically
:: STM (IO b) -> IO b
class Applicative m => Monad (m :: Type -> Type) where #
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following laws:
Furthermore, the Monad
and Applicative
operations should relate as follows:
The above laws imply:
and that pure
and (<*>
) satisfy the applicative functor laws.
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
Fail with a message. This operation is not part of the
mathematical definition of a monad, but is invoked on pattern-match
failure in a do
expression.
As part of the MonadFail proposal (MFP), this function is moved
to its own class MonadFail
(see Control.Monad.Fail for more
details). The definition here will be removed in a future
release.
Instances
Monad [] | Since: base-2.1 |
Monad Maybe | Since: base-2.1 |
Monad IO | Since: base-2.1 |
Monad Par1 | Since: base-4.9.0.0 |
Monad Q | |
Monad Rose | |
Monad Gen | |
Monad Complex | Since: base-4.9.0.0 |
Monad Min | Since: base-4.9.0.0 |
Monad Max | Since: base-4.9.0.0 |
Monad First | Since: base-4.9.0.0 |
Monad Last | Since: base-4.9.0.0 |
Monad Option | Since: base-4.9.0.0 |
Monad Identity | Since: base-4.8.0.0 |
Monad STM | Since: base-4.3.0.0 |
Monad First | Since: base-4.8.0.0 |
Monad Last | Since: base-4.8.0.0 |
Monad Dual | Since: base-4.8.0.0 |
Monad Sum | Since: base-4.8.0.0 |
Monad Product | Since: base-4.8.0.0 |
Monad Down | Since: base-4.11.0.0 |
Monad ReadP | Since: base-2.1 |
Monad NonEmpty | Since: base-4.9.0.0 |
Monad Tree | |
Monad Seq | |
Monad Vector | |
Monad Box | |
Monad Id | |
Monad SmallArray | |
Defined in Data.Primitive.SmallArray (>>=) :: SmallArray a -> (a -> SmallArray b) -> SmallArray b # (>>) :: SmallArray a -> SmallArray b -> SmallArray b # return :: a -> SmallArray a # fail :: String -> SmallArray a # | |
Monad Array | |
Monad P | Since: base-2.1 |
Monad (Either e) | Since: base-4.4.0.0 |
Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
Monad (ST s) | Since: base-2.1 |
Monad m => Monad (PropertyM m) | |
Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0 |
Defined in Control.Applicative (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # fail :: String -> WrappedMonad m a # | |
ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in Control.Arrow (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # fail :: String -> ArrowMonad a a0 # | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Monad m => Monad (MaybeT m) | |
Monad (SpecM a) | |
Monad m => Monad (ListT m) | |
Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
Monad f => Monad (Ap f) | Since: base-4.12.0.0 |
Monad f => Monad (Alt f) | Since: base-4.8.0.0 |
(Applicative f, Monad f) => Monad (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal (>>=) :: WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b # (>>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # return :: a -> WhenMissing f x a # fail :: String -> WhenMissing f x a # | |
Monad m => Monad (ExceptT e m) | |
Monad (Array DS Ix1) | |
Monad m => Monad (IdentityT m) | |
(Monad m, Error e) => Monad (ErrorT e m) | |
Monad m => Monad (StateT s m) | |
Monad m => Monad (StateT s m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(Monoid w, Functor m, Monad m) => Monad (AccumT w m) | |
Monad m => Monad (SelectT r m) | |
Monad ((->) r :: Type -> Type) | Since: base-2.1 |
(Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
(Monad f, Monad g) => Monad (Product f g) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal (>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b # (>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # return :: a -> WhenMatched f x y a # fail :: String -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Monad (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal (>>=) :: WhenMissing f k x a -> (a -> WhenMissing f k x b) -> WhenMissing f k x b # (>>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # return :: a -> WhenMissing f k x a # fail :: String -> WhenMissing f k x a # | |
Monad (ContT r m) | |
Monad m => Monad (ReaderT r m) | |
Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal (>>=) :: WhenMatched f k x y a -> (a -> WhenMatched f k x y b) -> WhenMatched f k x y b # (>>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # return :: a -> WhenMatched f k x y a # fail :: String -> WhenMatched f k x y a # | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
class Functor (f :: Type -> Type) where #
The Functor
class is used for types that can be mapped over.
Instances of Functor
should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor
for lists, Maybe
and IO
satisfy these laws.
Instances
The class Typeable
allows a concrete representation of a type to
be calculated.
typeRep#
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_
.
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_
.
RealWorld
is deeply magical. It is primitive, but it is not
unlifted (hence ptrArg
). We never manipulate values of type
RealWorld
; it's only used in the type system, to parameterise State#
.
The strict state-transformer monad.
A computation of type
transforms an internal state indexed
by ST
s as
, and returns a value of type a
.
The s
parameter is either
- an uninstantiated type variable (inside invocations of
runST
), or RealWorld
(inside invocations ofstToIO
).
It serves to keep the internal states of different invocations
of runST
separate from each other and from invocations of
stToIO
.
The >>=
and >>
operations are strict in the state (though not in
values stored in the state). For example,
runST
(writeSTRef _|_ v >>= f) = _|_
Instances
Monad (ST s) | Since: base-2.1 |
Functor (ST s) | Since: base-2.1 |
MonadFail (ST s) | Since: base-4.11.0.0 |
Applicative (ST s) | Since: base-4.4.0.0 |
MonadThrow (ST s) | |
Defined in Control.Monad.Catch | |
PrimMonad (ST s) | |
PrimBase (ST s) | |
Show (ST s a) | Since: base-2.1 |
Semigroup a => Semigroup (ST s a) | Since: base-4.11.0.0 |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
type PrimState (ST s) | |
Defined in Control.Monad.Primitive |
labelledExamplesWithResult :: Testable prop => Args -> prop -> IO Result #
A variant of labelledExamples
that takes test arguments and returns a result.
labelledExamplesResult :: Testable prop => prop -> IO Result #
A variant of labelledExamples
that returns a result.
labelledExamplesWith :: Testable prop => Args -> prop -> IO () #
A variant of labelledExamples
that takes test arguments.
labelledExamples :: Testable prop => prop -> IO () #
Given a property, which must use label
, collect
, classify
or cover
to associate labels with test cases, find an example test case for each possible label.
The example test cases are minimised using shrinking.
For example, suppose we test
and record the number
of times that delete
x xsx
occurs in xs
:
prop_delete :: Int -> [Int] -> Property prop_delete x xs = classify (count x xs == 0) "count x xs == 0" $ classify (count x xs == 1) "count x xs == 1" $ classify (count x xs >= 2) "count x xs >= 2" $ counterexample (show (delete x xs)) $ count x (delete x xs) == max 0 (count x xs-1) where count x xs = length (filter (== x) xs)
labelledExamples
generates three example test cases, one for each label:
>>>
labelledExamples prop_delete
*** Found example of count x xs == 0 0 [] [] *** Found example of count x xs == 1 0 [0] [] *** Found example of count x xs >= 2 5 [5,5] [5] +++ OK, passed 100 tests: 78% count x xs == 0 21% count x xs == 1 1% count x xs >= 2
verboseCheckAll :: Q Exp #
Test all properties in the current module.
This is just a convenience function that combines quickCheckAll
and verbose
.
verboseCheckAll
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
quickCheckAll :: Q Exp #
Test all properties in the current module.
The name of the property must begin with prop_
.
Polymorphic properties will be defaulted to Integer
.
Returns True
if all tests succeeded, False
otherwise.
To use quickCheckAll
, add a definition to your module along
the lines of
return [] runTests = $quickCheckAll
and then execute runTests
.
Note: the bizarre return []
in the example above is needed on
GHC 7.8 and later; without it, quickCheckAll
will not be able to find
any of the properties. For the curious, the return []
is a
Template Haskell splice that makes GHC insert the empty list
of declarations at that point in the program; GHC typechecks
everything before the return []
before it starts on the rest
of the module, which means that the later call to quickCheckAll
can see everything that was defined before the return []
. Yikes!
allProperties :: Q Exp #
List all properties in the current module.
$
has type allProperties
[(
.String
, Property
)]
allProperties
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
forAllProperties :: Q Exp #
Test all properties in the current module, using a custom
quickCheck
function. The same caveats as with quickCheckAll
apply.
$
has type forAllProperties
(
.
An example invocation is Property
-> IO
Result
) -> IO
Bool
$
,
which does the same thing as forAllProperties
quickCheckResult
$
.quickCheckAll
forAllProperties
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
monomorphic :: Name -> ExpQ #
Monomorphise an arbitrary property by defaulting all type variables to Integer
.
For example, if f
has type
then Ord
a => [a] -> [a]$(
has type monomorphic
'f)[
.Integer
] -> [Integer
]
If you want to use monomorphic
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
polyVerboseCheck :: Name -> ExpQ #
Test a polymorphic property, defaulting all type variables to Integer
.
This is just a convenience function that combines verboseCheck
and monomorphic
.
If you want to use polyVerboseCheck
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
polyQuickCheck :: Name -> ExpQ #
Test a polymorphic property, defaulting all type variables to Integer
.
Invoke as $(
, where polyQuickCheck
'prop)prop
is a property.
Note that just evaluating
in GHCi will seem to
work, but will silently default all type variables to quickCheck
prop()
!
$(
means the same as
polyQuickCheck
'prop)
.
If you want to supply custom arguments to quickCheck
$(monomorphic
'prop)polyQuickCheck
,
you will have to combine quickCheckWith
and monomorphic
yourself.
If you want to use polyQuickCheck
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
monadicST :: Testable a => (forall s. PropertyM (ST s) a) -> Property #
Runs the property monad for ST
-computations.
-- Your mutable sorting algorithm here sortST :: Ord a => [a] ->ST
s (MVector s a) sortST =thaw
.fromList
.sort
prop_sortST xs = monadicST $ do sorted <- run (freeze
=<< sortST xs) assert (toList
sorted == sort xs)
>>>
quickCheck prop_sortST
+++ OK, passed 100 tests.
monadicIO :: Testable a => PropertyM IO a -> Property #
Runs the property monad for IO
-computations.
prop_cat msg = monadicIO $ do (exitCode, stdout, _) <- run (readProcessWithExitCode
"cat" [] msg) pre (ExitSuccess
== exitCode) assert (stdout == msg)
>>>
quickCheck prop_cat
+++ OK, passed 100 tests.
monitor :: Monad m => (Property -> Property) -> PropertyM m () #
Allows making observations about the test data:
monitor (collect
e)
collects the distribution of value of e
.
monitor (counterexample
"Failure!")
Adds "Failure!"
to the counterexamples.
run :: Monad m => m a -> PropertyM m a #
The lifting operation of the property monad. Allows embedding
monadic/IO
-actions in properties:
log :: Int -> IO () prop_foo n = monadicIO $ do run (log n) -- ...
pre :: Monad m => Bool -> PropertyM m () #
Tests preconditions. Unlike assert
this does not cause the
property to fail, rather it discards them just like using the
implication combinator ==>
.
This allows representing the Hoare triple
{p} x ← e{q}
as
pre p x <- run e assert q
assert :: Monad m => Bool -> PropertyM m () #
Allows embedding non-monadic properties into monadic ones.
newtype PropertyM (m :: Type -> Type) a #
The property monad is really a monad transformer that can contain
monadic computations in the monad m
it is parameterized by:
m
- them
-computations that may be performed withinPropertyM
Elements of PropertyM m a
may mix property operations and m
-computations.
MkPropertyM | |
|
Instances
MonadTrans PropertyM | |
Defined in Test.QuickCheck.Monadic | |
Monad m => Monad (PropertyM m) | |
Functor (PropertyM m) | |
Monad m => MonadFail (PropertyM m) | |
Defined in Test.QuickCheck.Monadic | |
Applicative (PropertyM m) | |
Defined in Test.QuickCheck.Monadic | |
MonadIO m => MonadIO (PropertyM m) | |
Defined in Test.QuickCheck.Monadic |
verboseCheckWithResult :: Testable prop => Args -> prop -> IO Result #
Tests a property, using test arguments, produces a test result, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckWithResult
and verbose
.
verboseCheckResult :: Testable prop => prop -> IO Result #
Tests a property, produces a test result, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckResult
and verbose
.
verboseCheckWith :: Testable prop => Args -> prop -> IO () #
Tests a property, using test arguments, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckWith
and verbose
.
verboseCheck :: Testable prop => prop -> IO () #
Tests a property and prints the results and all test cases generated to stdout
.
This is just a convenience function that means the same as
.quickCheck
. verbose
quickCheckWithResult :: Testable prop => Args -> prop -> IO Result #
Tests a property, using test arguments, produces a test result, and prints the results to stdout
.
quickCheckResult :: Testable prop => prop -> IO Result #
Tests a property, produces a test result, and prints the results to stdout
.
quickCheckWith :: Testable prop => Args -> prop -> IO () #
Tests a property, using test arguments, and prints the results to stdout
.
quickCheck :: Testable prop => prop -> IO () #
Tests a property and prints the results to stdout
.
By default up to 100 tests are performed, which may not be enough
to find all bugs. To run more tests, use withMaxSuccess
.
If you want to get the counterexample as a Haskell value, rather than just printing it, try the quickcheck-with-counterexamples package.
Args specifies arguments to the QuickCheck driver
Args | |
|
Result represents the test result
Success | A successful test run |
| |
GaveUp | Given up |
| |
Failure | A failed test run |
| |
NoExpectedFailure | A property that should have failed did not |
|
total :: NFData a => a -> Property #
Checks that a value is total, i.e., doesn't crash when evaluated.
(=/=) :: (Eq a, Show a) => a -> a -> Property infix 4 #
Like /=
, but prints a counterexample when it fails.
(===) :: (Eq a, Show a) => a -> a -> Property infix 4 #
Like ==
, but prints a counterexample when it fails.
(.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property infixr 1 #
Disjunction: p1
.||.
p2
passes unless p1
and p2
simultaneously fail.
(.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property infixr 1 #
Conjunction: p1
.&&.
p2
passes if both p1
and p2
pass.
forAllShrinkBlind :: Testable prop => Gen a -> (a -> [a]) -> (a -> prop) -> Property #
Like forAllShrink
, but without printing the generated value.
forAllShrinkShow :: Testable prop => Gen a -> (a -> [a]) -> (a -> String) -> (a -> prop) -> Property #
Like forAllShrink
, but with an explicitly given show function.
forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> Property #
Like forAll
, but tries to shrink the argument for failing test cases.
forAllBlind :: Testable prop => Gen a -> (a -> prop) -> Property #
Like forAll
, but without printing the generated value.
forAllShow :: Testable prop => Gen a -> (a -> String) -> (a -> prop) -> Property #
Like forAll
, but with an explicitly given show function.
forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property #
Explicit universal quantification: uses an explicitly given test case generator.
within :: Testable prop => Int -> prop -> Property #
Considers a property failed if it does not complete within the given number of microseconds.
Note: if the property times out, variables quantified inside the
within
will not be printed. Therefore, you should use within
only in the body of your property.
Good: prop_foo a b c = within 1000000 ...
Bad: prop_foo = within 1000000 $ \a b c -> ...
Bad: prop_foo a b c = ...; main = quickCheck (within 1000000 prop_foo)
(==>) :: Testable prop => Bool -> prop -> Property infixr 0 #
Implication for properties: The resulting property holds if
the first argument is False
(in which case the test case is discarded),
or if the given property holds. Note that using implication carelessly can
severely skew test case distribution: consider using cover
to make sure
that your test data is still good quality.
coverTable :: Testable prop => String -> [(String, Double)] -> prop -> Property #
Checks that the values in a given table
appear a certain proportion of
the time. A call to coverTable
table
[(x1, p1), ..., (xn, pn)]
asserts
that of the values in table
, x1
should appear at least p1
percent of
the time, x2
at least p2
percent of the time, and so on.
Note: If the coverage check fails, QuickCheck prints out a warning, but
the property does not fail. To make the property fail, use checkCoverage
.
Continuing the example from the tabular
combinator...
data Command = LogIn | LogOut | SendMessage String deriving (Data, Show) prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ...
...we can add a coverage requirement as follows, which checks that LogIn
,
LogOut
and SendMessage
each occur at least 25% of the time:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> coverTable "Commands" [("LogIn", 25), ("LogOut", 25), ("SendMessage", 25)] $ 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ... property goes here ...
>>>
quickCheck prop_chatroom
+++ OK, passed 100 tests; 2909 discarded: 56% 0 17% 1 10% 2 6% 3 5% 4 3% 5 3% 7 Commands (111 in total): 51.4% LogIn 30.6% SendMessage 18.0% LogOut Table 'Commands' had only 18.0% LogOut, but expected 25.0%
tabulate :: Testable prop => String -> [String] -> prop -> Property #
Collects information about test case distribution into a table.
The arguments to tabulate
are the table's name and a list of values
associated with the current test case. After testing, QuickCheck prints the
frequency of all collected values. The frequencies are expressed as a
percentage of the total number of values collected.
You should prefer tabulate
to label
when each test case is associated
with a varying number of values. Here is a (not terribly useful) example,
where the test data is a list of integers and we record all values that
occur in the list:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> tabulate "List elements" (map show xs) $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests; 1684 discarded. List elements (109 in total): 3.7% 0 3.7% 17 3.7% 2 3.7% 6 2.8% -6 2.8% -7
Here is a more useful example. We are testing a chatroom, where the user can log in, log out, or send a message:
data Command = LogIn | LogOut | SendMessage String deriving (Data, Show) instance Arbitrary Command where ...
There are some restrictions on command sequences; for example, the user must
log in before doing anything else. The function valid :: [Command] -> Bool
checks that a command sequence is allowed. Our property then has the form:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = valid cmds ==> ...
The use of ==>
may skew test case distribution. We use collect
to see the
length of the command sequences, and tabulate
to get the frequencies of the
individual commands:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> 'collect' (length cmds) $ 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ...
>>>
quickCheckWith stdArgs{maxDiscardRatio = 1000} prop_chatroom
+++ OK, passed 100 tests; 2775 discarded: 60% 0 20% 1 15% 2 3% 3 1% 4 1% 5 Commands (68 in total): 62% LogIn 22% SendMessage 16% LogOut
:: Testable prop | |
=> Double | The required percentage (0-100) of test cases. |
-> Bool |
|
-> String | Label for the test case class. |
-> prop | |
-> Property |
Checks that at least the given proportion of successful test cases belong to the given class. Discarded tests (i.e. ones with a false precondition) do not affect coverage.
Note: If the coverage check fails, QuickCheck prints out a warning, but
the property does not fail. To make the property fail, use checkCoverage
.
For example:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> cover 50 (length xs > 1) "non-trivial" $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests; 135 discarded (26% non-trivial). Only 26% non-trivial, but expected 50%
Reports how many test cases satisfy a given condition.
For example:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> classify (length xs > 1) "non-trivial" $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests (22% non-trivial).
collect :: (Show a, Testable prop) => a -> prop -> Property #
Attaches a label to a test case. This is used for reporting test case distribution.
collect x = label (show x)
For example:
prop_reverse_reverse :: [Int] -> Property prop_reverse_reverse xs = collect (length xs) $ reverse (reverse xs) === xs
>>>
quickCheck prop_reverse_reverse
+++ OK, passed 100 tests: 7% 7 6% 3 5% 4 4% 6 ...
Each use of collect
in your property results in a separate
table of test case distribution in the output. If this is
not what you want, use tabulate
.
label :: Testable prop => String -> prop -> Property #
Attaches a label to a test case. This is used for reporting test case distribution.
For example:
prop_reverse_reverse :: [Int] -> Property prop_reverse_reverse xs = label ("length of input is " ++ show (length xs)) $ reverse (reverse xs) === xs
>>>
quickCheck prop_reverse_reverse
+++ OK, passed 100 tests: 7% length of input is 7 6% length of input is 3 5% length of input is 4 4% length of input is 6 ...
Each use of label
in your property results in a separate
table of test case distribution in the output. If this is
not what you want, use tabulate
.
The standard parameters used by checkCoverage
: certainty = 10^9
,
tolerance = 0.9
. See Confidence
for the meaning of the parameters.
checkCoverageWith :: Testable prop => Confidence -> prop -> Property #
Check coverage requirements using a custom confidence level.
See stdConfidence
.
An example of making the statistical test less stringent in order to improve performance:
quickCheck (checkCoverageWith stdConfidence{certainty = 10^6} prop_foo)
checkCoverage :: Testable prop => prop -> Property #
Check that all coverage requirements defined by cover
and coverTable
are met, using a statistically sound test, and fail if they are not met.
Ordinarily, a failed coverage check does not cause the property to fail.
This is because the coverage requirement is not tested in a statistically
sound way. If you use cover
to express that a certain value must appear 20%
of the time, QuickCheck will warn you if the value only appears in 19 out of
100 test cases - but since the coverage varies randomly, you may have just
been unlucky, and there may not be any real problem with your test
generation.
When you use checkCoverage
, QuickCheck uses a statistical test to account
for the role of luck in coverage failures. It will run as many tests as
needed until it is sure about whether the coverage requirements are met. If a
coverage requirement is not met, the property fails.
Example:
quickCheck (checkCoverage prop_foo)
withMaxSuccess :: Testable prop => Int -> prop -> Property #
Configures how many times a property will be tested.
For example,
quickCheck (withMaxSuccess 1000 p)
will test p
up to 1000 times.
again :: Testable prop => prop -> Property #
Modifies a property so that it will be tested repeatedly.
Opposite of once
.
once :: Testable prop => prop -> Property #
Modifies a property so that it only will be tested once.
Opposite of again
.
expectFailure :: Testable prop => prop -> Property #
Indicates that a property is supposed to fail. QuickCheck will report an error if it does not fail.
verboseShrinking :: Testable prop => prop -> Property #
Prints out the generated testcase every time the property fails, including during shrinking.
Only variables quantified over inside the verboseShrinking
are printed.
verbose :: Testable prop => prop -> Property #
Prints out the generated testcase every time the property is tested.
Only variables quantified over inside the verbose
are printed.
whenFail' :: Testable prop => IO () -> prop -> Property #
Performs an IO
action every time a property fails. Thus,
if shrinking is done, this can be used to keep track of the
failures along the way.
whenFail :: Testable prop => IO () -> prop -> Property #
Performs an IO
action after the last failure of a property.
printTestCase :: Testable prop => String -> prop -> Property #
Adds the given string to the counterexample if the property fails.
counterexample :: Testable prop => String -> prop -> Property #
Adds the given string to the counterexample if the property fails.
noShrinking :: Testable prop => prop -> Property #
Disables shrinking for a property altogether.
Only quantification inside the call to noShrinking
is affected.
:: Testable prop | |
=> (a -> [a]) |
|
-> a | The original argument |
-> (a -> prop) | |
-> Property |
Shrinks the argument to a property if it fails. Shrinking is done automatically for most types. This function is only needed when you want to override the default behavior.
mapSize :: Testable prop => (Int -> Int) -> prop -> Property #
Adjust the test case size for a property, by transforming it with the given function.
idempotentIOProperty :: Testable prop => IO prop -> Property #
Do I/O inside a property.
Warning: during shrinking, the I/O may not always be re-executed.
Instead, the I/O may be executed once and then its result retained.
If this is not acceptable, use ioProperty
instead.
ioProperty :: Testable prop => IO prop -> Property #
Do I/O inside a property.
Warning: any random values generated inside of the argument to ioProperty
will not currently be shrunk. For best results, generate all random values
before calling ioProperty
, or use idempotentIOProperty
if that is safe.
Note: if your property does no quantification, it will only be tested once.
To test it repeatedly, use again
.
The type of properties.
Instances
Testable Property | |
Example Property | |
Defined in Test.Hspec.Core.Example evaluateExample :: Property -> Params -> (ActionWith (Arg Property) -> IO ()) -> ProgressCallback -> IO Result # | |
Example (a -> Property) | |
Defined in Test.Hspec.Core.Example evaluateExample :: (a -> Property) -> Params -> (ActionWith (Arg (a -> Property)) -> IO ()) -> ProgressCallback -> IO Result # | |
type Arg Property | |
Defined in Test.Hspec.Core.Example | |
type Arg (a -> Property) | |
Defined in Test.Hspec.Core.Example |
The class of properties, i.e., types which QuickCheck knows how to test.
Typically a property will be a function returning Bool
or Property
.
If a property does no quantification, i.e. has no
parameters and doesn't use forAll
, it will only be tested once.
This may not be what you want if your property is an IO Bool
.
You can change this behaviour using the again
combinator.
property :: prop -> Property #
Convert the thing to a property.
propertyForAllShrinkShow :: Gen a -> (a -> [a]) -> (a -> [String]) -> (a -> prop) -> Property #
Optional; used internally in order to improve shrinking.
Tests a property but also quantifies over an extra value
(with a custom shrink and show function).
The Testable
instance for functions defines
propertyForAllShrinkShow
in a way that improves shrinking.
Instances
Testable Bool | |
Testable () | |
Defined in Test.QuickCheck.Property | |
Testable Prop | |
Defined in Test.QuickCheck.Property | |
Testable Result | |
Defined in Test.QuickCheck.Property | |
Testable Property | |
Testable Discard | |
Testable prop => Testable (Maybe prop) | |
Testable prop => Testable (Gen prop) | |
(Arbitrary a, Show a, Testable prop) => Testable (a -> prop) | |
Defined in Test.QuickCheck.Property |
data Confidence #
The statistical parameters used by checkCoverage
.
Confidence | |
|
Instances
Show Confidence | |
Defined in Test.QuickCheck.State showsPrec :: Int -> Confidence -> ShowS # show :: Confidence -> String # showList :: [Confidence] -> ShowS # |
applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d #
Extracts the value of a ternary function. Fn3
is the
pattern equivalent of this function.
applyFun2 :: Fun (a, b) c -> a -> b -> c #
Extracts the value of a binary function.
Fn2
is the pattern equivalent of this function.
prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool prop_zipWith f xs ys = zipWith (applyFun2 f) xs ys == [ applyFun2 f x y | (x, y) <- zip xs ys]
applyFun :: Fun a b -> a -> b #
Extracts the value of a function.
Fn
is the pattern equivalent of this function.
prop :: Fun String Integer -> Bool prop f = applyFun f "banana" == applyFun f "monkey" || applyFun f "banana" == applyFun f "elephant"
functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c #
functionVoid :: (forall b. void -> b) -> void :-> c #
functionShow :: (Show a, Read a) => (a -> c) -> a :-> c #
functionIntegral :: Integral a => (a -> b) -> a :-> b #
functionRealFrac :: RealFrac a => (a -> b) -> a :-> b #
pattern Fn :: forall a b. (a -> b) -> Fun a b #
A modifier for testing functions.
prop :: Fun String Integer -> Bool prop (Fn f) = f "banana" == f "monkey" || f "banana" == f "elephant"
pattern Fn2 :: forall a b c. (a -> b -> c) -> Fun (a, b) c #
A modifier for testing binary functions.
prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool prop_zipWith (Fn2 f) xs ys = zipWith f xs ys == [ f x y | (x, y) <- zip xs ys]
pattern Fn3 :: forall a b c d. (a -> b -> c -> d) -> Fun (a, b, c) d #
A modifier for testing ternary functions.
The type of possibly partial concrete functions
The class Function a
is used for random generation of showable
functions of type a -> b
.
There is a default implementation for function
, which you can use
if your type has structural equality. Otherwise, you can normally
use functionMap
or functionShow
.
Nothing
Instances
Generation of random shrinkable, showable functions.
To generate random values of type
,
you must have an instance Fun
a b
.Function
a
Blind x
: as x, but x does not have to be in the Show
class.
Instances
Functor Blind | |
Enum a => Enum (Blind a) | |
Eq a => Eq (Blind a) | |
Integral a => Integral (Blind a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Blind a) | |
Ord a => Ord (Blind a) | |
Real a => Real (Blind a) | |
Defined in Test.QuickCheck.Modifiers toRational :: Blind a -> Rational # | |
Show (Blind a) | |
Arbitrary a => Arbitrary (Blind a) | |
Fixed x
: as x, but will not be shrunk.
Instances
Functor Fixed | |
Enum a => Enum (Fixed a) | |
Eq a => Eq (Fixed a) | |
Integral a => Integral (Fixed a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Fixed a) | |
Ord a => Ord (Fixed a) | |
Read a => Read (Fixed a) | |
Real a => Real (Fixed a) | |
Defined in Test.QuickCheck.Modifiers toRational :: Fixed a -> Rational # | |
Show a => Show (Fixed a) | |
Arbitrary a => Arbitrary (Fixed a) | |
newtype OrderedList a #
Ordered xs
: guarantees that xs is ordered.
Ordered | |
|
Instances
newtype NonEmptyList a #
NonEmpty xs
: guarantees that xs is non-empty.
NonEmpty | |
|
Instances
data InfiniteList a #
InfiniteList xs _
: guarantees that xs is an infinite list.
When a counterexample is found, only prints the prefix of xs
that was used by the program.
Here is a contrived example property:
prop_take_10 :: InfiniteList Char -> Bool prop_take_10 (InfiniteList xs _) = or [ x == 'a' | x <- take 10 xs ]
In the following counterexample, the list must start with "bbbbbbbbbb"
but
the remaining (infinite) part can contain anything:
>>>
quickCheck prop_take_10
*** Failed! Falsified (after 1 test and 14 shrinks): "bbbbbbbbbb" ++ ...
InfiniteList | |
|
Instances
Show a => Show (InfiniteList a) | |
Defined in Test.QuickCheck.Modifiers showsPrec :: Int -> InfiniteList a -> ShowS # show :: InfiniteList a -> String # showList :: [InfiniteList a] -> ShowS # | |
Arbitrary a => Arbitrary (InfiniteList a) | |
Defined in Test.QuickCheck.Modifiers arbitrary :: Gen (InfiniteList a) # shrink :: InfiniteList a -> [InfiniteList a] # |
newtype SortedList a #
Sorted xs
: guarantees that xs is sorted.
Instances
Positive x
: guarantees that x > 0
.
Positive | |
|
Instances
Functor Positive | |
Enum a => Enum (Positive a) | |
Defined in Test.QuickCheck.Modifiers succ :: Positive a -> Positive a # pred :: Positive a -> Positive a # fromEnum :: Positive a -> Int # enumFrom :: Positive a -> [Positive a] # enumFromThen :: Positive a -> Positive a -> [Positive a] # enumFromTo :: Positive a -> Positive a -> [Positive a] # enumFromThenTo :: Positive a -> Positive a -> Positive a -> [Positive a] # | |
Eq a => Eq (Positive a) | |
Ord a => Ord (Positive a) | |
Read a => Read (Positive a) | |
Show a => Show (Positive a) | |
(Num a, Ord a, Arbitrary a) => Arbitrary (Positive a) | |
Negative x
: guarantees that x < 0
.
Negative | |
|
Instances
Functor Negative | |
Enum a => Enum (Negative a) | |
Defined in Test.QuickCheck.Modifiers succ :: Negative a -> Negative a # pred :: Negative a -> Negative a # fromEnum :: Negative a -> Int # enumFrom :: Negative a -> [Negative a] # enumFromThen :: Negative a -> Negative a -> [Negative a] # enumFromTo :: Negative a -> Negative a -> [Negative a] # enumFromThenTo :: Negative a -> Negative a -> Negative a -> [Negative a] # | |
Eq a => Eq (Negative a) | |
Ord a => Ord (Negative a) | |
Read a => Read (Negative a) | |
Show a => Show (Negative a) | |
(Num a, Ord a, Arbitrary a) => Arbitrary (Negative a) | |
NonZero x
: guarantees that x /= 0
.
NonZero | |
|
Instances
Functor NonZero | |
Enum a => Enum (NonZero a) | |
Defined in Test.QuickCheck.Modifiers succ :: NonZero a -> NonZero a # pred :: NonZero a -> NonZero a # fromEnum :: NonZero a -> Int # enumFrom :: NonZero a -> [NonZero a] # enumFromThen :: NonZero a -> NonZero a -> [NonZero a] # enumFromTo :: NonZero a -> NonZero a -> [NonZero a] # enumFromThenTo :: NonZero a -> NonZero a -> NonZero a -> [NonZero a] # | |
Eq a => Eq (NonZero a) | |
Ord a => Ord (NonZero a) | |
Defined in Test.QuickCheck.Modifiers | |
Read a => Read (NonZero a) | |
Show a => Show (NonZero a) | |
(Num a, Eq a, Arbitrary a) => Arbitrary (NonZero a) | |
newtype NonNegative a #
NonNegative x
: guarantees that x >= 0
.
Instances
newtype NonPositive a #
NonPositive x
: guarantees that x <= 0
.
Instances
Large x
: by default, QuickCheck generates Int
s drawn from a small
range. Large Int
gives you values drawn from the entire range instead.
Instances
Functor Large | |
Enum a => Enum (Large a) | |
Eq a => Eq (Large a) | |
Integral a => Integral (Large a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Large a) | |
Ord a => Ord (Large a) | |
Read a => Read (Large a) | |
Real a => Real (Large a) | |
Defined in Test.QuickCheck.Modifiers toRational :: Large a -> Rational # | |
Show a => Show (Large a) | |
Ix a => Ix (Large a) | |
Defined in Test.QuickCheck.Modifiers | |
(Integral a, Bounded a) => Arbitrary (Large a) | |
Small x
: generates values of x
drawn from a small range.
The opposite of Large
.
Instances
Functor Small | |
Enum a => Enum (Small a) | |
Eq a => Eq (Small a) | |
Integral a => Integral (Small a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Small a) | |
Ord a => Ord (Small a) | |
Read a => Read (Small a) | |
Real a => Real (Small a) | |
Defined in Test.QuickCheck.Modifiers toRational :: Small a -> Rational # | |
Show a => Show (Small a) | |
Ix a => Ix (Small a) | |
Defined in Test.QuickCheck.Modifiers | |
Integral a => Arbitrary (Small a) | |
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Shrink2 | |
|
Instances
Functor Shrink2 | |
Enum a => Enum (Shrink2 a) | |
Defined in Test.QuickCheck.Modifiers succ :: Shrink2 a -> Shrink2 a # pred :: Shrink2 a -> Shrink2 a # fromEnum :: Shrink2 a -> Int # enumFrom :: Shrink2 a -> [Shrink2 a] # enumFromThen :: Shrink2 a -> Shrink2 a -> [Shrink2 a] # enumFromTo :: Shrink2 a -> Shrink2 a -> [Shrink2 a] # enumFromThenTo :: Shrink2 a -> Shrink2 a -> Shrink2 a -> [Shrink2 a] # | |
Eq a => Eq (Shrink2 a) | |
Integral a => Integral (Shrink2 a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Shrink2 a) | |
Defined in Test.QuickCheck.Modifiers | |
Ord a => Ord (Shrink2 a) | |
Defined in Test.QuickCheck.Modifiers | |
Read a => Read (Shrink2 a) | |
Real a => Real (Shrink2 a) | |
Defined in Test.QuickCheck.Modifiers toRational :: Shrink2 a -> Rational # | |
Show a => Show (Shrink2 a) | |
Arbitrary a => Arbitrary (Shrink2 a) | |
Smart _ x
: tries a different order when shrinking.
Shrinking _ x
: allows for maintaining a state during shrinking.
Shrinking s a |
class ShrinkState s a where #
shrinkInit :: a -> s #
shrinkState :: a -> s -> [(a, s)] #
newtype ASCIIString #
ASCIIString
: generates an ASCII string.
Instances
newtype UnicodeString #
UnicodeString
: generates a unicode String.
The string will not contain surrogate pairs.
Instances
newtype PrintableString #
PrintableString
: generates a printable unicode String.
The string will not contain surrogate pairs.
Instances
Eq PrintableString | |
Defined in Test.QuickCheck.Modifiers (==) :: PrintableString -> PrintableString -> Bool # (/=) :: PrintableString -> PrintableString -> Bool # | |
Ord PrintableString | |
Defined in Test.QuickCheck.Modifiers compare :: PrintableString -> PrintableString -> Ordering # (<) :: PrintableString -> PrintableString -> Bool # (<=) :: PrintableString -> PrintableString -> Bool # (>) :: PrintableString -> PrintableString -> Bool # (>=) :: PrintableString -> PrintableString -> Bool # max :: PrintableString -> PrintableString -> PrintableString # min :: PrintableString -> PrintableString -> PrintableString # | |
Read PrintableString | |
Defined in Test.QuickCheck.Modifiers | |
Show PrintableString | |
Defined in Test.QuickCheck.Modifiers showsPrec :: Int -> PrintableString -> ShowS # show :: PrintableString -> String # showList :: [PrintableString] -> ShowS # | |
Arbitrary PrintableString | |
Defined in Test.QuickCheck.Modifiers arbitrary :: Gen PrintableString # shrink :: PrintableString -> [PrintableString] # |
infiniteList :: Arbitrary a => Gen [a] #
Generates an infinite list.
orderedList :: (Ord a, Arbitrary a) => Gen [a] #
Generates an ordered list.
coarbitraryEnum :: Enum a => a -> Gen b -> Gen b #
A coarbitrary
implementation for enums.
coarbitraryShow :: Show a => a -> Gen b -> Gen b #
coarbitrary
helper for lazy people :-).
coarbitraryReal :: Real a => a -> Gen b -> Gen b #
A coarbitrary
implementation for real numbers.
coarbitraryIntegral :: Integral a => a -> Gen b -> Gen b #
A coarbitrary
implementation for integral numbers.
(><) :: (Gen a -> Gen a) -> (Gen a -> Gen a) -> Gen a -> Gen a #
Combine two generator perturbing functions, for example the
results of calls to variant
or coarbitrary
.
genericCoarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b #
Generic CoArbitrary implementation.
shrinkDecimal :: RealFrac a => a -> [a] #
Shrink a real number, preferring numbers with shorter
decimal representations. See also shrinkRealFrac
.
shrinkRealFrac :: RealFrac a => a -> [a] #
Shrink a fraction, preferring numbers with smaller
numerators or denominators. See also shrinkDecimal
.
shrinkIntegral :: Integral a => a -> [a] #
Shrink an integral number.
shrinkMapBy :: (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b] #
Non-overloaded version of shrinkMap
.
shrinkMap :: Arbitrary a => (a -> b) -> (b -> a) -> b -> [b] #
Map a shrink function to another domain. This is handy if your data type has special invariants, but is almost isomorphic to some other type.
shrinkOrderedList :: (Ord a, Arbitrary a) => [a] -> [[a]] shrinkOrderedList = shrinkMap sort id shrinkSet :: (Ord a, Arbitrary a) => Set a -> Set [a] shrinkSet = shrinkMap fromList toList
shrinkNothing :: a -> [a] #
Returns no shrinking alternatives.
arbitraryPrintableChar :: Gen Char #
Generates a printable Unicode character.
arbitraryASCIIChar :: Gen Char #
Generates a random ASCII character (0-127).
arbitraryUnicodeChar :: Gen Char #
Generates any Unicode character (but not a surrogate)
arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a #
Generates an integral number from a bounded domain. The number is chosen from the entire range of the type, but small numbers are generated more often than big numbers. Inspired by demands from Phil Wadler.
arbitraryBoundedEnum :: (Bounded a, Enum a) => Gen a #
Generates an element of a bounded enumeration.
arbitraryBoundedRandom :: (Bounded a, Random a) => Gen a #
Generates an element of a bounded type. The element is chosen from the entire range of the type.
arbitraryBoundedIntegral :: (Bounded a, Integral a) => Gen a #
Generates an integral number. The number is chosen uniformly from
the entire range of the type. You may want to use
arbitrarySizedBoundedIntegral
instead.
arbitrarySizedFractional :: Fractional a => Gen a #
Generates a fractional number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
arbitrarySizedNatural :: Integral a => Gen a #
Generates a natural number. The number's maximum value depends on the size parameter.
arbitrarySizedIntegral :: Integral a => Gen a #
Generates an integral number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
applyArbitrary4 :: (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => (a -> b -> c -> d -> r) -> Gen r #
Apply a function of arity 4 to random arguments.
applyArbitrary3 :: (Arbitrary a, Arbitrary b, Arbitrary c) => (a -> b -> c -> r) -> Gen r #
Apply a ternary function to random arguments.
applyArbitrary2 :: (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r #
Apply a binary function to random arguments.
shrinkList :: (a -> [a]) -> [a] -> [[a]] #
Shrink a list of values given a shrinking function for individual values.
recursivelyShrink :: (Generic a, RecursivelyShrink (Rep a)) => a -> [a] #
Recursively shrink all immediate subterms.
genericShrink :: (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] #
Shrink a term to any of its immediate subterms, and also recursively shrink all subterms.
shrink2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => f a b -> [f a b] #
arbitrary2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => Gen (f a b) #
shrink1 :: (Arbitrary1 f, Arbitrary a) => f a -> [f a] #
arbitrary1 :: (Arbitrary1 f, Arbitrary a) => Gen (f a) #
Random generation and shrinking of values.
QuickCheck provides Arbitrary
instances for most types in base
,
except those which incur extra dependencies.
For a wider range of Arbitrary
instances see the
quickcheck-instances
package.
A generator for values of the given type.
It is worth spending time thinking about what sort of test data
you want - good generators are often the difference between
finding bugs and not finding them. You can use sample
,
label
and classify
to check the quality of your test data.
There is no generic arbitrary
implementation included because we don't
know how to make a high-quality one. If you want one, consider using the
testing-feat or
generic-random packages.
The QuickCheck manual goes into detail on how to write good generators. Make sure to look at it, especially if your type is recursive!
Produces a (possibly) empty list of all the possible immediate shrinks of the given value.
The default implementation returns the empty list, so will not try to
shrink the value. If your data type has no special invariants, you can
enable shrinking by defining shrink =
, but by customising
the behaviour of genericShrink
shrink
you can often get simpler counterexamples.
Most implementations of shrink
should try at least three things:
- Shrink a term to any of its immediate subterms.
You can use
subterms
to do this. - Recursively apply
shrink
to all immediate subterms. You can userecursivelyShrink
to do this. - Type-specific shrinkings such as replacing a constructor by a simpler constructor.
For example, suppose we have the following implementation of binary trees:
data Tree a = Nil | Branch a (Tree a) (Tree a)
We can then define shrink
as follows:
shrink Nil = [] shrink (Branch x l r) = -- shrink Branch to Nil [Nil] ++ -- shrink to subterms [l, r] ++ -- recursively shrink subterms [Branch x' l' r' | (x', l', r') <- shrink (x, l, r)]
There are a couple of subtleties here:
- QuickCheck tries the shrinking candidates in the order they
appear in the list, so we put more aggressive shrinking steps
(such as replacing the whole tree by
Nil
) before smaller ones (such as recursively shrinking the subtrees). - It is tempting to write the last line as
[Branch x' l' r' | x' <- shrink x, l' <- shrink l, r' <- shrink r]
but this is the wrong thing! It will force QuickCheck to shrinkx
,l
andr
in tandem, and shrinking will stop once one of the three is fully shrunk.
There is a fair bit of boilerplate in the code above.
We can avoid it with the help of some generic functions.
The function genericShrink
tries shrinking a term to all of its
subterms and, failing that, recursively shrinks the subterms.
Using it, we can define shrink
as:
shrink x = shrinkToNil x ++ genericShrink x where shrinkToNil Nil = [] shrinkToNil (Branch _ l r) = [Nil]
genericShrink
is a combination of subterms
, which shrinks
a term to any of its subterms, and recursivelyShrink
, which shrinks
all subterms of a term. These may be useful if you need a bit more
control over shrinking than genericShrink
gives you.
A final gotcha: we cannot define shrink
as simply
as this shrinks shrink
x = Nil:genericShrink
xNil
to Nil
, and shrinking will go into an
infinite loop.
If all this leaves you bewildered, you might try
to begin with,
after deriving shrink
= genericShrink
Generic
for your type. However, if your data type has any
special invariants, you will need to check that genericShrink
can't break those invariants.
Instances
class Arbitrary1 (f :: Type -> Type) where #
Lifting of the Arbitrary
class to unary type constructors.
liftArbitrary :: Gen a -> Gen (f a) #
liftShrink :: (a -> [a]) -> f a -> [f a] #
Instances
class Arbitrary2 (f :: Type -> Type -> Type) where #
Lifting of the Arbitrary
class to binary type constructors.
liftArbitrary2 :: Gen a -> Gen b -> Gen (f a b) #
liftShrink2 :: (a -> [a]) -> (b -> [b]) -> f a b -> [f a b] #
Instances
Arbitrary2 Either | |
Defined in Test.QuickCheck.Arbitrary liftArbitrary2 :: Gen a -> Gen b -> Gen (Either a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Either a b -> [Either a b] # | |
Arbitrary2 (,) | |
Defined in Test.QuickCheck.Arbitrary liftArbitrary2 :: Gen a -> Gen b -> Gen (a, b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)] # | |
Arbitrary2 (Const :: Type -> Type -> Type) | |
Defined in Test.QuickCheck.Arbitrary liftArbitrary2 :: Gen a -> Gen b -> Gen (Const a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Const a b -> [Const a b] # | |
Arbitrary2 (Constant :: Type -> Type -> Type) | |
Defined in Test.QuickCheck.Arbitrary liftArbitrary2 :: Gen a -> Gen b -> Gen (Constant a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Constant a b -> [Constant a b] # |
class CoArbitrary a where #
Used for random generation of functions.
You should consider using Fun
instead, which
can show the generated functions as strings.
If you are using a recent GHC, there is a default definition of
coarbitrary
using genericCoarbitrary
, so if your type has a
Generic
instance it's enough to say
instance CoArbitrary MyType
You should only use genericCoarbitrary
for data types where
equality is structural, i.e. if you can't have two different
representations of the same value. An example where it's not
safe is sets implemented using binary search trees: the same
set can be represented as several different trees.
Here you would have to explicitly define
coarbitrary s = coarbitrary (toList s)
.
Nothing
coarbitrary :: a -> Gen b -> Gen b #
Used to generate a function of type a -> b
.
The first argument is a value, the second a generator.
You should use variant
to perturb the random generator;
the goal is that different values for the first argument will
lead to different calls to variant
. An example will help:
instance CoArbitrary a => CoArbitrary [a] where coarbitrary [] =variant
0 coarbitrary (x:xs) =variant
1 . coarbitrary (x,xs)
Instances
infiniteListOf :: Gen a -> Gen [a] #
Generates an infinite list.
Generates a non-empty list of random length. The maximum length depends on the size parameter.
Generates a list of random length. The maximum length depends on the size parameter.
growingElements :: [a] -> Gen a #
Takes a list of elements of increasing size, and chooses among an initial segment of the list. The size of this initial segment increases with the size parameter. The input list must be non-empty.
frequency :: [(Int, Gen a)] -> Gen a #
Chooses one of the given generators, with a weighted random distribution. The input list must be non-empty.
Randomly uses one of the given generators. The input list must be non-empty.
suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a) #
Tries to generate a value that satisfies a predicate.
If it fails to do so after enough attempts, returns Nothing
.
suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b #
Generates a value for which the given function returns a Just
, and then
applies the function.
Run a generator. The size passed to the generator is always 30;
if you want another size then you should explicitly use resize
.
scale :: (Int -> Int) -> Gen a -> Gen a #
Adjust the size parameter, by transforming it with the given function.
resize :: Int -> Gen a -> Gen a #
Overrides the size parameter. Returns a generator which uses the given size instead of the runtime-size parameter.
Returns the size parameter. Used to construct generators that depend on the size parameter.
For example, listOf
, which uses the size parameter as an upper bound on
length of lists it generates, can be defined like this:
listOf :: Gen a -> Gen [a] listOf gen = do n <- getSize k <- choose (0,n) vectorOf k gen
You can also do this using sized
.
sized :: (Int -> Gen a) -> Gen a #
Used to construct generators that depend on the size parameter.
For example, listOf
, which uses the size parameter as an upper bound on
length of lists it generates, can be defined like this:
listOf :: Gen a -> Gen [a] listOf gen = sized $ \n -> do k <- choose (0,n) vectorOf k gen
You can also do this using getSize
.
A generator for values of type a
.
The third-party packages
QuickCheck-GenT
and
quickcheck-transformer
provide monad transformer versions of Gen
.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
replicateM_ :: Applicative m => Int -> m a -> m () #
Like replicateM
, but discards the result.
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM
n actn
times,
gathering the results.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM
, but discards the result.
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
The foldM
function is analogous to foldl
, except that its result is
encapsulated in a monad. Note that foldM
works from left-to-right over
the list arguments. This could be an issue where (
and the `folded
function' are not commutative.>>
)
foldM f a1 [x1, x2, ..., xm] == do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm
If right-to-left evaluation is required, the input list should be reversed.
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
The mapAndUnzipM
function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a state-transforming monad.
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, and channels
(e.g. MVar
and
Chan
).
For example, here is how we might implement an echo
server, using
forever
both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever
$ do client <- accept socketforkFinally
(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever
$ hGetLine client >>= hPutStrLn client
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter
function.
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
fixST :: (a -> ST s a) -> ST s a #
Allow the result of a state transformer computation to be used (lazily) inside the computation.
Note that if f
is strict,
.fixST
f = _|_
rnfTypeRep :: TypeRep -> () #
Force a TypeRep
to normal form.
typeRepFingerprint :: TypeRep -> Fingerprint #
Takes a value of type a
and returns a concrete representation
of that type.
Since: base-4.7.0.0
typeRepTyCon :: TypeRep -> TyCon #
Observe the type constructor of a quantified type representation.
typeRepArgs :: TypeRep -> [TypeRep] #
Observe the argument types of a type representation
splitTyConApp :: TypeRep -> (TyCon, [TypeRep]) #
Splits a type constructor application. Note that if the type constructor is polymorphic, this will not return the kinds that were used.
funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep #
Applies a type to a function type. Returns: Just u
if the first argument
represents a function of type t -> u
and the second argument represents a
function of type t
. Otherwise, returns Nothing
.
gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b) #
A flexible variation parameterised in a type constructor
eqT :: (Typeable a, Typeable b) => Maybe (a :~: b) #
Extract a witness of equality of two types
Since: base-4.7.0.0
showsTypeRep :: TypeRep -> ShowS #
Show a type representation
typeRep :: Typeable a => proxy a -> TypeRep #
Takes a value of type a
and returns a concrete representation
of that type.
Since: base-4.7.0.0
type TypeRep = SomeTypeRep #
A quantified type representation.
tyConFingerprint :: TyCon -> Fingerprint #
tyConModule :: TyCon -> String #
tyConPackage :: TyCon -> String #
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence
.
As of base 4.8.0.0, sequence_
is just sequenceA_
, specialized
to Monad
.
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
data (a :: k) :~: (b :: k) :: forall k. k -> k -> Type where infix 4 #
Propositional equality. If a :~: b
is inhabited by some terminating
value, then the type a
is the same as the type b
. To use this equality
in practice, pattern-match on the a :~: b
to get out the Refl
constructor;
in the body of the pattern-match, the compiler knows that a ~ b
.
Since: base-4.7.0.0
Instances
TestEquality ((:~:) a :: k -> Type) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
NFData2 ((:~:) :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~:) a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
a ~ b => Bounded (a :~: b) | Since: base-4.7.0.0 |
a ~ b => Enum (a :~: b) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
Eq (a :~: b) | Since: base-4.7.0.0 |
Ord (a :~: b) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
a ~ b => Read (a :~: b) | Since: base-4.7.0.0 |
Show (a :~: b) | Since: base-4.7.0.0 |
NFData (a :~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq |
data (a :: k1) :~~: (b :: k2) :: forall k1 k2. k1 -> k2 -> Type where infix 4 #
Kind heterogeneous propositional equality. Like :~:
, a :~~: b
is
inhabited by a terminating value if and only if a
is the same type as b
.
Since: base-4.10.0.0
Instances
TestEquality ((:~~:) a :: k -> Type) | Since: base-4.10.0.0 |
Defined in Data.Type.Equality | |
NFData2 ((:~~:) :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~~:) a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
a ~~ b => Bounded (a :~~: b) | Since: base-4.10.0.0 |
a ~~ b => Enum (a :~~: b) | Since: base-4.10.0.0 |
Defined in Data.Type.Equality succ :: (a :~~: b) -> a :~~: b # pred :: (a :~~: b) -> a :~~: b # fromEnum :: (a :~~: b) -> Int # enumFrom :: (a :~~: b) -> [a :~~: b] # enumFromThen :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromTo :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromThenTo :: (a :~~: b) -> (a :~~: b) -> (a :~~: b) -> [a :~~: b] # | |
Eq (a :~~: b) | Since: base-4.10.0.0 |
Ord (a :~~: b) | Since: base-4.10.0.0 |
a ~~ b => Read (a :~~: b) | Since: base-4.10.0.0 |
Show (a :~~: b) | Since: base-4.10.0.0 |
NFData (a :~~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq |
runST :: (forall s. ST s a) -> a #
Return the value computed by a state transformer computation.
The forall
ensures that the internal state used by the ST
computation is inaccessible to the rest of the program.
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit,
resulting in an Either
Int
Int
:Either
Int
'()'
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
fromMaybe :: a -> Maybe a -> a #
The fromMaybe
function takes a default value and and Maybe
value. If the Maybe
is Nothing
, it returns the default values;
otherwise, it returns the value contained in the Maybe
.
Examples
Basic usage:
>>>
fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>>
fromMaybe "" Nothing
""
Read an integer from a string using readMaybe
. If we fail to
parse an integer, we want to return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
fromMaybe 0 (readMaybe "5")
5>>>
fromMaybe 0 (readMaybe "")
0
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Nothing
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
deepseq :: NFData a => a -> b -> b #
deepseq
: fully evaluates the first argument, before returning the
second.
The name deepseq
is used to illustrate the relationship to seq
:
where seq
is shallow in the sense that it only evaluates the top
level of its argument, deepseq
traverses the entire data structure
evaluating it completely.
deepseq
can be useful for forcing pending exceptions,
eradicating space leaks, or forcing lazy I/O to happen. It is
also useful in conjunction with parallel Strategies (see the
parallel
package).
There is no guarantee about the ordering of evaluation. The
implementation may evaluate the components of the structure in
any order or in parallel. To impose an actual order on
evaluation, use pseq
from Control.Parallel in the
parallel
package.
Since: deepseq-1.1.0.0
A class of types that can be fully evaluated.
Since: deepseq-1.1.0.0
Instances
NFData Bool | |
Defined in Control.DeepSeq | |
NFData Char | |
Defined in Control.DeepSeq | |
NFData Double | |
Defined in Control.DeepSeq | |
NFData Float | |
Defined in Control.DeepSeq | |
NFData Int | |
Defined in Control.DeepSeq | |
NFData Int8 | |
Defined in Control.DeepSeq | |
NFData Int16 | |
Defined in Control.DeepSeq | |
NFData Int32 | |
Defined in Control.DeepSeq | |
NFData Int64 | |
Defined in Control.DeepSeq | |
NFData Integer | |
Defined in Control.DeepSeq | |
NFData Natural | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Ordering | |
Defined in Control.DeepSeq | |
NFData Word | |
Defined in Control.DeepSeq | |
NFData Word8 | |
Defined in Control.DeepSeq | |
NFData Word16 | |
Defined in Control.DeepSeq | |
NFData Word32 | |
Defined in Control.DeepSeq | |
NFData Word64 | |
Defined in Control.DeepSeq | |
NFData CallStack | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData () | |
Defined in Control.DeepSeq | |
NFData TyCon | NOTE: Prior to Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Version | Since: deepseq-1.3.0.0 |
Defined in Control.DeepSeq | |
NFData ThreadId | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Void | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Unique | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData ExitCode | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData MaskingState | Since: deepseq-1.4.4.0 |
Defined in Control.DeepSeq rnf :: MaskingState -> () # | |
NFData TypeRep | NOTE: Prior to Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData All | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Any | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CChar | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CSChar | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUChar | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CShort | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUShort | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CInt | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUInt | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CLong | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CULong | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CLLong | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CULLong | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CBool | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData CFloat | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CDouble | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CPtrdiff | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CSize | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CWchar | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CSigAtomic | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq rnf :: CSigAtomic -> () # | |
NFData CClock | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CTime | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUSeconds | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CSUSeconds | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq rnf :: CSUSeconds -> () # | |
NFData CFile | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CFpos | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CJmpBuf | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CIntPtr | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUIntPtr | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CIntMax | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData CUIntMax | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData Fingerprint | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq rnf :: Fingerprint -> () # | |
NFData SrcLoc | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData IntSet | |
Defined in Data.IntSet.Internal | |
NFData FailureReason | |
Defined in Test.Hspec.Core.Example rnf :: FailureReason -> () # | |
NFData Ix2 | |
Defined in Data.Massiv.Core.Index.Ix | |
NFData Ix0 | |
Defined in Data.Massiv.Core.Index.Internal | |
NFData Comp | |
Defined in Control.Scheduler.Computation | |
NFData Doc | |
Defined in Text.PrettyPrint.HughesPJ | |
NFData TextDetails | |
Defined in Text.PrettyPrint.Annotated.HughesPJ rnf :: TextDetails -> () # | |
NFData ZonedTime | |
Defined in Data.Time.LocalTime.Internal.ZonedTime | |
NFData LocalTime | |
Defined in Data.Time.LocalTime.Internal.LocalTime | |
NFData UniversalTime | |
Defined in Data.Time.Clock.Internal.UniversalTime rnf :: UniversalTime -> () # | |
NFData UTCTime | |
Defined in Data.Time.Clock.Internal.UTCTime | |
NFData Day | |
Defined in Data.Time.Calendar.Days | |
NFData a => NFData [a] | |
Defined in Control.DeepSeq | |
NFData a => NFData (Maybe a) | |
Defined in Control.DeepSeq | |
NFData a => NFData (Ratio a) | |
Defined in Control.DeepSeq | |
NFData (Ptr a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData (FunPtr a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData (IORef a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Complex a) | |
Defined in Control.DeepSeq | |
NFData (Fixed a) | Since: deepseq-1.3.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Min a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Max a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (First a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Last a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData m => NFData (WrappedMonoid m) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq rnf :: WrappedMonoid m -> () # | |
NFData a => NFData (Option a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData (StableName a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq rnf :: StableName a -> () # | |
NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Identity a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (First a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Last a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Dual a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Sum a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Product a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (Down a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (NonEmpty a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData a => NFData (IntMap a) | |
Defined in Data.IntMap.Internal | |
NFData a => NFData (Tree a) | |
NFData a => NFData (Seq a) | |
Defined in Data.Sequence.Internal | |
NFData a => NFData (FingerTree a) | |
Defined in Data.Sequence.Internal rnf :: FingerTree a -> () # | |
NFData a => NFData (Digit a) | |
Defined in Data.Sequence.Internal | |
NFData a => NFData (Node a) | |
Defined in Data.Sequence.Internal | |
NFData a => NFData (Elem a) | |
Defined in Data.Sequence.Internal | |
NFData a => NFData (Set a) | |
Defined in Data.Set.Internal | |
NFData a => NFData (Hashed a) | |
Defined in Data.Hashable.Class | |
NFData (Vector a) | |
Defined in Data.Vector.Unboxed.Base | |
NFData (Vector a) | |
Defined in Data.Vector.Storable | |
NFData a => NFData (Vector a) | |
Defined in Data.Vector | |
NFData e => NFData (Border e) | |
Defined in Data.Massiv.Core.Index | |
NFData (IxN n) | |
Defined in Data.Massiv.Core.Index.Ix | |
NFData ix => NFData (Stride ix) | |
Defined in Data.Massiv.Core.Index.Stride | |
NFData ix => NFData (Sz ix) | |
Defined in Data.Massiv.Core.Index.Internal | |
NFData a => NFData (Doc a) | |
Defined in Text.PrettyPrint.Annotated.HughesPJ | |
NFData a => NFData (AnnotDetails a) | |
Defined in Text.PrettyPrint.Annotated.HughesPJ rnf :: AnnotDetails a -> () # | |
NFData (Vector a) | |
Defined in Data.Vector.Primitive | |
NFData (a -> b) | This instance is for convenience and consistency with Since: deepseq-1.3.0.0 |
Defined in Control.DeepSeq | |
(NFData a, NFData b) => NFData (Either a b) | |
Defined in Control.DeepSeq | |
(NFData a, NFData b) => NFData (a, b) | |
Defined in Control.DeepSeq | |
(NFData a, NFData b) => NFData (Array a b) | |
Defined in Control.DeepSeq | |
(NFData a, NFData b) => NFData (Arg a b) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData (STRef s a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
(NFData k, NFData a) => NFData (Map k a) | |
Defined in Data.Map.Internal | |
NFData (MVector s a) | |
Defined in Data.Vector.Unboxed.Base | |
NFData (MVector s a) | |
Defined in Data.Vector.Storable.Mutable | |
NFData (MVector s a) | |
Defined in Data.Vector.Primitive.Mutable | |
(NFData a1, NFData a2, NFData a3) => NFData (a1, a2, a3) | |
Defined in Control.DeepSeq | |
NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
NFData (a :~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Index ix => NFData (Stencil ix e a) | |
Defined in Data.Massiv.Array.Stencil.Internal | |
(Index ix, NFData e) => NFData (Array B ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
(Index ix, NFData e) => NFData (Array N ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
NFData ix => NFData (Array S ix e) | |
Defined in Data.Massiv.Array.Manifest.Storable | |
Index ix => NFData (Array P ix e) | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
NFData ix => NFData (Array U ix e) | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
(NFData a1, NFData a2, NFData a3, NFData a4) => NFData (a1, a2, a3, a4) | |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g, NFData a) => NFData (Product f g a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g, NFData a) => NFData (Sum f g a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData (a :~~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData (a1, a2, a3, a4, a5) | |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g, NFData a) => NFData (Compose f g a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData (a1, a2, a3, a4, a5, a6) | |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData (a1, a2, a3, a4, a5, a6, a7) | |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData (a1, a2, a3, a4, a5, a6, a7, a8) | |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8, NFData a9) => NFData (a1, a2, a3, a4, a5, a6, a7, a8, a9) | |
Defined in Control.DeepSeq |
A Selector
is a predicate; it can simultaneously constrain the type and
value of an exception.
type Expectation = Assertion #
expectationFailure :: HasCallStack -> String -> Expectation #
shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldStartWith` prefix
sets the expectation that list
starts with prefix
,
shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldEndWith` suffix
sets the expectation that list
ends with suffix
,
shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldContain` sublist
sets the expectation that sublist
is contained,
wholly and intact, anywhere in list
.
shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
xs `shouldMatchList` ys
sets the expectation that xs
has the same
elements that ys
has, possibly in another order
shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldNotBe` notExpected
sets the expectation that actual
is not
equal to notExpected
shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldNotSatisfy` p
sets the expectation that p v
is False
.
shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldNotContain` sublist
sets the expectation that sublist
is not
contained anywhere in list
.
shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldNotReturn` notExpected
sets the expectation that action
does not return notExpected
.
shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation infix 1 #
action `shouldThrow` selector
sets the expectation that action
throws
an exception. The precise nature of the expected exception is described
with a Selector
.
prop :: (HasCallStack, Testable prop) => String -> prop -> Spec #
prop ".." $ ..
is a shortcut for
it ".." $ property $ ..
example :: Expectation -> Expectation #
example
is a type restricted version of id
. It can be used to get better
error messages on type mismatches.
Compare e.g.
it "exposes some behavior" $ example $ do putStrLn
with
it "exposes some behavior" $ do putStrLn
type ActionWith a = a -> IO () #
An IO
action that expects an argument of type a
A type class for examples
Instances
Run an IO action while constructing the spec tree.
SpecM
is a monad to construct a spec tree, without executing any spec
items. runIO
allows you to run IO actions during this construction phase.
The IO action is always run when the spec tree is constructed (e.g. even
when --dry-run
is specified).
If you do not need the result of the IO action to construct the spec tree,
beforeAll
may be more suitable for your use case.
beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b #
Run a custom action before every spec item.
beforeAll_ :: IO () -> SpecWith a -> SpecWith a #
Run a custom action before the first spec item.
after :: ActionWith a -> SpecWith a -> SpecWith a #
Run a custom action after every spec item.
around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec #
Run a custom action before and/or after every spec item.
afterAll :: ActionWith a -> SpecWith a -> SpecWith a #
Run a custom action after the last spec item.
around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a #
Run a custom action before and/or after every spec item.
aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b #
Run a custom action before and/or after every spec item.
describe :: HasCallStack => String -> SpecWith a -> SpecWith a #
The describe
function combines a list of specs into a larger spec.
it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
The it
function creates a spec item.
A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
describe "absolute" $ do it "returns a positive number when given a negative number" $ absolute (-1) == 1
specify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
specify
is an alias for it
.
xspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
xspecify
is an alias for xit
.
fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fit
is an alias for fmap focus . it
fspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fspecify
is an alias for fit
.
fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a #
fdescribe
is an alias for fmap focus . describe
parallel :: SpecWith a -> SpecWith a #
parallel
marks all spec items of the given spec to be safe for parallel
evaluation.
pending :: HasCallStack -> Expectation #
pending
can be used to mark a spec item as pending.
If you want to textually specify a behavior but do not have an example yet, use this:
describe "fancyFormatter" $ do it "can format text in a way that everyone likes" $ pending
pendingWith :: HasCallStack -> String -> Expectation #
pendingWith
is similar to pending
, but it takes an additional string
argument that can be used to specify the reason for why the spec item is pending.
modifyMaxSuccess :: (Int -> Int) -> SpecWith a -> SpecWith a #
Use a modified maxSuccess
for given spec.
modifyMaxDiscardRatio :: (Int -> Int) -> SpecWith a -> SpecWith a #
Use a modified maxDiscardRatio
for given spec.
modifyMaxShrinks :: (Int -> Int) -> SpecWith a -> SpecWith a #
Use a modified maxShrinks
for given spec.