Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt doesn't format proptest! blocks #2867

Open
coltfred opened this issue Jul 27, 2018 · 3 comments
Open

rustfmt doesn't format proptest! blocks #2867

coltfred opened this issue Jul 27, 2018 · 3 comments
Labels
a-macros needs-mcve needs a Minimal Complete and Verifiable Example p-low

Comments

@coltfred
Copy link

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?

@topecongiro
Copy link
Contributor

Currently rustfmt does not format a macro call with braces. Could you please try using parentheses instead by replacing proptest!{ /* ... */ } with proptest!( /* ... */); ?

@coltfred
Copy link
Author

@topecongiro That doesn't seem to have any effect. I'm using stable: rustfmt 0.6.1-stable (49279d7 2018-05-08).

@joshuataylor
Copy link

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 nightly rustc 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 nightly rustc 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros needs-mcve needs a Minimal Complete and Verifiable Example p-low
Projects
None yet
Development

No branches or pull requests

5 participants