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

README: document cfg_attr for cases #236

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions rstest_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down