The hedgehog package

[Tags:bsd3, library, test]

Hedgehog is a modern property-based testing system, in the spirit of QuickCheck. Hedgehog uses integrated shrinking, so shrinks obey the invariants of generated values by construction.

To get started quickly, see the examples: https://github.com/hedgehogqa/haskell-hedgehog/tree/master/hedgehog-example


[Skip to Readme]

Properties

Versions 0.1, 0.2, 0.2.1, 0.2.2, 0.3
Change log CHANGELOG.md
Dependencies ansi-terminal (==0.6.*), async (>=2.0 && <2.2), base (>=3 && <5), bytestring (==0.10.*), concurrent-output (>=1.7 && <2.0), containers (>=0.4 && <0.6), directory (>=1.2 && <1.4), exceptions (>=0.7 && <0.9), mmorph (>=1.0 && <1.2), mtl (>=2.1 && <2.3), pretty-show (==1.6.*), primitive (==0.6.*), random (==1.1.*), resourcet (==1.1.*), semigroups (>=0.16 && <0.19), stm (==2.4.*), template-haskell (>=2.10 && <2.13), text (>=1.1 && <1.3), th-lift (==0.7.*), time (>=1.4 && <1.9), transformers (>=0.3 && <0.6), transformers-base (==0.4.*), unix (>=2.6 && <2.8), wl-pprint-annotated (>=0.0 && <0.2) [details]
License BSD3
Author Jacob Stanley
Maintainer Jacob Stanley <jacob@stanley.io>
Category Testing
Home page https://hedgehog.qa
Bug tracker https://github.com/hedgehogqa/haskell-hedgehog/issues
Source repository head: git clone git://github.com/hedgehogqa/haskell-hedgehog.git
Uploaded Sun Jun 11 02:13:36 UTC 2017 by JacobStanley
Distributions NixOS:0.3
Downloads 330 total (76 in the last 30 days)
Votes
4 []
Status Docs available [build log]
Last success reported on 2017-06-11 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for hedgehog

Readme for hedgehog-0.3

hedgehog Hackage Travis

Hedgehog will eat all your bugs.

<img src="https://github.com/hedgehogqa/haskell-hedgehog/raw/master/img/hedgehog-logo.png" width="307" align="right"/>

Hedgehog is a modern property-based testing system, in the spirit of QuickCheck. Hedgehog uses integrated shrinking, so shrinks obey the invariants of generated values by construction.

Features

  • Integrated shrinking, shrinks obey invariants by construction.
  • Generators allow monadic effects.
  • Range combinators for full control over the scope of generated numbers and collections.
  • Equality and roundtrip assertions show a diff instead of the two inequal values.
  • Template Haskell test runner which executes properties concurrently.

Example

The main module, Hedgehog, includes almost everything you need to get started writing property tests with Hedgehog.

It is designed to be used alongside Hedgehog.Gen and Hedgehog.Range which should be imported qualified. You also need to enable Template Haskell so the Hedgehog test runner can find your properties.

{-# LANGUAGE TemplateHaskell #-}

import           Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range

Once you have your imports set up, you can write a simple property:

prop_reverse :: Property
prop_reverse =
  property $ do
    xs <- forAll $ Gen.list (Range.linear 0 100) Gen.alpha
    reverse (reverse xs) === xs

And add the Template Haskell splice which will discover your properties:

tests :: IO Bool
tests =
  checkParallel $$(discover)

If you prefer to avoid macros, you can specify the group of properties to run manually instead:

tests :: IO Bool
tests =
  checkParallel $ Group "Test.Example" [
      ("prop_reverse", prop_reverse)
    ]

You can then load the module in GHCi, and run it:

λ tests
━━━ Test.Example ━━━
  ✓ prop_reverse passed 100 tests.