native zig PBT and DST with shrinking, replay, and fault injection
Files
README.md

hegel-zig #

hegel-zig is a property testing and deterministic simulation library for Zig. it generates test cases, shrinks failures, and emits replay blobs. its native Zig engine ports libhegel, which builds on Hypothesis. the pinned Rust engine serves as a reference for differential testing.

install #

requires Zig 0.17 and a host target. from your project:

zig fetch --save=hegel https://tangled.org/zzstoatzz.io/hegel-zig/archive/2e188e8018af17839a731cd77be508d588cda80b.tar.gz

add the module to your test target in build.zig:

const hegel = b.dependency("hegel", .{ .target = target, .optimize = optimize });
tests.root_module.addImport("hegel", hegel.module("hegel"));

use #

const hegel = @import("hegel");
const std = @import("std");

test "bytes round-trip through a packed integer" {
    try hegel.run(.{}, {}, roundTrip);
}

fn roundTrip(_: void, case: *hegel.TestCase) !void {
    const high = try case.int(u8, 0, 255);
    const low = try case.int(u8, 0, 255);
    const packed_value = (@as(u16, high) << 8) | low;
    try std.testing.expectEqual(high, @as(u8, @truncate(packed_value >> 8)));
    try std.testing.expectEqual(low, @as(u8, @truncate(packed_value)));
}

on failure, set HEGEL_ZIG_REPLAY to the printed blob and rerun the test. see the state machine example for model checks and the fault plan example for interruptions before and after a write takes effect.

The optional campaign CLI runs committed harnesses in disposable checkouts and retains structured results and replay bundles. Build it with zig build campaign; see campaigns for manifests and use.

develop #

zig build test-campaign    # check CLI outcomes, isolation, cleanup and replay
zig build test             # run regressions and planted mutants with native Zig
zig build compare-engines  # compare traces, errors, replay, and corpora against Rust

the comparison also requires Cargo, Git, and Python 3. docs/ covers harnesses, compatibility, and source provenance; scope records what we build ourselves and what we leave out.

used by #

zat, zds, zkv, pmdeflate, prefect-server, and plyr.fm.

license #

the wrapper is MIT. the native engine retains MPL-2.0 and other inherited terms in LICENSES/. see the licensing guide for source availability and provenance.