Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Util.Test.Testing

Description

Basic testing utilities.

Synopsis

Documentation

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 #

Constructors

Config 

Fields

Instances

Instances details
Show Config Source # 
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

metadata

data ModuleMeta Source #

Constructors

ModuleMeta 

Fields

  • 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 #

Constructors

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. io_human is one way to do this.

Instances

Instances details
Show Tag Source # 
Instance details

Defined in Util.Test.Testing

Methods

showsPrec :: Int -> Tag -> ShowS #

show :: Tag -> String #

showList :: [Tag] -> ShowS #

Eq Tag Source # 
Instance details

Defined in Util.Test.Testing

Methods

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

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

assertions

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

Check against a function. Use like:

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

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

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

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 #

not_equal :: (Stack.HasCallStack, Show a, Eq a) => 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.

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

type Pattern = Text Source #

Pattern as matched by pattern_matches.

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

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.

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

equal for quickcheck.

pretty printing

pretty_compare Source #

Arguments

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

filesystem

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.

util