Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type Selector a = a -> Bool
- type SpecWith a = SpecM a ()
- type Spec = SpecWith ()
- class ImpSpec t where
- type ImpSpecEnv t = (r :: Type) | r -> t
- type ImpSpecState t = (r :: Type) | r -> t
- impInitIO :: QCGen -> IO (ImpInit t)
- impPrepAction :: ImpM t ()
- class StatefulGen g m => HasStatefulGen g m | m -> g where
- askStatefulGen :: m g
- class HasGenEnv env g | env -> g where
- getGenEnv :: env -> g
- data ImpState t = ImpState {
- impStateSpecState :: !(ImpSpecState t)
- impStateLog :: !(Doc AnsiStyle)
- data ImpEnv t = ImpEnv {
- impEnvSpecEnv :: !(ImpSpecEnv t)
- impEnvStateRef :: !(IORef (ImpState t))
- impEnvQCGenRef :: !(IOGenM QCGen)
- impEnvQCSize :: !Int
- data ImpInit t = ImpInit {
- impInitEnv :: ImpSpecEnv t
- impInitState :: ImpSpecState t
- newtype ImpM t a = ImpM {}
- data ImpException = ImpException {}
- assertFailure :: (HasCallStack, MonadIO m) => String -> m a
- assertBool :: (HasCallStack, MonadIO m) => String -> Bool -> m ()
- arbitrary :: (Arbitrary a, MonadGen m) => m a
- describe :: HasCallStack => String -> SpecWith a -> SpecWith a
- xdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- prop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- xprop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- fprop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- expectationFailure :: (HasCallStack, MonadIO m) => String -> m ()
- shouldBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m ()
- shouldSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m ()
- shouldStartWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldEndWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldMatchList :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m ()
- shouldNotBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m ()
- shouldNotSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m ()
- shouldNotContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldNotReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m ()
- shouldThrow :: (HasCallStack, Exception e, MonadUnliftIO m) => m a -> Selector e -> m ()
- uniformM :: (HasStatefulGen g m, Uniform a) => m a
- uniformRM :: (HasStatefulGen g m, UniformRange a) => (a, a) -> m a
- uniformByteStringM :: HasStatefulGen a m => Int -> m ByteString
- uniformListM :: (HasStatefulGen g m, Uniform a) => Int -> m [a]
- assertColorFailure :: (HasCallStack, MonadIO m) => String -> m a
- shouldBeRight :: (HasCallStack, Show a, Show b, Eq b, MonadIO m) => Either a b -> b -> m ()
- shouldBeLeft :: (HasCallStack, Show a, Eq a, Show b, MonadIO m) => Either a b -> a -> m ()
- expectRight :: (HasCallStack, Show a, MonadIO m) => Either a b -> m b
- expectRightDeep :: (HasCallStack, Show a, NFData b, MonadIO m) => Either a b -> m b
- expectRightDeep_ :: (HasCallStack, Show a, NFData b, MonadIO m) => Either a b -> m ()
- expectLeft :: (HasCallStack, Show b, MonadIO m) => Either a b -> m a
- expectLeftDeep :: (HasCallStack, NFData a, Show b, MonadIO m) => Either a b -> m a
- expectLeftDeep_ :: (HasCallStack, NFData a, Show b, MonadIO m) => Either a b -> m ()
- shouldBeJust :: (HasCallStack, Show a, Eq a, MonadIO m) => Maybe a -> a -> m ()
- expectJust :: (HasCallStack, MonadIO m) => Maybe a -> m a
- expectJustDeep :: (HasCallStack, NFData a, MonadIO m) => Maybe a -> m a
- expectJustDeep_ :: (HasCallStack, NFData a, MonadIO m) => Maybe a -> m ()
- expectNothing :: (HasCallStack, Show a, MonadIO m) => Maybe a -> m ()
- io :: IO a -> IO a
- impSpecMain :: Spec -> IO ()
- impSpecConfig :: Config
- impSpecMainWithConfig :: Config -> Spec -> IO ()
- uniformListRM :: (HasStatefulGen g m, UniformRange a) => (a, a) -> Int -> m [a]
- uniformShortByteStringM :: HasStatefulGen a m => Int -> m ShortByteString
- ansiDocToString :: Doc AnsiStyle -> String
- prettyImpException :: ImpException -> Doc AnsiStyle
- applyQCGen :: (QCGen -> (b, QCGen)) -> ImpM t b
- evalImpM :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO b
- getLogs :: ImpM t (Doc AnsiStyle)
- modifyLogs :: (Doc AnsiStyle -> Doc AnsiStyle) -> ImpM t ()
- impSetSeed :: Int -> ImpM t ()
- evalImpGenM :: ImpSpec t => ImpInit t -> ImpM t b -> Gen (IO b)
- runImpGenM :: ImpSpec t => ImpInit t -> ImpM t b -> Gen (IO (b, ImpState t))
- runImpM :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO (b, ImpState t)
- execImpGenM :: ImpSpec t => ImpInit t -> ImpM t b -> Gen (IO (ImpState t))
- execImpM :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO (ImpState t)
- runImpGenM_ :: ImpSpec t => ImpInit t -> ImpM t b -> Gen (IO ())
- runImpM_ :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO ()
- withImpInit :: ImpSpec t => SpecWith (ImpInit t) -> Spec
- modifyImpInit :: (ImpInit t -> ImpInit t) -> SpecWith (ImpInit t) -> SpecWith (ImpInit t)
- impAnn :: NFData a => String -> ImpM t a -> ImpM t a
- impAnnDoc :: NFData a => Doc AnsiStyle -> ImpM t a -> ImpM t a
- logWithCallStack :: CallStack -> Doc AnsiStyle -> ImpM t ()
- logDoc :: HasCallStack => Doc AnsiStyle -> ImpM t ()
- logText :: HasCallStack => Text -> ImpM t ()
- logString :: HasCallStack => String -> ImpM t ()
Documentation
A Selector
is a predicate; it can simultaneously constrain the type and
value of an exception.
class ImpSpec t where Source #
Nothing
type ImpSpecEnv t = (r :: Type) | r -> t Source #
type ImpSpecEnv t = Proxy t
type ImpSpecState t = (r :: Type) | r -> t Source #
type ImpSpecState t = Proxy t
class StatefulGen g m => HasStatefulGen g m | m -> g where Source #
Nothing
askStatefulGen :: m g Source #
default askStatefulGen :: MonadReader g m => m g Source #
Instances
(HasGenEnv env g, StatefulGen g (ReaderT env m), Monad m) => HasStatefulGen g (ReaderT env m) Source # | |
Defined in Test.ImpSpec.Random askStatefulGen :: ReaderT env m g Source # | |
HasStatefulGen (IOGenM QCGen) (ImpM t) Source # | |
Defined in Test.ImpSpec.Internal askStatefulGen :: ImpM t (IOGenM QCGen) Source # |
ImpState | |
|
ImpEnv | |
|
ImpInit | |
|
Instances
(Show (ImpSpecEnv t), Show (ImpSpecState t)) => Show (ImpInit t) Source # | |
(Eq (ImpSpecEnv t), Eq (ImpSpecState t)) => Eq (ImpInit t) Source # | |
(Ord (ImpSpecEnv t), Ord (ImpSpecState t)) => Ord (ImpInit t) Source # | |
Defined in Test.ImpSpec.Internal |
Instances
data ImpException Source #
Stores extra information about the failure of the unit test
ImpException | |
|
Instances
Exception ImpException Source # | |
Defined in Test.ImpSpec.Internal | |
Show ImpException Source # | |
Defined in Test.ImpSpec.Internal showsPrec :: Int -> ImpException -> ShowS # show :: ImpException -> String # showList :: [ImpException] -> ShowS # |
assertFailure :: (HasCallStack, MonadIO m) => String -> m a Source #
Just like expectationFailure
, but does not force the return type to unit. Lifted
version of assertFailure
assertBool :: (HasCallStack, MonadIO m) => String -> Bool -> m () Source #
Lifted version of assertBool
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
fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fit
is an alias for fmap focus . it
fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a #
fdescribe
is an alias for fmap focus . describe
expectationFailure :: (HasCallStack, MonadIO m) => String -> m () #
shouldBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m () infix 1 #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
shouldSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m () infix 1 #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldStartWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldStartWith` prefix
sets the expectation that list
starts with prefix
,
shouldEndWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldEndWith` suffix
sets the expectation that list
ends with suffix
,
shouldContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldContain` sublist
sets the expectation that sublist
is contained,
wholly and intact, anywhere in list
.
shouldMatchList :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
xs `shouldMatchList` ys
sets the expectation that xs
has the same
elements that ys
has, possibly in another order
shouldReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m () infix 1 #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
shouldNotBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m () infix 1 #
actual `shouldNotBe` notExpected
sets the expectation that actual
is not
equal to notExpected
shouldNotSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m () infix 1 #
v `shouldNotSatisfy` p
sets the expectation that p v
is False
.
shouldNotContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldNotContain` sublist
sets the expectation that sublist
is not
contained anywhere in list
.
shouldNotReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m () infix 1 #
action `shouldNotReturn` notExpected
sets the expectation that action
does not return notExpected
.
shouldThrow :: (HasCallStack, Exception e, MonadUnliftIO m) => m a -> Selector e -> m () infix 1 Source #
Lifted version of shouldThrow
.
uniformM :: (HasStatefulGen g m, Uniform a) => m a Source #
uniformRM :: (HasStatefulGen g m, UniformRange a) => (a, a) -> m a Source #
uniformByteStringM :: HasStatefulGen a m => Int -> m ByteString Source #
uniformListM :: (HasStatefulGen g m, Uniform a) => Int -> m [a] Source #
assertColorFailure :: (HasCallStack, MonadIO m) => String -> m a Source #
shouldBeRight :: (HasCallStack, Show a, Show b, Eq b, MonadIO m) => Either a b -> b -> m () infix 1 Source #
shouldBeLeft :: (HasCallStack, Show a, Eq a, Show b, MonadIO m) => Either a b -> a -> m () infix 1 Source #
expectRight :: (HasCallStack, Show a, MonadIO m) => Either a b -> m b Source #
Return value on the Right
and fail otherwise. Lifted version of expectRight
.
expectRightDeep :: (HasCallStack, Show a, NFData b, MonadIO m) => Either a b -> m b Source #
Same as expectRight
, but also evaluate the returned value to NF
expectRightDeep_ :: (HasCallStack, Show a, NFData b, MonadIO m) => Either a b -> m () Source #
Same as expectRightDeep
, but discards the result
expectLeft :: (HasCallStack, Show b, MonadIO m) => Either a b -> m a Source #
Return value on the Left
and fail otherwise
expectLeftDeep :: (HasCallStack, NFData a, Show b, MonadIO m) => Either a b -> m a Source #
Same as expectLeft
, but also evaluate the returned value to NF
expectLeftDeep_ :: (HasCallStack, NFData a, Show b, MonadIO m) => Either a b -> m () Source #
Same as expectLeftDeep
, but discards the result
shouldBeJust :: (HasCallStack, Show a, Eq a, MonadIO m) => Maybe a -> a -> m () Source #
expectJust :: (HasCallStack, MonadIO m) => Maybe a -> m a Source #
expectJustDeep :: (HasCallStack, NFData a, MonadIO m) => Maybe a -> m a Source #
expectJustDeep_ :: (HasCallStack, NFData a, MonadIO m) => Maybe a -> m () Source #
expectNothing :: (HasCallStack, Show a, MonadIO m) => Maybe a -> m () Source #
Enforce the type of expectation
Useful with polymorphic expectations that are defined below.
Example
Because shouldBeExpr
is polymorphic in m
, compiler will choke with a unification
error. This is due to the fact that hspec's it
expects a polymorphic Example
.
it "MyTest" $ do "foo" `shouldBeExpr` "bar"
However, this is easily solved by io
:
it "MyTest" $ io $ do "foo" `shouldBeExpr` "bar"
impSpecMain :: Spec -> IO () Source #
uniformListRM :: (HasStatefulGen g m, UniformRange a) => (a, a) -> Int -> m [a] Source #
uniformShortByteStringM :: HasStatefulGen a m => Int -> m ShortByteString Source #
applyQCGen :: (QCGen -> (b, QCGen)) -> ImpM t b Source #
impSetSeed :: Int -> ImpM t () Source #
Override the QuickCheck generator using a fixed seed.
runImpM :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO (b, ImpState t) Source #
execImpM :: ImpSpec t => Maybe QCGen -> Maybe Int -> ImpInit t -> ImpM t b -> IO (ImpState t) Source #
impAnn :: NFData a => String -> ImpM t a -> ImpM t a Source #
Annotation for when failure happens. All the logging done within annotation will be discarded if there no failures within the annotation.
logWithCallStack :: CallStack -> Doc AnsiStyle -> ImpM t () Source #
Adds a source location and Doc to the log, which are only shown if the test fails
logDoc :: HasCallStack => Doc AnsiStyle -> ImpM t () Source #
Adds a Doc to the log, which is only shown if the test fails