proptest-rs / proptest

Hypothesis-like property testing for Rust
Apache License 2.0
1.63k stars 152 forks source link

Unable to set `failure_persistence` using `#![proptest_config]` #423

Closed mauricelam closed 4 months ago

mauricelam commented 4 months ago

I have a project where I want to change the failure_persistence configuration, but it does not seem to be taking effect. When I run the following test, it still shows the failed to find lib.rs or main.rs warning

running 1 test
proptest: FileFailurePersistence::SourceParallel set, but failed to find lib.rs or main.rs
29
24
14
test test::test ... ok

despite the failure_persistence being set to FileFailurePersistence::Direct. The cases property in the same configuration is being picked up.

src/test.rs:

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod test {
    use proptest::test_runner::FileFailurePersistence;

    proptest::proptest! {
        #![proptest_config(proptest::test_runner::Config {
            failure_persistence: Some(Box::new(FileFailurePersistence::Direct("failure_persistence.txt"))),
            cases: 3,
            ..Default::default()
        })]
        #[test]
        fn test(a in 0..30) {
            println!("{a}")
        }
    }
}

Cargo.toml:

[package]
name = "proptest-file"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "test"
path = "src/test.rs"

[dependencies]
proptest = "1.4.0"
matthew-russo commented 4 months ago

Thanks for the report, I have a fix pending review