Karya, built on 2020-11-26T21:03:17 (patch 23b5be2d53a9e8e7d6136cda5aae2849abe5cded)
Safe HaskellNone



Basic testing utilities.



type Test = IO.IO () Source #

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_".

data Config Source #





Instances details
Show Config # 
Instance details

Defined in Util.Test.Testing

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


data ModuleMeta Source #




  • initialize :: IO.IO () -> IO.IO ()

    Wrap each test with IO level setup and teardown. Sync exceptions are caught from the test function, so this should only see async exceptions.

  • tags :: [Tag]

data Tag Source #



Especially expensive to run.


Wants to have a conversation. This implies the tests must be serialized, since who wants to have a conversation in parallel. io_human is one way to do this.


Instances details
Eq Tag # 
Instance details

Defined in Util.Test.Testing


(==) :: Tag -> Tag -> Bool #

(/=) :: Tag -> Tag -> Bool #

Show Tag # 
Instance details

Defined in Util.Test.Testing


showsPrec :: Int -> Tag -> ShowS #

show :: Tag -> String #

showList :: [Tag] -> ShowS #


check_val :: Show a => CallStack.Stack => a -> (a -> Bool) -> Test Source #

Check against a function. Use like:

check_val (f x) $ \case -> ...

equal :: (CallStack.Stack, Show a, Eq a) => a -> a -> Test Source #

equal_fmt :: (CallStack.Stack, Eq a, Show a) => (a -> Text) -> a -> a -> Test Source #

equal_on :: (CallStack.Stack, 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 :: (CallStack.Stack, Show err, Show a, Eq a) => Either err a -> a -> Test Source #

not_equal :: (CallStack.Stack, Show a, Eq a) => a -> a -> Test Source #

strings_like :: forall txt. (CallStack.Stack, TextLike txt) => [txt] -> [Pattern] -> Test Source #

Strings in the first list match patterns in the second list, using pattern_matches.

left_like :: (CallStack.Stack, 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.

match :: (CallStack.Stack, TextLike txt) => txt -> Pattern -> Test Source #

type Pattern = Text Source #

Pattern as matched by pattern_matches.

exception assertions

throws :: (CallStack.Stack, Show a) => a -> Pattern -> Test Source #

The given pure value should throw an exception that matches the predicate.

io assertions

io_equal :: (CallStack.Stack, Eq a, Show a) => IO.IO a -> a -> Test Source #

io_human :: CallStack.Stack => String -> IO.IO a -> IO.IO a Source #

Only a human can check these things.

low level

success :: CallStack.Stack => Text -> Test Source #

Print a msg with a special tag indicating a passing test.

failure :: CallStack.Stack => Text -> Test Source #

Print a msg with a special tag indicating a failing test.



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 :: (CallStack.Stack, QuickCheck.Testable prop) => prop -> Test Source #

Run a quickcheck property.

q_equal :: (Show a, Eq a) => a -> a -> QuickCheck.Property Source #

equal for quickcheck.

pretty printing

pretty_compare Source #


:: 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.

pprint :: Show a => a -> IO.IO () Source #


tmp_dir :: String -> IO.IO IO.FilePath Source #

Get a tmp dir, which will be unique for each test run.

in_tmp_dir :: String -> IO.IO a -> IO.IO a Source #

Run the computation with cwd in a new tmp dir.

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.