//! The repository's seed and budget convention for proptest //! (robot-docs/testing.md#seeds-and-budgets). //! //! `ALBEDO_PROPERTY_SEED` unset runs the gate's fixed seed, `random` a fresh //! one, and a number that seed. `ALBEDO_PROPERTY_CASES` sets the cases per //! property. Failure persistence is off: a counterexample is committed as a //! named example test instead of a `proptest-regressions` file. use proptest::test_runner::{Config, RngSeed}; use std::hash::{BuildHasher, RandomState}; /// The seed every property runs with when `ALBEDO_PROPERTY_SEED` is unset. pub const GATE_SEED: u64 = 1; /// A config for a property that runs `gate_cases` cases in the gate. /// /// It prints the seed it chose. `cargo test` shows a test's output only when /// the test fails, so a failure's log names the seed beside proptest's /// minimal failing input. pub fn config(gate_cases: u32) -> Config { let seed = match std::env::var("ALBEDO_PROPERTY_SEED").as_deref() { Err(_) => GATE_SEED, Ok("random") => RandomState::new().hash_one(std::process::id()), Ok(value) => value .parse() .expect("ALBEDO_PROPERTY_SEED must be unset, \"random\", or an integer"), }; let cases = match std::env::var("ALBEDO_PROPERTY_CASES") { Ok(value) => value .parse() .expect("ALBEDO_PROPERTY_CASES must be an integer"), Err(_) => gate_cases, }; eprintln!("ALBEDO_PROPERTY_SEED={seed} ALBEDO_PROPERTY_CASES={cases}"); Config { cases, rng_seed: RngSeed::Fixed(seed), failure_persistence: None, ..Config::default() } }