Safe Haskell | None |
---|
A module containing utilities for testing with test-framework
, HUnit
,
and testable
.
- isExceptionThrown :: (Functor m, MonadCatchIO m, Exception e) => m a -> m (Either e a)
- assertThrown :: (Functor m, MonadCatchIO m, Exception e, Show e) => Maybe String -> Proxy e -> m () -> m ()
- assertNotThrown :: (Functor m, MonadCatchIO m, Exception e, Show e) => Maybe (e -> String) -> m () -> m ()
- timeMicroseconds :: (Monad m, MonadIO m) => m a -> m (a, Integer)
- timeoutMicroseconds :: Integer -> IO a -> IO (Maybe a)
- assertMicroseconds :: Integer -> IO a -> IO a
- timeoutProcessMicroseconds :: Integer -> ProcessHandle -> IO (Maybe ExitCode)
- assertProcessMicroseconds :: Integer -> ProcessHandle -> IO ()
- catchStdout :: IO a -> IO (a, ByteString)
- catchStderr :: IO a -> IO (a, ByteString)
- data TestUtilException where
- TestUtilException :: Exception e => e -> TestUtilException
- testUtilExceptionToException :: Exception e => e -> SomeException
- testUtilExceptionFromException :: Exception e => SomeException -> Maybe e
- data TimeoutOverflow = TimeoutOverflow {}
- timeoutOverflow_message :: Lens' TimeoutOverflow (Maybe String)
- timeoutOverflow_microseconds :: Lens' TimeoutOverflow Integer
- timeoutOverflow_inputBound :: Lens' TimeoutOverflow Integer
- data TimeLimitExceeded = TimeLimitExceeded {}
- timelimitExceeded_message :: Lens' TimeLimitExceeded (Maybe String)
- timelimitExceeded_callerName :: Lens' TimeLimitExceeded String
- timelimitExceeded_microseconds :: Lens' TimeLimitExceeded Integer
Throwing and catching exceptions
isExceptionThrown :: (Functor m, MonadCatchIO m, Exception e) => m a -> m (Either e a)Source
Determine whether an exception was caught, and return it if so.
:: (Functor m, MonadCatchIO m, Exception e, Show e) | |
=> Maybe String | Optional error message. |
-> Proxy e | Type of exception to test for. |
-> m () | |
-> m () |
Assert that an exception is thrown.
When an exception is not thrown, the input String
, or otherwise a
default string, is output.
For more control, see the more fundamental isExceptionThrown
.
assertNotThrown :: (Functor m, MonadCatchIO m, Exception e, Show e) => Maybe (e -> String) -> m () -> m ()Source
Assert that an exception is not thrown.
When an exception is thrown, the input function, or a default one, is given the exception and the resulting string is output.
For more control, see the more fundamental isExceptionThrown
.
Concurrent TDD
Process timing
timeMicroseconds :: (Monad m, MonadIO m) => m a -> m (a, Integer)Source
Time a computation.
timeoutMicroseconds :: Integer -> IO a -> IO (Maybe a)Source
Run a computation within an approximate time limit.
This is currently a wrapper for timeout
that checks for
overflows.
assertMicroseconds :: Integer -> IO a -> IO aSource
Assert that a computation runs within an approximate time limit.
If the computation does not finish within the given time limit, a
TimeLimitExceeded
exception is thrown.
For more control, see the more fundamental timeoutMicroseconds
function.
assertProcessMicroseconds :: Integer -> ProcessHandle -> IO ()Source
Assert that a process finishes within an approximate time limit.
If the computation does not finish within the given time limit, a
TimeLimitExceeded
exception is thrown.
For more control, see the more fundamental timeoutProcessMicroseconds
function.
Catching stdout/stderr
catchStdout :: IO a -> IO (a, ByteString)Source
A wrapper around system-posix-riderct
's redirectStdout to redirect
stdout during the execution of a
computation and capture the output, restoring the handle upon completion.
This may be useful for writing unit tests against some parts of a program
that interface with the outside world, such as logging and the CLI frontend.
NB: Since the standard file streams are redirected into a Knob
, all tests
that invoke catchHandle
must be run in isolation from each other, since
only one test can read the handle's output at a time. The author recommends
structuring tests such that all such tests under a test tree that uses
test-framework's mutuallyExclusive
function and whose child nodes all do
the same. Both stdout
and stderr
can be captured at the same time,
however.
catchStderr :: IO a -> IO (a, ByteString)Source
A wrapper around system-posix-riderct
's redirectStderr to redirect
stdout during the execution of a
computation and capture the output, restoring the handle upon completion.
This may be useful for writing unit tests against some parts of a program
that interface with the outside world, such as logging and the CLI frontend.
NB: Since the standard file streams are redirected into a Knob
, all tests
that invoke catchHandle
must be run in isolation from each other, since
only one test can read the handle's output at a time. The author recommends
structuring tests such that all such tests under a test tree that uses
test-framework's mutuallyExclusive
function and whose child nodes all do
the same. Both stdout
and stderr
can be captured at the same time,
however.
Exceptions
data TestUtilException whereSource
A class of exceptions for Tests.Util.
TestUtilException :: Exception e => e -> TestUtilException |
testUtilExceptionToException :: Exception e => e -> SomeExceptionSource
testUtilExceptionFromException :: Exception e => SomeException -> Maybe eSource
data TimeoutOverflow Source
timeoutMicrosoconds
was invoked with an integer that would cause the
input given to timeout
to overflow.
TimeoutOverflow | |
|
data TimeLimitExceeded Source
TimeLimitExceeded | |
|