Skip to content

Expose hedgehog function for testing#158

Draft
micahhahn wants to merge 1 commit into
trunkfrom
expose-hedgehog-function
Draft

Expose hedgehog function for testing#158
micahhahn wants to merge 1 commit into
trunkfrom
expose-hedgehog-function

Conversation

@micahhahn

@micahhahn micahhahn commented Jun 10, 2026

Copy link
Copy Markdown
Member

This PR exposes a new function from the Test module called hedgehog. This function is almost identical to the fuzz function except that we accept the Gen type that underlies the Fuzz opaque type:

hedgehog :: (Stack.HasCallStack, Show a) => Hedgehog.Gen a -> Text -> (a -> Expectation) -> Test

This allows consumers of the library to use the raw powerful Hedgehog combinators if they need to instead of our Elm-like wrappers.

Why do we need this?

I'm trying to write a Fuzzer for a recursive type that is an extension of a JSON object (for json-render):

newtype StatePath = StatePath Text

data Exp
  = Object (Map Text Exp)
  | Array [Exp]
  | String Text
  | Number Scientific
  | Bool Bool
  | BindState StatePath

A first attempt at a fuzzer might look like:

fuzzExp :: Fuzzer Exp
fuzzExp = 
  Fuzz.oneOf
    [ map (Map.fromList >> Object) (Fuzz.list (Fuzz.tuple (Fuzz.text, fuzzExp))),
      map Array (Fuzz.list fuzzExp)
      map String Fuzz.text,
      map (fromFloatDigits >> Number) Fuzz.float,
      map Bool Fuzz.bool, 
      map (StatePath >> BindState) Fuzz.Text
    ]

This of course will cause an infinite recursion.

@micahhahn micahhahn changed the title Expose hedgehog function Expose hedgehog function for testing Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant