hegeltest 0.1.17

Property-based testing for Rust, built on Hypothesis
Documentation

Hegel for Rust

[!IMPORTANT] We're excited you're checking out Hegel! Hegel is in beta, and we'd love for you to try it and give any feedback you have.

As part of our beta, we may make breaking changes if it makes Hegel a better property-based testing library. If that instability bothers you, please check back in a few months for a stable release!

See https://hegel.dev/compatibility for more details.

hegel-rust is a property-based testing library for Rust. hegel-rust is based on Hypothesis, using the Hegel protocol.

Installation

To install: cargo add --dev hegeltest.

Hegel requires uv on your PATH, which we use to install the required hegel-core server component. See https://hegel.dev/reference/installation for details.

Quickstart

Here's a quick example of how to write a Hegel test:

use hegel::generators::integers;
use hegel::TestCase;

#[hegel::test]
fn test_addition_commutative(tc: TestCase) {
    let x = tc.draw(integers::<i32>());
    let y = tc.draw(integers::<i32>());
    assert_eq!(x + y, y + x);
}

This test will fail! Integer addition panics on overflow. Hegel will produce a minimal failing test case for us:

Draw 1: 1
Draw 2: 2147483647
thread 'test_addition_commutative' (2) panicked at examples/readme.rs:8:16:
attempt to add with overflow

For a passing test, try:

#[hegel::test]
fn test_wrapping_addition_commutative(tc: TestCase) {
    let add = i32::wrapping_add;
    let x = tc.draw(integers::<i32>());
    let y = tc.draw(integers::<i32>());
    assert_eq!(add(x, y), add(y, x));
}