Hegel (hegel_elixir v0.1.1)

View Source

Property-based testing for Elixir, powered by Hegel's Hypothesis-derived engine.

A property receives a Hegel.TestCase and draws values from contextual generators. Hegel runs the property against examples chosen by libhegel, then shrinks each failure.

alias Hegel.Generators, as: Gen

Hegel.check(fn tc ->
  values = Hegel.draw(tc, Gen.list_of(Gen.integer()))
  assert Enum.reverse(Enum.reverse(values)) == values
end)

For ExUnit's property and check all syntax, use Hegel.ExUnit.

Summary

Functions

Rejects the current example using the contextual test case.

Rejects the current example when condition is false.

Runs a property, returning :ok or raising its minimized failure.

Draws a value using the current property test case.

Draws a value from a generator in the current property.

Marks the current example as a property failure.

Attaches diagnostic information to the minimized counterexample.

Runs a property and returns a structured result without raising for a discovered counterexample.

Draws one value outside a property test.

Guides generation toward larger observed values under label.

Returns the exact libhegel engine version compiled into the NIF.

Types

run_result()

@type run_result() :: {:ok, Hegel.Result.t()} | {:error, Hegel.Result.t()}

Functions

assume(condition)

Rejects the current example using the contextual test case.

assume(test_case, condition)

Rejects the current example when condition is false.

assume(test_case, condition, reason)

@spec assume(Hegel.TestCase.t(), term(), term()) :: :ok | no_return()

check(property, options \\ [])

@spec check((Hegel.TestCase.t() -> term()), keyword() | map() | Hegel.Settings.t()) ::
  :ok

Runs a property, returning :ok or raising its minimized failure.

After replaying the minimized blob, Hegel restores the exception kind, reason, and stacktrace. ExUnit can then render its assertion diff.

draw(generator)

@spec draw(Hegel.Generator.t(value)) :: value when value: term()

Draws a value using the current property test case.

draw(test_case, generator, metadata \\ %{})

@spec draw(Hegel.TestCase.t(), Hegel.Generator.t(value), map() | keyword()) :: value
when value: term()

Draws a value from a generator in the current property.

fail(message \\ "property failed")

Marks the current example as a property failure.

note(message)

note(test_case, message)

Attaches diagnostic information to the minimized counterexample.

run(property, options \\ [])

@spec run((Hegel.TestCase.t() -> term()), keyword() | map() | Hegel.Settings.t()) ::
  run_result()

Runs a property and returns a structured result without raising for a discovered counterexample.

Invalid generator configuration and native errors raise before libhegel can treat them as counterexamples. Use check/2 when ExUnit should receive the minimized assertion.

sample(generator, options \\ [])

@spec sample(
  Hegel.Generator.t(value),
  keyword()
) :: value
when value: term()

Draws one value outside a property test.

Sampling uses libhegel's single-test-case mode and performs no shrinking. It is intended for exploration; real tests should use check/2.

target(value, label)

target(test_case, value, label)

Guides generation toward larger observed values under label.

version()

@spec version() :: String.t()

Returns the exact libhegel engine version compiled into the NIF.