diff --git a/.travis.yml b/.travis.yml index 92e06704..2e342262 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: rust sudo: false dist: trusty rust: -- 1.32.0 +- 1.40.0 - stable - beta - nightly diff --git a/appveyor.yml b/appveyor.yml index fc3f8283..a2a05114 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,7 +4,7 @@ environment: - TARGET: nightly-i686-pc-windows-msvc - TARGET: nightly-x86_64-pc-windows-gnu - TARGET: nightly-i686-pc-windows-gnu - - TARGET: 1.32.0-x86_64-pc-windows-gnu + - TARGET: 1.40.0-x86_64-pc-windows-gnu install: - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe" - ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null diff --git a/proptest/CHANGELOG.md b/proptest/CHANGELOG.md index 768fe4e1..90b35f94 100644 --- a/proptest/CHANGELOG.md +++ b/proptest/CHANGELOG.md @@ -1,3 +1,11 @@ +## Unreleased + +### New Features + +- The `proptest!` macro can now be used with `async fn` tests, such as + tests that use the `tokio::test` or `async_std::test` attributes from + those respective crates. + ## 0.10.1 ### New Features diff --git a/proptest/Cargo.toml b/proptest/Cargo.toml index f6acfd83..5ae3b91b 100644 --- a/proptest/Cargo.toml +++ b/proptest/Cargo.toml @@ -125,3 +125,4 @@ optional = true [dev-dependencies] regex = "1.0" +tokio = { version = "0.3.1", features = ["macros", "rt"] } diff --git a/proptest/src/sugar.rs b/proptest/src/sugar.rs index 6dfcf5c7..cd8bb452 100644 --- a/proptest/src/sugar.rs +++ b/proptest/src/sugar.rs @@ -164,6 +164,23 @@ macro_rules! proptest { } )* }; + + (#![proptest_config($config:expr)] + $( + $(#[$meta:meta])* + async fn $test_name:ident($($parm:pat in $strategy:expr),+ $(,)?) $body:block + )*) => { + $( + $(#[$meta])* + async fn $test_name() { + let mut config = $config.clone(); + config.test_name = Some( + concat!(module_path!(), "::", stringify!($test_name))); + $crate::proptest_helper!(@_BODY config ($($parm in $strategy),+) [] $body); + } + )* + }; + (#![proptest_config($config:expr)] $( $(#[$meta:meta])* @@ -180,6 +197,22 @@ macro_rules! proptest { )* }; + (#![proptest_config($config:expr)] + $( + $(#[$meta:meta])* + async fn $test_name:ident($($arg:tt)+) $body:block + )*) => { + $( + $(#[$meta])* + async fn $test_name() { + let mut config = $config.clone(); + config.test_name = Some( + concat!(module_path!(), "::", stringify!($test_name))); + $crate::proptest_helper!(@_BODY2 config ($($arg)+) [] $body); + } + )* + }; + ($( $(#[$meta:meta])* fn $test_name:ident($($parm:pat in $strategy:expr),+ $(,)?) $body:block @@ -189,6 +222,15 @@ macro_rules! proptest { fn $test_name($($parm in $strategy),+) $body)* } }; + ($( + $(#[$meta:meta])* + async fn $test_name:ident($($parm:pat in $strategy:expr),+ $(,)?) $body:block + )*) => { $crate::proptest! { + #![proptest_config($crate::test_runner::Config::default())] + $($(#[$meta])* + async fn $test_name($($parm in $strategy),+) $body)* + } }; + ($( $(#[$meta:meta])* fn $test_name:ident($($arg:tt)+) $body:block @@ -198,6 +240,15 @@ macro_rules! proptest { fn $test_name($($arg)+) $body)* } }; + ($( + $(#[$meta:meta])* + async fn $test_name:ident($($arg:tt)+) $body:block + )*) => { $crate::proptest! { + #![proptest_config($crate::test_runner::Config::default())] + $($(#[$meta])* + async fn $test_name($($arg)+) $body)* + } }; + (|($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { $crate::proptest!( $crate::test_runner::Config::default(), @@ -1206,6 +1257,14 @@ mod test { } } + proptest! { + #[tokio::test] + async fn test_something_async(a in 0u32..42u32, b in 1u32..10u32) { + prop_assume!(a != 41 || b != 9); + assert!(a + b < 50); + } + } + prop_compose! { #[allow(dead_code)] fn single_closure_is_move(base: u64)(off in 0..10u64) -> u64 {