Safe Haskell | None |
---|---|
Language | Haskell2010 |
Basic testing utilities.
Synopsis
- data Config = Config {
- configTestName :: !Text
- modifyTestConfig :: (Config -> Config) -> IO ()
- withTestName :: Text -> IO a -> IO a
- data ModuleMeta = ModuleMeta {
- initialize :: IO () -> IO ()
- tags :: [Tag]
- moduleMeta :: ModuleMeta
- data Tag = Large
- check :: HasCallStack => Text -> Bool -> IO Bool
- checkVal :: Show a => HasCallStack => a -> (a -> Bool) -> IO Bool
- equal :: (HasCallStack, Show a, Eq a) => a -> a -> IO Bool
- equalFmt :: (HasCallStack, Eq a, Show a) => (a -> Text) -> a -> a -> IO Bool
- rightEqual :: (HasCallStack, Show err, Show a, Eq a) => Either err a -> a -> IO Bool
- notEqual :: (HasCallStack, Show a, Eq a) => a -> a -> IO Bool
- equalf :: (HasCallStack, Show a, ApproxEq a) => Double -> a -> a -> IO Bool
- stringsLike :: forall txt. (HasCallStack, TextLike txt) => [txt] -> [Pattern] -> IO Bool
- leftLike :: (HasCallStack, Show a, TextLike txt) => Either txt a -> Pattern -> IO Bool
- match :: (HasCallStack, TextLike txt) => txt -> Pattern -> IO Bool
- type Pattern = Text
- throws :: (HasCallStack, Show a) => a -> Pattern -> IO Bool
- ioEqual :: (HasCallStack, Eq a, Show a) => IO a -> a -> IO Bool
- success :: HasCallStack => Text -> IO Bool
- failure :: HasCallStack => Text -> IO Bool
- expectRight :: (HasCallStack, Show a) => Either a b -> b
- quickcheck :: (HasCallStack, Testable prop) => prop -> IO Bool
- qcEqual :: (Show a, Eq a) => a -> a -> Property
- pprint :: Show a => a -> IO ()
- uniqueTmpDir :: String -> IO FilePath
- inTmpDir :: String -> IO a -> IO a
- tmpBaseDir :: FilePath
- force :: NFData a => a -> IO ()
Documentation
Config | |
|
withTestName :: Text -> IO a -> IO a Source #
Set configTestName
. This is a grody hack, but I need it because GHC
call stack is off by one, so you get the caller line number, but the
callee's function name: https://ghc.haskell.org/trac/ghc/ticket/11686
metadata
data ModuleMeta Source #
ModuleMeta | |
|
Large | Especially expensive to run. |
assertions
checkVal :: Show a => HasCallStack => a -> (a -> Bool) -> IO Bool Source #
Check against a function. Use like:
checkVal (f x) $ \case -> ...
rightEqual :: (HasCallStack, Show err, Show a, Eq a) => Either err a -> a -> IO Bool Source #
stringsLike :: forall txt. (HasCallStack, TextLike txt) => [txt] -> [Pattern] -> IO Bool Source #
Strings in the first list match patterns in the second list, using
patternMatches
.
leftLike :: (HasCallStack, Show a, TextLike txt) => Either txt a -> Pattern -> IO Bool Source #
It's common for Left to be an error msg, or be something that can be converted to one.
exception assertions
throws :: (HasCallStack, Show a) => a -> Pattern -> IO Bool Source #
The given pure value should throw an exception that matches the predicate.
io assertions
low level
success :: HasCallStack => Text -> IO Bool Source #
Print a msg with a special tag indicating a passing test.
failure :: HasCallStack => Text -> IO Bool Source #
Print a msg with a special tag indicating a failing test.
extracting
expectRight :: (HasCallStack, Show a) => Either a b -> b Source #
QuickCheck
quickcheck :: (HasCallStack, Testable prop) => prop -> IO Bool Source #
Run a quickcheck property.
pretty printing
filesystem
uniqueTmpDir :: String -> IO FilePath Source #
Get a tmp dir, which will be unique for each test run.
tmpBaseDir :: FilePath Source #
All tmp files used by tests should go in this directory.
TODO instead of being hardcoded this should be configured per-project.