Skip to content

Commit ddb4456

Browse files
authored
Merge pull request #476 from proptest-rs/attr-macro-doc
add doc comment to attr macro. Fixes #473
2 parents ca308b0 + ebafcc6 commit ddb4456

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

proptest-macro/src/lib.rs

+46
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@ use proc_macro::TokenStream;
22

33
mod property_test;
44

5+
/// The `property_test` procedural macro simplifies the creation of property-based tests
6+
/// using the `proptest` crate. This macro provides a more concise syntax for writing tests
7+
/// that automatically generate test cases based on properties.
8+
///
9+
/// # Example
10+
///
11+
/// Using the `property_test` macro:
12+
///
13+
/// ```
14+
/// #[property_test]
15+
/// fn foo(x: i32) {
16+
/// assert_eq!(x, x);
17+
/// }
18+
/// ```
19+
///
20+
/// is roughly equivalent to:
21+
///
22+
/// ```
23+
/// proptest! {
24+
/// #[test]
25+
/// fn foo(x in any::<i32>()) {
26+
/// assert_eq!(x, x);
27+
/// }
28+
/// }
29+
/// ```
30+
///
31+
/// # Details
32+
///
33+
/// The `property_test` macro is used to define property-based tests, where the parameters
34+
/// of the test function are automatically generated by `proptest`. The macro takes care
35+
/// of setting up the test harness and generating input values, allowing the user to focus
36+
/// on writing the test logic.
37+
///
38+
/// # Attributes
39+
///
40+
/// The `property_test` macro can take an optional `config` attribute, which allows you to
41+
/// customize the configuration of the `proptest` runner.
42+
///
43+
/// E.g. running 100 cases:
44+
///
45+
/// ```rust
46+
/// #[property_test(config = "ProptestConfig { cases: 100, .. ProptestConfig::default() }")]
47+
/// fn foo(x: i32) {
48+
/// assert_eq!(x, x);
49+
/// }
50+
/// ```
551
#[proc_macro_attribute]
652
pub fn property_test(attr: TokenStream, item: TokenStream) -> TokenStream {
753
property_test::property_test(attr.into(), item.into()).into()

0 commit comments

Comments
 (0)