rustfmt
rustfmt copied to clipboard
rustfmt doesn't format proptest! blocks
I tried searching around but couldn't find anything about this. I'm trying to use rustfmt (by way of cargo fmt) to format my files, but the proptest! blocks are not being formatted. Seems like a valuable thing to support. Am I missing something?
Currently rustfmt does not format a macro call with braces. Could you please try using parentheses instead by replacing proptest!{ /* ... */ } with proptest!( /* ... */); ?
@topecongiro That doesn't seem to have any effect. I'm using stable: rustfmt 0.6.1-stable (49279d7 2018-05-08).
Hi there,
Apologies for the bump, I just wanted to check if the issue I'm seeing is the same as this one, before submitting an issue.
Example repository: https://github.com/joshuataylor/proptest_example
Ideally, I would like the code to look like this: https://github.com/joshuataylor/proptest_example/blob/main/tests/proptest_test.rs
#[cfg(test)]
mod tests {
use proptest::prelude::*;
proptest!(
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
);
proptest! {
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example2(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
}
}
Here is a sample file, with no formatting.
#[cfg(test)]
mod tests {
use proptest::prelude::*;
proptest!(
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
);
proptest! {
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example2(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
}
}
cargo fmt currently formats like this file, which I believe to be wrong.
#[cfg(test)]
mod tests {
use proptest::prelude::*;
proptest!(
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
);
proptest! {
#![proptest_config(ProptestConfig::with_cases(2))]
#[test]
fn test_example2(a in 1..4i32, b in 5..10i32) {
prop_assert!(a <= b);
}
}
}
Tested on:
-
MacOS ARM64 stable
rustc 1.79.0 (129f3b996 2024-06-10)and nightlyrustc 1.81.0-nightly (6be96e386 2024-07-09)).Darwin btsl 22.6.0 Darwin Kernel Version 22.6.0: Mon Apr 22 20:51:27 PDT 2024; root:xnu-8796.141.3.705.2~1/RELEASE_ARM64_T6020 arm64 arm Darwin -
Linux AMD64 (ArchLinux, if it matters) stable
rustc 1.79.0 (129f3b996 2024-06-10)and nightlyrustc 1.81.0-nightly (6be96e386 2024-07-09)Linux dev 6.8.8-2-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.8-2 (2024-06-24T09:00Z) x86_64 GNU/Linux