Skip to content

Commit

Permalink
README: document cfg_attr for cases (#236)
Browse files Browse the repository at this point in the history
* README: document cfg_attr for cases

Fixes #234.

* rstest_macros: document cfg_attr for cases
  • Loading branch information
flokli committed Apr 5, 2024
1 parent 3f91774 commit e03fed3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
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
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

0 comments on commit e03fed3

Please sign in to comment.