Skip to content

About

Property-based testing for Lean 4, with integrated shrinking and model-based state machine testing.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

lean-hedgehog

Property-based testing for Lean 4.

import Hedgehog
open Hedgehog

def reverseReverse : Property Id := property do
  let xs ← forAll (Gen.list (.linear 0 100) Gen.alpha)
  xs.reverse.reverse === xs

#eval check reverseReverse "reverse reverse"

In Lean a property can be proved, and a proof beats any number of tests. Hedgehog is for where there is no proof, or not yet: it checks the property on generated inputs and shrinks a failure to a small counterexample.

  • Integrated shrinking, the idea from Erlang QuickCheck: a generator carries its own shrinks, so there is no shrinker to write and a shrunk value keeps the generator's invariants.
  • Systems with state, tested against a model, for the bugs that only emerge from chaos: commands as open types, or transitions as one closed type.

The guide is USAGE. The examples are in Examples/, each with a bug to find; lake exe examples runs them.

Installation

In lakefile.toml, on Lean 4.35.0 or later:

[[require]]
name = "hedgehog"
git = "https://github.com/hedgehogqa/lean-hedgehog"
rev = "v0.2.1"

AI disclosure

lean-hedgehog was written with strong assistance from AI coding agents, with humans leading the ideas. This would not exist without haskell-hedgehog, written by hand.

In memory of Jacob Stanley

lean-hedgehog is dedicated to Jacob Stanley, author and co-founder of Hedgehog, who passed away on 9 April 2023.

About

Property-based testing for Lean 4, with integrated shrinking and model-based state machine testing.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages