hedgehog: Release with confidence.

[ bsd3, library, testing ] [ Propose Tags ] [ Report a vulnerability ]

Hedgehog automatically generates a comprehensive array of test cases, exercising your software in ways human testers would never imagine.

Generate hundreds of test cases automatically, exposing even the most insidious of corner cases. Failures are automatically simplified, giving developers coherent, intelligible error messages.

To get started quickly, see the examples.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.4.1, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.6, 0.6.1, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1, 1.1.2, 1.2, 1.3, 1.4, 1.5
Change log CHANGELOG.md
Dependencies ansi-terminal (>=0.6 && <1.2), async (>=2.0 && <2.3), barbies (>=1.0 && <2.2), base (>=4.9 && <5), bytestring (>=0.10 && <0.13), concurrent-output (>=1.7 && <1.11), containers (>=0.4 && <0.8), deepseq (>=1.1.0.0 && <1.6), directory (>=1.2 && <1.4), erf (>=2.0 && <2.1), exceptions (>=0.7 && <0.11), lifted-async (>=0.7 && <0.11), mmorph (>=1.0 && <1.3), monad-control (>=1.0 && <1.1), mtl (>=2.1 && <2.4), pretty-show (>=1.6 && <1.11), primitive (>=0.6 && <0.10), random (>=1.1 && <1.3), resourcet (>=1.1 && <1.4), safe-exceptions (>=0.1 && <0.2), stm (>=2.4 && <2.6), template-haskell (>=2.10 && <2.23), text (>=1.1 && <2.2), time (>=1.4 && <1.15), transformers (>=0.5 && <0.7), transformers-base (>=0.4.5.1 && <0.5), wl-pprint-annotated (>=0.0 && <0.2) [details]
Tested with ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.3, ghc ==8.10.1, ghc ==9.2.1
License BSD-3-Clause
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 repo head: git clone git://github.com/hedgehogqa/haskell-hedgehog.git
Uploaded by moodmosaic at 2024-07-24T13:51:14Z
Distributions Arch:1.2, Debian:1.0.3, LTSHaskell:1.5, NixOS:1.4, Stackage:1.5
Reverse Dependencies 63 direct, 103 indirect [details]
Downloads 47269 total (329 in the last 30 days)
Rating 2.75 (votes: 12) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-24 [all 1 reports]

Readme for hedgehog-1.5

[back to package description]

Release with confidence.

Hackage GitHub CI

Hedgehog automatically generates a comprehensive array of test cases, exercising your software in ways human testers would never imagine.

Generate hundreds of test cases automatically, exposing even the most insidious of corner cases. Failures are automatically simplified, giving developers coherent, intelligible error messages.

Features

  • Integrated shrinking, shrinks obey invariants by construction.
  • Abstract state machine testing.
  • 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:

{-# LANGUAGE OverloadedStrings #-}

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.

In Memory of Jacob Stanley

As we come to the end of our guide to haskell-hedgehog, we'd like to take a moment to remember and honor one of its key contributors, our dear friend, author and co-founder, Jacob Stanley.

Jacob's passion for Haskell and his commitment to creating high-quality, reliable software was truly inspiring. His work has shaped haskell-hedgehog in countless ways, and without him, it wouldn't be the project it is today.

Jacob passed away unexpectedly on April 9th. His absence is deeply felt, but his impact on this project, and on all of us who had the privilege to work with him, remains. We continue to maintain and develop haskell-hedgehog in his memory and in honor of his dedication to excellence in programming.

As you explore haskell-hedgehog, and possibly contribute to its ongoing development, we invite you to join us in remembering Jacob Stanley — a tremendous developer, collaborator, and friend.


Contributors