diff options
Diffstat (limited to 'vendor/maybe-async/tests')
16 files changed, 501 insertions, 0 deletions
diff --git a/vendor/maybe-async/tests/test.rs b/vendor/maybe-async/tests/test.rs new file mode 100644 index 000000000..4062e39dc --- /dev/null +++ b/vendor/maybe-async/tests/test.rs @@ -0,0 +1,15 @@ +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.pass("tests/ui/01-maybe-async.rs"); + t.pass("tests/ui/02-must-be-async.rs"); + t.pass("tests/ui/03-must-be-sync.rs"); + t.pass("tests/ui/04-unit-test-util.rs"); + t.pass("tests/ui/05-replace-future-generic-type-with-output.rs"); + t.pass("tests/ui/06-sync_impl_async_impl.rs"); + + t.compile_fail("tests/ui/test_fail/01-empty-test.rs"); + t.compile_fail("tests/ui/test_fail/02-unknown-path.rs"); + t.compile_fail("tests/ui/test_fail/03-async-gt2.rs"); + t.compile_fail("tests/ui/test_fail/04-bad-sync-cond.rs"); +} diff --git a/vendor/maybe-async/tests/ui/01-maybe-async.rs b/vendor/maybe-async/tests/ui/01-maybe-async.rs new file mode 100644 index 000000000..33b8248e5 --- /dev/null +++ b/vendor/maybe-async/tests/ui/01-maybe-async.rs @@ -0,0 +1,81 @@ +#![allow(dead_code)] + +use maybe_async::maybe_async; + +#[maybe_async(Send)] +trait Trait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async(?Send)] +pub trait PubTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async] +pub(crate) trait PubCrateTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async] +async fn async_fn() {} + +#[maybe_async] +pub async fn pub_async_fn() {} + +#[maybe_async] +pub(crate) async fn pub_crate_async_fn() {} + +#[maybe_async] +unsafe fn unsafe_fn() {} + +struct Struct; + +#[maybe_async] +impl Trait for Struct { + fn sync_fn() {} + + async fn declare_async(&self) {} + + async fn async_fn(&self) { + async { self.declare_async().await }.await + } +} + +#[cfg(feature = "is_sync")] +fn main() -> std::result::Result<(), ()> { + let s = Struct; + s.declare_async(); + s.async_fn(); + async_fn(); + pub_async_fn(); + Ok(()) +} + +#[cfg(not(feature = "is_sync"))] +#[async_std::main] +async fn main() { + let s = Struct; + s.declare_async().await; + s.async_fn().await; + async_fn().await; + pub_async_fn().await; +} diff --git a/vendor/maybe-async/tests/ui/02-must-be-async.rs b/vendor/maybe-async/tests/ui/02-must-be-async.rs new file mode 100644 index 000000000..cfe2285b8 --- /dev/null +++ b/vendor/maybe-async/tests/ui/02-must-be-async.rs @@ -0,0 +1,96 @@ +#![allow(dead_code)] + +#[maybe_async::maybe_async] +trait Trait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async::maybe_async(?Send)] +trait NotSendTrait { + async fn declare_async_not_send(&self); + + async fn async_fn_not_send(&self) { + self.declare_async_not_send().await + } +} + +#[maybe_async::maybe_async] +pub trait PubTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async::maybe_async] +pub(crate) trait PubCrateTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::must_be_async] +async fn async_fn() {} + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::must_be_async] +pub async fn pub_async_fn() {} + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::maybe_async] +pub(crate) async fn pub_crate_async_fn() {} + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::maybe_async] +unsafe fn unsafe_fn() {} + +struct Struct; + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::must_be_async] +impl Trait for Struct { + fn sync_fn() {} + + async fn declare_async(&self) {} + + async fn async_fn(&self) { + async { self.declare_async().await }.await + } +} + +#[cfg(not(feature = "is_sync"))] +#[maybe_async::must_be_async(?Send)] +impl NotSendTrait for Struct { + async fn declare_async_not_send(&self) {} + + async fn async_fn_not_send(&self) { + async { self.declare_async_not_send().await }.await + } +} + +#[cfg(feature = "is_sync")] +fn main() {} + +#[cfg(not(feature = "is_sync"))] +#[async_std::main] +async fn main() { + let s = Struct; + s.declare_async().await; + s.async_fn().await; + async_fn().await; + pub_async_fn().await; +} diff --git a/vendor/maybe-async/tests/ui/03-must-be-sync.rs b/vendor/maybe-async/tests/ui/03-must-be-sync.rs new file mode 100644 index 000000000..94fa30fc6 --- /dev/null +++ b/vendor/maybe-async/tests/ui/03-must-be-sync.rs @@ -0,0 +1,74 @@ +#![allow(dead_code)] + +#[maybe_async::maybe_async] +trait Trait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async::maybe_async] +pub trait PubTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async::maybe_async] +pub(crate) trait PubCrateTrait { + fn sync_fn() {} + + async fn declare_async(&self); + + async fn async_fn(&self) { + self.declare_async().await + } +} + +#[maybe_async::maybe_async] +async fn async_fn() {} + +#[maybe_async::maybe_async] +pub async fn pub_async_fn() {} + +#[maybe_async::maybe_async] +pub(crate) async fn pub_crate_async_fn() {} + +#[maybe_async::maybe_async] +unsafe fn unsafe_fn() {} + +struct Struct; + +#[cfg(feature = "is_sync")] +#[maybe_async::must_be_sync] +impl Trait for Struct { + fn sync_fn() {} + + async fn declare_async(&self) {} + + async fn async_fn(&self) { + async { self.declare_async().await }.await + } +} + +#[cfg(feature = "is_sync")] +fn main() -> std::result::Result<(), ()> { + let s = Struct; + s.declare_async(); + s.async_fn(); + async_fn(); + pub_async_fn(); + Ok(()) +} + +#[cfg(not(feature = "is_sync"))] +#[async_std::main] +async fn main() {} diff --git a/vendor/maybe-async/tests/ui/04-unit-test-util.rs b/vendor/maybe-async/tests/ui/04-unit-test-util.rs new file mode 100644 index 000000000..4642e1f84 --- /dev/null +++ b/vendor/maybe-async/tests/ui/04-unit-test-util.rs @@ -0,0 +1,38 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +#[maybe_async::test( +feature = "is_sync", +async(all(not(feature="is_sync"), feature = "async_std"), async_std::test), +async(all(not(feature="is_sync"), feature = "tokio"), tokio::test) +)] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test(feature = "is_sync", async(not(feature = "is_sync"), async_std::test))] +async fn test_async_fn2() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test("feature=\"is_sync\"", async(not(feature = "is_sync"), async_std::test))] +async fn test_async_fn3() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test(feature = "is_sync", async("not(feature = \"is_sync\")", "async_std::test"))] +async fn test_async_fn4() { + let res = async_fn().await; + assert_eq!(res, true); +} + +fn main() { + +} diff --git a/vendor/maybe-async/tests/ui/05-replace-future-generic-type-with-output.rs b/vendor/maybe-async/tests/ui/05-replace-future-generic-type-with-output.rs new file mode 100644 index 000000000..241058069 --- /dev/null +++ b/vendor/maybe-async/tests/ui/05-replace-future-generic-type-with-output.rs @@ -0,0 +1,34 @@ +#![allow(unused_imports)] +use std::future::Future; + +#[maybe_async::maybe_async] +pub async fn with_fn<T, F: Sync + std::future::Future<Output = Result<(), ()>>>( + test: T, +) -> Result<(), ()> + where + T: FnOnce() -> F, +{ + test().await +} + +#[maybe_async::maybe_async] +pub async fn with_fn_where<T, F>(test: T) -> Result<(), ()> + where + T: FnOnce() -> F, + F: Sync + Future<Output = Result<(), ()>>, +{ + test().await +} + +#[maybe_async::sync_impl] +fn main() { + with_fn(|| Ok(())).unwrap(); + with_fn_where(|| Ok(())).unwrap(); +} + +#[maybe_async::async_impl] +#[tokio::main] +async fn main() { + with_fn(|| async { Ok(()) }).await.unwrap(); + with_fn_where(|| async { Ok(()) }).await.unwrap(); +} diff --git a/vendor/maybe-async/tests/ui/06-sync_impl_async_impl.rs b/vendor/maybe-async/tests/ui/06-sync_impl_async_impl.rs new file mode 100644 index 000000000..68605faa0 --- /dev/null +++ b/vendor/maybe-async/tests/ui/06-sync_impl_async_impl.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused_variables)] + +/// InnerClient differ a lot between sync and async. +#[maybe_async::maybe_async] +trait Trait { + async fn maybe_async_fn(); +} + +/// The higher level API for end user. +pub struct Struct; + +/// Synchronous implementation, only compiles when `is_sync` feature is off. +/// Else the compiler will complain that *request is defined multiple times* and +/// blabla. +#[maybe_async::sync_impl] +impl Trait for Struct { + fn maybe_async_fn() { } +} + +/// Asynchronous implementation, only compiles when `is_sync` feature is off. +#[maybe_async::async_impl] +impl Trait for Struct { + async fn maybe_async_fn() { } +} + +impl Struct { + #[maybe_async::maybe_async] + async fn another_maybe_async_fn() { + Self::maybe_async_fn().await + // When `is_sync` is toggle on, this block will compiles to: + // Self::maybe_async_fn() + } +} + +#[maybe_async::sync_impl] +fn main() { + let _ = Struct::another_maybe_async_fn(); +} + +#[maybe_async::async_impl] +#[tokio::main] +async fn main() { + let _ = Struct::another_maybe_async_fn().await; +} diff --git a/vendor/maybe-async/tests/ui/test_fail/01-empty-test.rs b/vendor/maybe-async/tests/ui/test_fail/01-empty-test.rs new file mode 100644 index 000000000..f409e7334 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/01-empty-test.rs @@ -0,0 +1,17 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +// at least one sync condition should be specified +#[maybe_async::test()] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +fn main() { + +} diff --git a/vendor/maybe-async/tests/ui/test_fail/01-empty-test.stderr b/vendor/maybe-async/tests/ui/test_fail/01-empty-test.stderr new file mode 100644 index 000000000..b90d9ee35 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/01-empty-test.stderr @@ -0,0 +1,7 @@ +error: Arguments cannot be empty, at least specify the condition for sync code + --> tests/ui/test_fail/01-empty-test.rs:9:1 + | +9 | #[maybe_async::test()] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `maybe_async::test` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.rs b/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.rs new file mode 100644 index 000000000..7b79bd1f2 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.rs @@ -0,0 +1,17 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +// should only accept `async` +#[maybe_async::test(feature="is_sync", unknown(not(feature="is_sync"), async_std::test))] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +fn main() { + +} diff --git a/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.stderr b/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.stderr new file mode 100644 index 000000000..6a603c01d --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/02-unknown-path.stderr @@ -0,0 +1,5 @@ +error: Unknown path: `unknown`, must be `async` + --> tests/ui/test_fail/02-unknown-path.rs:9:40 + | +9 | #[maybe_async::test(feature="is_sync", unknown(not(feature="is_sync"), async_std::test))] + | ^^^^^^^ diff --git a/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.rs b/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.rs new file mode 100644 index 000000000..f7313bd52 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.rs @@ -0,0 +1,16 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +#[maybe_async::test(feature="is_sync", async(feature="async", async_std::test, added))] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +fn main() { + +} diff --git a/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.stderr b/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.stderr new file mode 100644 index 000000000..8c051da85 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/03-async-gt2.stderr @@ -0,0 +1,5 @@ +error: Must pass two metas or string literals like `async(condition, async_test_macro)`, you passed 3 metas. + --> tests/ui/test_fail/03-async-gt2.rs:8:40 + | +8 | #[maybe_async::test(feature="is_sync", async(feature="async", async_std::test, added))] + | ^^^^^ diff --git a/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.rs b/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.rs new file mode 100644 index 000000000..f5ad658a4 --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.rs @@ -0,0 +1,17 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +// bad sync condition +#[maybe_async::test(unknown(feature="async", async_std::test))] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +fn main() { + +}
\ No newline at end of file diff --git a/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.stderr b/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.stderr new file mode 100644 index 000000000..97294ffcc --- /dev/null +++ b/vendor/maybe-async/tests/ui/test_fail/04-bad-sync-cond.stderr @@ -0,0 +1,5 @@ +error[E0537]: invalid predicate `unknown` + --> tests/ui/test_fail/04-bad-sync-cond.rs:9:21 + | +9 | #[maybe_async::test(unknown(feature="async", async_std::test))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/vendor/maybe-async/tests/unit-test-util.rs b/vendor/maybe-async/tests/unit-test-util.rs new file mode 100644 index 000000000..486fa6e1b --- /dev/null +++ b/vendor/maybe-async/tests/unit-test-util.rs @@ -0,0 +1,30 @@ +use maybe_async::maybe_async; + +#[maybe_async] +async fn async_fn() -> bool { + true +} + +#[maybe_async::test(feature = "is_sync", async(not(feature = "is_sync"), async_std::test))] +async fn test_async_fn() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test(feature = "is_sync", async(not(feature = "is_sync"), tokio::test))] +async fn test_async_fn2() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test(feature = "is_sync")] +async fn test_async_fn3() { + let res = async_fn().await; + assert_eq!(res, true); +} + +#[maybe_async::test(feature = "is_sync")] +async fn test_sync_fn() { + let res = async_fn(); + assert_eq!(res, true); +} |