From c492d62a5128cf837ef350f8e83dc72bfe1e7cd0 Mon Sep 17 00:00:00 2001 From: frozenlib Date: Sat, 15 Jul 2023 15:45:25 +0900 Subject: [PATCH] Add docuemnt for `#[proptest(async = ...)]`. --- README.md | 34 ++++++++++++++++++++++++++++++++-- src/lib.rs | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1336b1e..7264707 100644 --- a/README.md +++ b/README.md @@ -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 | | --------------------------------------------------- | -------- | ------ | ---- | ------- | ----- | ------------------ | @@ -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)]` @@ -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. diff --git a/src/lib.rs b/src/lib.rs index 02979e4..a0cffda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 | //! | --------------------------------------------------- | -------- | ------ | ---- | ------- | ----- | ------------------ | @@ -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)]` //! @@ -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.