Safe Haskell | Safe-Inferred |
---|
Basic testing utilities.
Synopsis
- type Test = IO.IO ()
- type Profile = IO.IO ()
- data Config = Config {}
- modify_test_config :: (Config -> Config) -> IO.IO ()
- with_test_name :: Text -> IO.IO a -> IO.IO a
- data ModuleMeta = ModuleMeta {
- initialize :: IO.IO () -> IO.IO ()
- tags :: [Tag]
- moduleMeta :: ModuleMeta
- data Tag
- = Large
- | Interactive
- check :: Stack.HasCallStack => Text -> Bool -> Test
- check_val :: (Show a, Stack.HasCallStack) => a -> (a -> Bool) -> Test
- equal :: (Stack.HasCallStack, Show a, Eq a) => a -> a -> Test
- equal_fmt :: (Stack.HasCallStack, Eq a, Show a) => (a -> Text) -> a -> a -> Test
- equal_on :: (Stack.HasCallStack, Eq b, Show a, Show b) => (a -> b) -> a -> b -> Test
- right_equal :: (Stack.HasCallStack, Show err, Show a, Eq a) => Either err a -> a -> Test
- not_equal :: (Stack.HasCallStack, Show a, Eq a) => a -> a -> Test
- equalf :: (Stack.HasCallStack, Show a, ApproxEq.ApproxEq a) => Double -> a -> a -> Test
- strings_like :: forall txt. (Stack.HasCallStack, TextLike txt) => [txt] -> [Pattern] -> Test
- left_like :: (Stack.HasCallStack, Show a, TextLike txt) => Either txt a -> Pattern -> Test
- match :: (Stack.HasCallStack, TextLike txt) => txt -> Pattern -> Test
- type Pattern = Text
- throws :: (Stack.HasCallStack, Show a) => a -> Pattern -> Test
- io_equal :: (Stack.HasCallStack, Eq a, Show a) => IO.IO a -> a -> Test
- io_human :: Stack.HasCallStack => String -> IO.IO a -> IO.IO a
- pause :: String -> IO.IO ()
- success :: Stack.HasCallStack => Text -> Test
- failure :: Stack.HasCallStack => Text -> Test
- expect_right :: (Stack.HasCallStack, Show a) => Either a b -> b
- hedgehog :: Property -> Test
- property :: Stack.HasCallStack => PropertyT IO.IO () -> Property
- (===) :: (MonadTest m, Eq a, Show a, Stack.HasCallStack) => a -> a -> m ()
- (/==) :: (MonadTest m, Eq a, Show a, Stack.HasCallStack) => a -> a -> m ()
- quickcheck :: (Stack.HasCallStack, QuickCheck.Testable prop) => prop -> Test
- q_equal :: (Show a, Eq a) => a -> a -> QuickCheck.Property
- pretty_compare :: Show a => Text -> Text -> Bool -> a -> a -> Bool -> Text
- prettyp :: Pretty.Pretty a => a -> IO.IO ()
- pprint :: Show a => a -> IO.IO ()
- tmp_dir :: String -> IO.IO IO.FilePath
- in_tmp_dir :: String -> IO.IO a -> IO.IO a
- tmp_base_dir :: IO.FilePath
- force :: DeepSeq.NFData a => a -> IO.IO ()
Documentation
The type of toplevel tests, which is the same as the type of individual test functions. It's just IO () for now, but some day I may be able to move to something more specialized, so if tests have declared types it might as well be one I can change in one place.
type Profile = IO.IO () Source #
Profiles are just like tests, but I'll use a different type just for documentation at least. The real determination is that profiles start with "profile_" instead of "test_".
Config | |
|
with_test_name :: Text -> IO.IO a -> IO.IO a Source #
Set config_test_name
. 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. |
Interactive | Wants to have a conversation. This implies the tests must be
serialized, since who wants to have a conversation in parallel.
|
assertions
check_val :: (Show a, Stack.HasCallStack) => a -> (a -> Bool) -> Test Source #
Check against a function. Use like:
check_val (f x) $ \case -> ...
equal_on :: (Stack.HasCallStack, Eq b, Show a, Show b) => (a -> b) -> a -> b -> Test Source #
Assert these things are equal after applying a function. Print without the function if they're not equal. This is for cases when the extract function loses information it would be nice to see if the test fails.
right_equal :: (Stack.HasCallStack, Show err, Show a, Eq a) => Either err a -> a -> Test Source #
equalf :: (Stack.HasCallStack, Show a, ApproxEq.ApproxEq a) => Double -> a -> a -> Test Source #
strings_like :: forall txt. (Stack.HasCallStack, TextLike txt) => [txt] -> [Pattern] -> Test Source #
Strings in the first list match patterns in the second list, using
pattern_matches
.
left_like :: (Stack.HasCallStack, Show a, TextLike txt) => Either txt a -> Pattern -> Test Source #
It's common for Left to be an error msg, or be something that can be converted to one.
exception assertions
throws :: (Stack.HasCallStack, Show a) => a -> Pattern -> Test Source #
The given pure value should throw an exception that matches the predicate.
io assertions
io_human :: Stack.HasCallStack => String -> IO.IO a -> IO.IO a Source #
Only a human can check these things.
low level
success :: Stack.HasCallStack => Text -> Test Source #
Print a msg with a special tag indicating a passing test.
failure :: Stack.HasCallStack => Text -> Test Source #
Print a msg with a special tag indicating a failing test.
extracting
expect_right :: (Stack.HasCallStack, Show a) => Either a b -> b Source #
hedgehog
property :: Stack.HasCallStack => PropertyT IO.IO () -> Property #
Creates a property with the default configuration.
(===) :: (MonadTest m, Eq a, Show a, Stack.HasCallStack) => a -> a -> m () infix 4 #
Fails the test if the two arguments provided are not equal.
(/==) :: (MonadTest m, Eq a, Show a, Stack.HasCallStack) => a -> a -> m () infix 4 #
Fails the test if the two arguments provided are equal.
QuickCheck
quickcheck :: (Stack.HasCallStack, QuickCheck.Testable prop) => prop -> Test Source #
Run a quickcheck property.
pretty printing
:: Show a | |
=> Text | equal operator |
-> Text | inequal operator |
-> Bool | If True then equal is expected so inequal will be highlighted red. Otherwise, inequal is expected and highlighted green. |
-> a | |
-> a | |
-> Bool | True if as are equal |
-> Text |
Show the values nicely, whether they are equal or not.
prettyp :: Pretty.Pretty a => a -> IO.IO () Source #
filesystem
tmp_dir :: String -> IO.IO IO.FilePath Source #
Get a tmp dir, which will be unique for each test run.
tmp_base_dir :: IO.FilePath Source #
All tmp files used by tests should go in this directory. TODO instead of being hardcoded this should be configured per-project.
util
force :: DeepSeq.NFData a => a -> IO.IO () Source #