| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Testlib.Assertions
Synopsis
- assertBool :: HasCallStack => String -> Bool -> App ()
- assertOne :: (HasCallStack, Foldable t) => t a -> App a
- assertAtLeastOne :: (HasCallStack, Foldable t) => t a -> App ()
- expectFailure :: HasCallStack => (AssertionFailure -> App ()) -> App a -> App ()
- shouldMatch :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App ()
- eventually :: App a -> App a
- shouldMatchWithMsg :: (MakesValue a, MakesValue b, HasCallStack) => Maybe String -> a -> b -> App ()
- data LenientMatchRule
- shouldMatchWithRules :: (MakesValue a, MakesValue b, HasCallStack) => [LenientMatchRule] -> (Value -> App (Maybe Value)) -> a -> b -> App ()
- shouldMatchBase64 :: (MakesValue a, HasCallStack) => a -> ByteString -> App ()
- shouldNotMatch :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App ()
- shouldMatchInt :: (MakesValue a, HasCallStack) => a -> Int -> App ()
- shouldNotMatchInt :: (MakesValue a, HasCallStack) => a -> Int -> App ()
- shouldMatchRange :: (MakesValue a, HasCallStack) => a -> (Int, Int) -> App ()
- shouldMatchSet :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App ()
- shouldBeEmpty :: (MakesValue a, HasCallStack) => a -> App ()
- shouldBeNull :: (MakesValue a, HasCallStack) => a -> App ()
- shouldMatchOneOf :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App ()
- data Shape
- shouldMatchShape :: (MakesValue a, HasCallStack) => a -> Shape -> App ()
- matchShape :: String -> Value -> Shape -> Maybe String
- matchShapeLoc :: String -> String
- valueShape :: MakesValue a => a -> App Shape
- shouldContainString :: HasCallStack => String -> String -> App ()
- shouldContain :: (Eq a, Show a, HasCallStack) => [a] -> [a] -> App ()
- shouldNotContain :: (Eq a, Show a, HasCallStack) => [a] -> [a] -> App ()
- printFailureDetails :: AssertionFailure -> IO String
- printAppFailureDetails :: AppFailure -> IO String
- prettyContext :: String -> String
- printExceptionDetails :: SomeException -> IO String
- prettierCallStack :: CallStack -> IO String
- prettierCallStackLines :: CallStack -> IO String
- getSourceDir :: String -> IO (Maybe FilePath)
- type SourceDirCache = Map String (Maybe FilePath)
- getSourceDirCached :: SourceDirCache -> String -> IO (SourceDirCache, Maybe FilePath)
- tryReadFile :: FilePath -> IO (Maybe String)
- getLineNumber :: Int -> String -> Maybe String
- prettyResponse :: Response -> String
Documentation
assertBool :: HasCallStack => String -> Bool -> App () Source #
assertAtLeastOne :: (HasCallStack, Foldable t) => t a -> App () Source #
expectFailure :: HasCallStack => (AssertionFailure -> App ()) -> App a -> App () Source #
Arguments
| :: (MakesValue a, MakesValue b, HasCallStack) | |
| => a | The actual value |
| -> b | The expected value |
| -> App () |
eventually :: App a -> App a Source #
Retries every 100ms until timeOutSeconds from Env is reached
Arguments
| :: (MakesValue a, MakesValue b, HasCallStack) | |
| => Maybe String | Message to be added to failure report |
| -> a | The actual value |
| -> b | The expected value |
| -> App () |
data LenientMatchRule Source #
Constructors
| EmptyArrayIsNull | |
| ArraysAreSets | |
| RemoveNullFieldsFromObjects |
Instances
shouldMatchWithRules :: (MakesValue a, MakesValue b, HasCallStack) => [LenientMatchRule] -> (Value -> App (Maybe Value)) -> a -> b -> App () Source #
Arguments
| :: (MakesValue a, HasCallStack) | |
| => a | The actual value, in base64 |
| -> ByteString | The expected value |
| -> App () |
Arguments
| :: (MakesValue a, MakesValue b, HasCallStack) | |
| => a | The actual value |
| -> b | The un-expected value |
| -> App () |
Arguments
| :: (MakesValue a, HasCallStack) | |
| => a | The actual value |
| -> Int | The expected value |
| -> App () |
Specialized variant of shouldMatch to avoid the need for type annotations.
Arguments
| :: (MakesValue a, HasCallStack) | |
| => a | The actual value |
| -> Int | The expected value |
| -> App () |
Arguments
| :: (MakesValue a, HasCallStack) | |
| => a | The actual value |
| -> (Int, Int) | The expected range, inclusive both sides |
| -> App () |
shouldMatchSet :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App () Source #
Match on sorted lists (sets where elements may occur more than once). (Maybe this should
be called shouldMatchMultiSet?)
shouldBeEmpty :: (MakesValue a, HasCallStack) => a -> App () Source #
shouldBeNull :: (MakesValue a, HasCallStack) => a -> App () Source #
shouldMatchOneOf :: (MakesValue a, MakesValue b, HasCallStack) => a -> b -> App () Source #
A simple DSL for describing the recursive structure (shape) of a JSON
value. Use shouldMatchShape to assert that a value conforms to a shape,
or valueShape to compute the shape of an existing value.
Object matching is strict: any key present in the actual value but absent
from the expected SObject field list causes an assertion failure.
FUTUREWORK: heterogenous arrays (`["yes", true, 3]`) FUTUREWORK: optional attributes
Arguments
| :: (MakesValue a, HasCallStack) | |
| => a | The actual value |
| -> Shape | The expected shape |
| -> App () |
Assert that actual conforms to shape. Provides a JSON-path-like
location in the failure message (e.g. .assets[0].key).
matchShapeLoc :: String -> String Source #
Format a path for use in error messages, using the document root ($)
when the path is empty.
valueShape :: MakesValue a => a -> App Shape Source #
Compute the Shape of an existing JSON value. Useful for inspecting
what shape a response actually has, or for using a known-good response as
a shape template via shouldMatchShape.
Arrays: if the array is empty the element shape is SAny; otherwise the
shape of the first element is used for all elements.
Arguments
| :: HasCallStack | |
| => String | The actual value |
| -> String | The expected value |
| -> App () |
Arguments
| :: (Eq a, Show a, HasCallStack) | |
| => [a] | The actual value |
| -> [a] | The expected value |
| -> App () |
Arguments
| :: (Eq a, Show a, HasCallStack) | |
| => [a] | The actual value |
| -> [a] | The expected value |
| -> App () |
prettyContext :: String -> String Source #
getSourceDirCached :: SourceDirCache -> String -> IO (SourceDirCache, Maybe FilePath) Source #
prettyResponse :: Response -> String Source #