Hegel (hegel_elixir v0.1.1)
View SourceProperty-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
@type run_result() :: {:ok, Hegel.Result.t()} | {:error, Hegel.Result.t()}
Functions
Rejects the current example using the contextual test case.
Rejects the current example when condition is false.
@spec assume(Hegel.TestCase.t(), term(), term()) :: :ok | no_return()
@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.
@spec draw(Hegel.Generator.t(value)) :: value when value: term()
Draws a value using the current property test case.
@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.
Marks the current example as a property failure.
Attaches diagnostic information to the minimized counterexample.
@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.
@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.
Guides generation toward larger observed values under label.
@spec version() :: String.t()
Returns the exact libhegel engine version compiled into the NIF.