Skip to content

Commit

Permalink
Add docuemnt for #[proptest(async = ...)].
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenlib committed Jul 15, 2023
1 parent 839fe30 commit c492d62
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ fn my_test(_x: u32, #[strategy(1..10u32)] y: u32, #[strategy(0..#y)] z: u32) {
}
```

## Helper attributes
## Attributes

Helper attributes can be written in the following positions.
Attributes can be written in the following positions.

| attribute | function | struct | enum | variant | field | function parameter |
| --------------------------------------------------- | -------- | ------ | ---- | ------- | ----- | ------------------ |
Expand All @@ -92,6 +92,9 @@ Helper attributes can be written in the following positions.
| [`#[arbitrary(args = T)]`](#arbitraryargs--t) | ||| | | |
| [`#[arbitrary(bound(...))]`](#arbitraryboundt1-t2-) | ||||| |
| [`#[arbitrary(dump)]`](#arbitrarydump) | ||| | | |
| [`#[proptest]`](#proptest) || | | | | |
| [`#[proptest(async = ...)]`](#proptestasync--) || | | | | |
| [`#[proptest_dump]`](#proptest_dump) || | | | | |

## `#[derive(Arbitrary)]`

Expand Down Expand Up @@ -631,6 +634,33 @@ fn my_test_with_config_3(_input: i32) {
}
```

### `#[proptest(async = ...)]`

Async functions can be tested by setting `async = ...` to the argument of `#[proptest]`.

The following values are allowed after `async =`.
The value specifies the asynchronous runtime used for the test.

- "tokio"

```toml
[dev-dependencies]
test-strategy = "0.3"
proptest = "1.1.0"
tokio = { version = "1.28.1", features = ["rt-multi-thread"] }
```

```rust
use test_strategy::proptest;
use proptest::prop_assert;

#[proptest(async = "tokio")]
async fn my_test_async() {
async { }.await;
prop_assert!(true);
}
```

### `#[proptest_dump]`

You can add `#[proptest_dump]` to `#[proptest]` and output the code generated by `#[proptest]` as an compile error message.
Expand Down
34 changes: 32 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
//! }
//! ```
//!
//! ## Helper attributes
//! ## Attributes
//!
//! Helper attributes can be written in the following positions.
//! Attributes can be written in the following positions.
//!
//! | attribute | function | struct | enum | variant | field | function parameter |
//! | --------------------------------------------------- | -------- | ------ | ---- | ------- | ----- | ------------------ |
Expand All @@ -87,6 +87,9 @@
//! | [`#[arbitrary(args = T)]`](#arbitraryargs--t) | | ✔ | ✔ | | | |
//! | [`#[arbitrary(bound(...))]`](#arbitraryboundt1-t2-) | | ✔ | ✔ | ✔ | ✔ | |
//! | [`#[arbitrary(dump)]`](#arbitrarydump) | | ✔ | ✔ | | | |
//! | [`#[proptest]`](#proptest) | ✔ | | | | | |
//! | [`#[proptest(async = ...)]`](#proptestasync--) | ✔ | | | | | |
//! | [`#[proptest_dump]`](#proptest_dump) | ✔ | | | | | |
//!
//! ## `#[derive(Arbitrary)]`
//!
Expand Down Expand Up @@ -626,6 +629,33 @@
//! }
//! ```
//!
//! ### `#[proptest(async = ...)]`
//!
//! Async functions can be tested by setting `async = ...` to the argument of `#[proptest]`.
//!
//! The following values are allowed after `async =`.
//! The value specifies the asynchronous runtime used for the test.
//!
//! - "tokio"
//!
//! ```toml
//! [dev-dependencies]
//! test-strategy = "0.3"
//! proptest = "1.1.0"
//! tokio = { version = "1.28.1", features = ["rt-multi-thread"] }
//! ```
//!
//! ```rust
//! use test_strategy::proptest;
//! use proptest::prop_assert;
//!
//! #[proptest(async = "tokio")]
//! async fn my_test_async() {
//! async { }.await;
//! prop_assert!(true);
//! }
//! ```
//!
//! ### `#[proptest_dump]`
//!
//! You can add `#[proptest_dump]` to `#[proptest]` and output the code generated by `#[proptest]` as an compile error message.
Expand Down

0 comments on commit c492d62

Please sign in to comment.