Skip to main content

standalone_function

Attribute Macro standalone_function 

Source
#[standalone_function]
Expand description

Rewrite a function taking a TestCase plus additional arguments into one that takes just those arguments and internally runs Hegel.

Behaves like test for name rewriting, explicit test cases, and settings parsing. The generated function has the original signature with the TestCase parameter removed, and its body is run as an FnMut closure inside [Hegel::run].

use hegel::TestCase;
use hegel::generators as gs;

#[hegel::standalone_function(test_cases = 10)]
fn check_addition_commutative(tc: TestCase, increment: i32) {
    let n: i32 = tc.draw(gs::integers());
    assert_eq!(n + increment, increment + n);
}

// callers invoke it as a normal function:
check_addition_commutative(5);