antigen: Fault injection for QuickCheck

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

AntiGen extends QuickCheck to allow injecting random faults into QuickCheck generators. . It introduces the AntiGen monad, a drop-in replacement for Gen that allows developers to define negative generators alongside their standard positive generators.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.2.0.0, 0.3.0.0
Change log CHANGELOG.md
Dependencies base (>=4.18 && <5), free (>=5.2 && <5.3), mtl (>=2.3.1 && <2.4), QuickCheck (>=2.15.0 && <2.18), quickcheck-transformer (>=0.3.1 && <0.4), random (>=1.2 && <1.4) [details]
Tested with ghc ==9.10.3
License MIT
Copyright 2026 Input Output Global Inc (IOG)
Author IOG Ledger Team
Maintainer hackage@iohk.io
Uploaded by j_jaager at 2026-01-28T15:25:31Z
Revised Revision 1 made by j_jaager at 2026-01-28T15:50:17Z
Category Testing
Source repo head: git clone https://github.com/input-output-hk/antigen
Distributions
Downloads 13 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-01-28 [all 1 reports]

Readme for antigen-0.3.0.0

[back to package description]

AntiGen

AntiGen lets you write QuickCheck generators that can also be negated to generate negative examples. It can be used as a drop-in replacement for Gen.

Example

-- Returns an integer `n` (such that 0 <= n <= 5) and a string of length `n` consisting only of characters 'a'
antiGenLengthString :: AntiGen (Int, String)
antiGenLengthString = do
  -- Use (|!) to provide both a positive and a negative generator
  l <- choose (0, 5) |! choose (6, 10)
  s <-
    pure (replicate l 'a') |! do
      NonNegative l' <- suchThat arbitrary $ \(NonNegative x) -> x /= l
      pure $ replicate l' 'b'
  pure (l, s)

To generate a positive example, use runAntiGen

ghci> generate (runAntiGen antiGenLengthString)
(1, "a")

To generate a negative example, use zapAntiGen

ghci> generate (zapAntiGen 1 antiGenLengthString)
(6, "aaaaaa") -- length is too long
ghci> generate (zapAntiGen 1 antiGenLengthString)
(2, "bbbb") -- length of the string does not match up with the integer

Notice that there is exactly one mistake in the example above. The first argument of zapAntiGen can be used to specify how many negations the generator should introduce.

ghci> generate $ zapAntiGen 2 antiGenLengthString
(10,"b") -- both values are wrong