proptest-rs / proptest

Hypothesis-like property testing for Rust
Apache License 2.0
1.69k stars 158 forks source link

cargo fmt broken within proptest macro? #370

Closed vlovich closed 11 months ago

vlovich commented 1 year ago

Hi,

I noticed a strange issue where nothing within proptest! {} is formatted by cargo fmt.

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

    proptest! {
         #[test]
         fn test_it(s: u8) {
             eprintln!("Example that never gets formatted even though its very very very long and {} {} {} {} {}", "this", "should", "be", "split", "up");
         }
    }
}
vlovich commented 1 year ago

Oh maybe this is implicit by way of https://github.com/rust-lang/rustfmt/issues/8? Not sure if that's about formatting the macro code or the call site.

rex-remind101 commented 1 year ago

Thanks for raising this, this does appear to be an issue with rustfmt which we unfortunately do not have control over.

tzemanovic commented 11 months ago

https://github.com/proptest-rs/proptest/pull/316 will help with that

matthew-russo commented 11 months ago

As mentioned, this is the expected rustfmt behavior with declarative macros and not specific to proptest. I'm going to close this as there is no action for us to take

cgbur commented 8 months ago

For the time being you could consider copying your proptest block into a new Rust file and formatting with https://github.com/andrewbaxter/genemichaels which handles macros. Granted it took 9 months to support stable let-else formatting, so macro formatting is probably still a few years out.