hledger-lib-1.12: Core data types, parsers and functionality for the hledger accounting tools

Safe Haskell | None
Language | Haskell2010

Hledger.Utils.Test

Synopsis

- type HasCallStack = ?callStack :: CallStack
- fork' :: Test a -> Test (Test a)
- fork :: Test a -> Test ()
- skip :: Test ()
- ok :: Test ()
- note' :: Show s => s -> Test ()
- rerun :: Int -> Test a -> IO ()
- run :: Test a -> IO ()
- rerunOnly :: Int -> Text -> Test a -> IO ()
- runOnly :: Text -> Test a -> IO ()
- using :: IO r -> (r -> IO ()) -> (r -> Test a) -> Test a
- expectEq :: (Eq a, Show a, HasCallStack) => a -> a -> Test ()
- expectLeftNoShow :: HasCallStack => Either e a -> Test ()
- expectLeft :: (Show a, HasCallStack) => Either e a -> Test ()
- expectRightNoShow :: HasCallStack => Either e a -> Test ()
- expectRight :: (Show e, HasCallStack) => Either e a -> Test ()
- expectJust :: HasCallStack => Maybe a -> Test ()
- expect :: HasCallStack -> Bool -> Test ()
- io :: IO a -> Test a
- mapsOf :: Ord k => [Int] -> Test k -> Test v -> Test [Map k v]
- mapOf :: Ord k => Int -> Test k -> Test v -> Test (Map k v)
- pair :: Test a -> Test b -> Test (a, b)
- listsOf :: [Int] -> Test a -> Test [[a]]
- listOf :: Int -> Test a -> Test [a]
- pick :: [a] -> Test a
- word8' :: Word8 -> Word8 -> Test Word8
- word' :: Word -> Word -> Test Word
- double' :: Double -> Double -> Test Double
- int' :: Int -> Int -> Test Int
- word :: Test Word
- double :: Test Double
- int :: Test Int
- word8 :: Test Word8
- bool :: Test Bool
- random' :: Random a => a -> a -> Test a
- random :: Random a => Test a
- note :: Text -> Test ()
- scope :: Text -> Test a -> Test a
- crash :: HasCallStack => Text -> Test a
- data Test a
- runEasytests :: [String] -> Test () -> IO Bool
- tests :: Text -> [Test ()] -> Test ()
- _tests :: Text -> [Test ()] -> Test ()
- test :: Text -> Test a -> Test a
- _test :: Text -> Test a -> Test a
- it :: Text -> Test a -> Test a
- _it :: Text -> Test a -> Test a
- is :: (Eq a, Show a, HasCallStack) => a -> a -> Test ()
- expectEqPP :: (Eq a, Show a, HasCallStack) => a -> a -> Test ()
- expectParse :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> Test ()
- expectParseE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> Test ()
- expectParseError :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> String -> Test ()
- expectParseErrorE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> String -> Test ()
- expectParseEq :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> a -> Test ()
- expectParseEqE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> a -> Test ()
- expectParseEqOn :: (Monoid st, Eq b, Show b, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> (a -> b) -> b -> Test ()
- expectParseEqOnE :: (Monoid st, Eq b, Show b, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> (a -> b) -> b -> Test ()

# Documentation

type HasCallStack = ?callStack :: CallStack Source #

Request a CallStack.

NOTE: The implicit parameter `?callStack :: CallStack` is an implementation detail and should not be considered part of the `CallStack` API, we may decide to change the implementation in the future.

Since: base-4.9.0.0

fork' :: Test a -> Test (Test a) Source #

Run a test in a separate thread, return a future which can be used to block on its result.

fork :: Test a -> Test () Source #

Run a test in a separate thread, not blocking for its result.

skip :: Test () Source #

Explicitly skip this test

ok :: Test () Source #

Record a successful test at the current scope

note' :: Show s => s -> Test () Source #

Log a showable value

rerun :: Int -> Test a -> IO () Source #

Rerun all tests with the given seed

run :: Test a -> IO () Source #

Run all tests

rerunOnly :: Int -> Text -> Test a -> IO () Source #

Rerun all tests with the given seed and whose scope starts with the given prefix

runOnly :: Text -> Test a -> IO () Source #

Run all tests whose scope starts with the given prefix

using :: IO r -> (r -> IO ()) -> (r -> Test a) -> Test a Source #

A test with a setup and teardown

expectEq :: (Eq a, Show a, HasCallStack) => a -> a -> Test () Source #

expectLeftNoShow :: HasCallStack => Either e a -> Test () Source #

expectLeft :: (Show a, HasCallStack) => Either e a -> Test () Source #

expectRightNoShow :: HasCallStack => Either e a -> Test () Source #

expectRight :: (Show e, HasCallStack) => Either e a -> Test () Source #

expectJust :: HasCallStack => Maybe a -> Test () Source #

expect :: HasCallStack -> Bool -> Test () Source #

io :: IO a -> Test a Source #

Convenient alias for `liftIO`

mapsOf :: Ord k => [Int] -> Test k -> Test v -> Test [Map k v] Source #

Generate a `[Data.Map k v]` of the given sizes.

mapOf :: Ord k => Int -> Test k -> Test v -> Test (Map k v) Source #

Generate a `Data.Map k v` of the given size.

pair :: Test a -> Test b -> Test (a, b) Source #

Alias for `liftA2 (,)`.

listsOf :: [Int] -> Test a -> Test [[a]] Source #

Generate a list of lists of the given sizes, an alias for `sizes `forM` \n -> listOf n gen`

listOf :: Int -> Test a -> Test [a] Source #

Alias for `replicateM`

pick :: [a] -> Test a Source #

Sample uniformly from the given list of possibilities

word8' :: Word8 -> Word8 -> Test Word8 Source #

Generate a random `Double` in the given range Note: `word8' 0 10` includes both `0` and `10`.

word' :: Word -> Word -> Test Word Source #

Generate a random `Double` in the given range Note: `word' 0 10` includes both `0` and `10`.

double' :: Double -> Double -> Test Double Source #

Generate a random `Double` in the given range Note: `double' 0 1` includes both `0` and `1`.

int' :: Int -> Int -> Test Int Source #

Generate a random `Int` in the given range Note: `int' 0 5` includes both `0` and `5`

word :: Test Word Source #

Generate a random `Word`

double :: Test Double Source #

Generate a random `Double`

int :: Test Int Source #

Generate a random `Int`

word8 :: Test Word8 Source #

bool :: Test Bool Source #

random' :: Random a => a -> a -> Test a Source #

Generate a bounded random value. Inclusive on both sides.

random :: Random a => Test a Source #

Generate a random value

note :: Text -> Test () Source #

Log a message

scope :: Text -> Test a -> Test a Source #

Label a test. Can be nested. A "." is placed between nested scopes, so `scope "foo" . scope "bar"` is equivalent to `scope "foo.bar"`

crash :: HasCallStack => Text -> Test a Source #

Record a failure at the current scope

data Test a Source #

Tests are values of type `Test a`, and `Test` forms a monad with access to:

- repeatable randomness (the `random` and `random'` functions for random and bounded random values, or handy specialized `int`, `int'`, `double`, `double'`, etc)
- I/O (via `liftIO` or `io`, which is an alias for `liftIO`)
- failure (via `crash`, which yields a stack trace, or `fail`, which does not)
- logging (via `note`, `noteScoped`, or `note'`)
- hierarchically-named subcomputations (under `scope`) which can be switched on and off via `runOnly`
- parallelism (via `fork`)
- conjunction of tests via `MonadPlus` (the `<|>` operation runs both tests, even if the first test fails, and the tests function used above is just `msum`).

Using any or all of these capabilities, you assemble `Test` values into a "test suite" (just another `Test` value) using ordinary Haskell code, not framework magic. Notice that to generate a list of random values, we just `replicateM` and `forM` as usual.

Instances

Monad Test |
Instance details Defined in EasyTest.Internal Methods (>>=) :: Test a -> (a -> Test b) -> Test b Source # (>>) :: Test a -> Test b -> Test b Source # return :: a -> Test a Source # fail :: String -> Test a Source #
Functor Test |
Instance details Defined in EasyTest.Internal Methods fmap :: (a -> b) -> Test a -> Test b Source # (<$) :: a -> Test b -> Test a Source #
Applicative Test |
Instance details Defined in EasyTest.Internal Methods pure :: a -> Test a Source # (<*>) :: Test (a -> b) -> Test a -> Test b Source # liftA2 :: (a -> b -> c) -> Test a -> Test b -> Test c Source # (*>) :: Test a -> Test b -> Test b Source # (<*) :: Test a -> Test b -> Test a Source #
MonadIO Test |
Instance details Defined in EasyTest.Internal Methods liftIO :: IO a -> Test a Source #
Alternative Test |
Instance details Defined in EasyTest.Internal Methods empty :: Test a Source # (<|>) :: Test a -> Test a -> Test a Source # some :: Test a -> Test [a] Source # many :: Test a -> Test [a] Source #
MonadPlus Test |
Instance details Defined in EasyTest.Internal Methods mzero :: Test a Source # mplus :: Test a -> Test a -> Test a Source #
MonadReader Env Test |
Instance details Defined in EasyTest.Internal Methods ask :: Test Env Source # local :: (Env -> Env) -> Test a -> Test a Source # reader :: (Env -> a) -> Test a Source #
IsString (Test a -> Test a) |
Instance details Defined in EasyTest.Internal Methods fromString :: String -> Test a -> Test a Source #

runEasytests :: [String] -> Test () -> IO Bool Source #

Run some easytest tests, catching easytest's ExitCode exception, returning True if there was a problem. With arguments, runs only the scope (or single test) named by the first argument (exact, case sensitive). If there is a second argument, it should be an integer and will be used as the seed for randomness.

tests :: Text -> [Test ()] -> Test () Source #

Name and group a list of tests. Combines easytest's "scope" and "tests".

_tests :: Text -> [Test ()] -> Test () Source #

Skip the given list of tests, and any following tests in a monadic sequence, with the same type signature as "group".

test :: Text -> Test a -> Test a Source #

Name the given test(s). A readability synonym for easytest's "scope".

_test :: Text -> Test a -> Test a Source #

Skip the given test(s), with the same type signature as "test". If called in a monadic sequence of tests, also skips following tests.

it :: Text -> Test a -> Test a Source #

Name the given test(s). A synonym for "test".

_it :: Text -> Test a -> Test a Source #

Skip the given test(s), and any following tests in a monadic sequence. A synonym for "_test".

is :: (Eq a, Show a, HasCallStack) => a -> a -> Test () Source #

Shorter and flipped version of expectEqPP. The expected value goes last.

expectEqPP :: (Eq a, Show a, HasCallStack) => a -> a -> Test () Source #

Like easytest's expectEq (asserts the second (actual) value equals the first (expected) value) but pretty-prints the values in the failure output.

expectParse :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> Test () Source #

Test that this stateful parser runnable in IO successfully parses all of the given input text, showing the parse error if it fails.

expectParseE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> Test () Source #

expectParseError :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> String -> Test () Source #

Test that this stateful parser runnable in IO fails to parse the given input text, with a parse error containing the given string.

expectParseErrorE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> String -> Test () Source #

expectParseEq :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> a -> Test () Source #

Like expectParse, but also test the parse result is an expected value, pretty-printing both if it fails.

expectParseEqE :: (Monoid st, Eq a, Show a, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> a -> Test () Source #

expectParseEqOn :: (Monoid st, Eq b, Show b, HasCallStack) => StateT st (ParsecT CustomErr Text IO) a -> Text -> (a -> b) -> b -> Test () Source #

Like expectParseEq, but transform the parse result with the given function before comparing it.

expectParseEqOnE :: (Monoid st, Eq b, Show b, HasCallStack) => StateT st (ParsecT CustomErr Text (ExceptT FinalParseError IO)) a -> Text -> (a -> b) -> b -> Test () Source #