From 94cffc75a95e4341e69e74512640e58858494061 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 2 Apr 2024 15:47:55 +0300 Subject: [PATCH 1/2] README: document cfg_attr for cases Fixes #234. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index c7af851e..9e225557 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,25 @@ fn it_works(#[case] a: u32, #[case] b: u32) { See [`rstest_reuse`][reuse-crate-link] for more details. +#### Feature flagged cases + +In case you want certain test cases to only be present if a certain feature is +enabled, use `#[cfg_attr(feature = …, case(…))]`: + +```rust +use rstest::rstest; + +#[rstest] +#[case(2, 2)] +#[cfg_attr(feature = "frac", case(4/2, 2))] +#[case(4/2, 2)] +fn it_works(#[case] a: u32, #[case] b: u32) { + assert!(a == b); +} +``` + +This also works with [`rstest_reuse`][reuse-crate-link]. + ### Magic Conversion If you need a value where its type implement `FromStr()` trait you can use a literal From 0c7addafea8f7fde2bcc493c0beaef6401fa9c65 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 5 Apr 2024 13:40:54 +0300 Subject: [PATCH 2/2] rstest_macros: document cfg_attr for cases --- rstest_macros/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rstest_macros/src/lib.rs b/rstest_macros/src/lib.rs index 553e051f..cb71efce 100644 --- a/rstest_macros/src/lib.rs +++ b/rstest_macros/src/lib.rs @@ -483,6 +483,24 @@ pub fn fixture( /// assert_eq!(s.as_ref().len(), len); /// } /// ``` +/// ### Feature flagged cases +/// +/// In case you want certain test cases to only be present if a certain feature is +/// enabled, use `#[cfg_attr(feature = …, case(…))]`: +/// +/// ``` +/// use rstest::rstest; +/// +/// #[rstest] +/// #[case(2, 2)] +/// #[cfg_attr(feature = "frac", case(4/2, 2))] +/// #[case(4/2, 2)] +/// fn it_works(#[case] a: u32, #[case] b: u32) { +/// assert!(a == b); +/// } +/// ``` +/// +/// This also works with [`rstest_reuse`](https://crates.io/crates/rstest_reuse). /// /// ### Magic Conversion ///