microspec-0.2.1.3: Tiny QuickCheck test library with minimal dependencies

Safe Haskell | Safe-Inferred
Language | Haskell2010

Test.Microspec

Contents

- Specification
- Configuration
- Compatibility

Description

Tests can be structured as nested `it` / `describe` statements

E.g.

    microspec $ do
       describe "plus" $ do
          it "adds positive numbers" $ do
             it "does 1 + 1" $
                1 + 1 === 2
             it "does 2 + 2" $
                2 + 2 === 4
          it "is commutative" $
             \x y -> x + y === y + (x :: Int)

...which will return, nicely in green instead of bold:

      plus
        adds positive numbers
          does 1 + 1
          does 2 + 2
        is commutative

        -----
      Runtime: 0.00943336s
      Successes: 3, Pending: 0, Failures: 0

Synopsis

- microspec :: Microspec () -> IO ()
- microspecWith :: MArgs -> Microspec () -> IO ()
- describe :: MTestable t => String -> t -> Microspec ()
- it :: MTestable t => String -> t -> Microspec ()
- pending :: Pending
- prop :: MTestable prop => String -> prop -> Microspec ()
- data Microspec a
- class MTestable t
- data MArgs = MArgs {
  - _mArgs_timeoutSecs :: Maybe Double
  - _mArgs_qcArgs :: Args
  }
- defaultMArgs :: MArgs
- shouldBe :: (Eq x, Show x) => x -> x -> Property
- shouldSatisfy :: Show x => x -> (x -> Bool) -> Property
- module Test.QuickCheck
- module Test.QuickCheck.Modifiers
- module Test.QuickCheck.Monadic

# Specification

microspec :: Microspec () -> IO () Source #

Run your spec. Put this at the top level, e.g.:

    main = microspec $ do
       describe "plus 1" $
          3 + 1 === 4

microspecWith :: MArgs -> Microspec () -> IO () Source #

`microspec` with `MArgs`

describe :: MTestable t => String -> t -> Microspec () Source #

Describe a test, e.g.:

    describe "reverse 'foo' is 'oof'" $
       reverse "foo" === "oof"

it :: MTestable t => String -> t -> Microspec () Source #

An alias for `describe`. Usually used inside a `describe` block:

     describe "replicate" $ do
        it "doubles with 2" $
           replicate 2 'x' === "xx"
        it "creates a list of the right size" $
           \(Positive n) -> length (replicate n 'x') === n

pending :: Pending Source #

Describe a test as unwritten, e.g.:

    describe "meaning of life" $ pending

prop :: MTestable prop => String -> prop -> Microspec () Source #

Note that you don't need to use this to create a test, e.g.:

    describe "reverse preserves length" $
       \l -> length (reverse l) === length l

data Microspec a Source #

A series of tests, to run with `microspec`

#### Instances

Instances details

Applicative Microspec Source # |
Instance details Defined in Test.Microspec Methods pure :: a -> Microspec a Source # (<*>) :: Microspec (a -> b) -> Microspec a -> Microspec b Source # liftA2 :: (a -> b -> c) -> Microspec a -> Microspec b -> Microspec c Source # (*>) :: Microspec a -> Microspec b -> Microspec b Source # (<*) :: Microspec a -> Microspec b -> Microspec a Source #
Functor Microspec Source # |
Instance details Defined in Test.Microspec Methods fmap :: (a -> b) -> Microspec a -> Microspec b Source # (<$) :: a -> Microspec b -> Microspec a Source #
Monad Microspec Source # |
Instance details Defined in Test.Microspec Methods (>>=) :: Microspec a -> (a -> Microspec b) -> Microspec b Source # (>>) :: Microspec a -> Microspec b -> Microspec b Source # return :: a -> Microspec a Source #
MTestable (Microspec ()) Source # |
Instance details Defined in Test.Microspec Methods describe :: String -> Microspec () -> Microspec () Source #

class MTestable t Source #

Something which can be tested

Note both Bools and Properties can be tested, but only Properties show the values that weren't equal

For both unit tests and property tests, if you want to see the outputs of failed tests use `===`. If you just want to test for equality, use `==`.

For example, the outputs of running:

      microspec $ do
         describe "baddies" $ do
            it "isn't 1 =="  $ 0 == (1 :: Int)
            it "isn't 1 ===" $ 0 === (1 :: Int)
            it "isn't always 1 =="  $ x -> x == (1 :: Int)
            it "isn't always 1 ===" $ x -> x === (1 :: Int)

are:

      isn't 1 == - *** Failed! Falsifiable (after 1 test)
      isn't 1 === - *** Failed! Falsifiable (after 1 test):  | 0 /= 1
      isn't always 1 == - *** Failed! Falsifiable (after 1 test):  | 0
      isn't always 1 === - *** Failed! Falsifiable (after 1 test):  | 0 | 0 /= 1

Minimal complete definition

describe

#### Instances

Instances details

MTestable Property Source # |
Instance details Defined in Test.Microspec Methods describe :: String -> Property -> Microspec () Source #
MTestable Bool Source # |
Instance details Defined in Test.Microspec Methods describe :: String -> Bool -> Microspec () Source #
MTestable (Microspec ()) Source # |
Instance details Defined in Test.Microspec Methods describe :: String -> Microspec () -> Microspec () Source #
(Arbitrary a, Show a, Testable prop) => MTestable (a -> prop) Source # |
Instance details Defined in Test.Microspec Methods describe :: String -> (a -> prop) -> Microspec () Source #

# Configuration

data MArgs Source #

Tweak how tests are run, with `microspecWith`.

Constructors

MArgs |

Fields

- _mArgs_timeoutSecs :: Maybe Double

  Number of seconds before each test times out. If you want to do this on a per-test basis, try `within`

- _mArgs_qcArgs :: Args

  Arguments to use with QuickCheck tests

#### Instances

Instances details

Read MArgs Source # |
Instance details Defined in Test.Microspec Methods readsPrec :: Int -> ReadS MArgs Source # readList :: ReadS [MArgs] Source # readPrec :: ReadPrec MArgs Source # readListPrec :: ReadPrec [MArgs] Source #
Show MArgs Source # |
Instance details Defined in Test.Microspec Methods showsPrec :: Int -> MArgs -> ShowS Source # show :: MArgs -> String Source # showList :: [MArgs] -> ShowS Source #

defaultMArgs :: MArgs Source #

Default arguments. Calling "microspec" is the same as calling "microspecWith defaultMArgs".

# Compatibility

shouldBe :: (Eq x, Show x) => x -> x -> Property Source #

Hspec compatibility. Equivalent to using `===`

shouldSatisfy :: Show x => x -> (x -> Bool) -> Property Source #

Since: 0.2.1.0

module Test.QuickCheck

module Test.QuickCheck.Modifiers

module Test.QuickCheck.Monadic