diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | test/Cargo.lock | 8 | ||||
| -rw-r--r-- | test/Cargo.toml | 2 | ||||
| -rw-r--r-- | test/no_metadata/Cargo.toml | 11 | ||||
| -rw-r--r-- | test/no_metadata/src/lib.rs | 2 | ||||
| -rw-r--r-- | test/src/test_fallback.rs | 54 |
6 files changed, 81 insertions, 3 deletions
@@ -1,7 +1,7 @@ -.PHONY: check clippy check-lock test-crate test-sync test-async expand fmt-expand lock doc +.PHONY: check clippy check-lock test-crate test-sync test-async test-no-metadata expand fmt-expand lock doc # make check -check: clippy expand fmt-expand test-crate test-sync test-async check-lock +check: clippy expand fmt-expand test-crate test-sync test-async test-no-metadata check-lock # make doc doc: @@ -27,6 +27,9 @@ test-sync: test-async: cargo test -p might_be_async_test_async --features metadata_async --manifest-path test/Cargo.toml +test-no-metadata: + cargo test -p might_be_async_test_fallback --features async --manifest-path test/Cargo.toml + expand: python3 scripts/expand_codes.py diff --git a/test/Cargo.lock b/test/Cargo.lock index 5d4be76..2e65476 100644 --- a/test/Cargo.lock +++ b/test/Cargo.lock @@ -137,6 +137,14 @@ dependencies = [ ] [[package]] +name = "might_be_async_test_fallback" +version = "0.1.0" +dependencies = [ + "futures", + "might_be_async", +] + +[[package]] name = "might_be_async_test_sync" version = "0.1.0" dependencies = [ diff --git a/test/Cargo.toml b/test/Cargo.toml index b92b54b..68a4698 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["sync", "async"] +members = ["sync", "async", "no_metadata"] resolver = "2" diff --git a/test/no_metadata/Cargo.toml b/test/no_metadata/Cargo.toml new file mode 100644 index 0000000..e228ecb --- /dev/null +++ b/test/no_metadata/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "might_be_async_test_fallback" +version = "0.1.0" +edition = "2024" + +[features] +async = [] + +[dependencies] +might_be_async = { path = "../.." } +futures = "0.3" diff --git a/test/no_metadata/src/lib.rs b/test/no_metadata/src/lib.rs new file mode 100644 index 0000000..abe379d --- /dev/null +++ b/test/no_metadata/src/lib.rs @@ -0,0 +1,2 @@ +#![allow(unused)] +include!("../../src/test_fallback.rs"); diff --git a/test/src/test_fallback.rs b/test/src/test_fallback.rs new file mode 100644 index 0000000..1f729fb --- /dev/null +++ b/test/src/test_fallback.rs @@ -0,0 +1,54 @@ +#[might_be_async::func] +fn fallback_id(x: i32) -> i32 { + x +} + +#[cfg(not(feature = "async"))] +#[test] +fn test_fallback_func_sync() { + assert_eq!(fallback_id(42), 42); +} + +#[cfg(feature = "async")] +#[test] +fn test_fallback_func_async() { + let r = futures::executor::block_on(fallback_id(42)); + assert_eq!(r, 42); +} + +#[cfg(not(feature = "async"))] +#[test] +fn test_fallback_select_implicit_sync() { + let r = might_be_async::select! { { 1 } else { 2 } }; + assert_eq!(r, 2); +} + +#[cfg(feature = "async")] +#[test] +fn test_fallback_select_implicit_async() { + let r = might_be_async::select! { { 1 } else { 2 } }; + assert_eq!(r, 1); +} + +#[cfg(not(feature = "async"))] +fn fallback_double(x: i32) -> i32 { + x * 2 +} + +#[cfg(feature = "async")] +async fn fallback_double(x: i32) -> i32 { + x * 2 +} + +#[cfg(not(feature = "async"))] +#[test] +fn test_fallback_invoke_sync() { + assert_eq!(might_be_async::invoke!(fallback_double(5)), 10); +} + +#[cfg(feature = "async")] +#[test] +fn test_fallback_invoke_async() { + let r = futures::executor::block_on(async { might_be_async::invoke!(fallback_double(5)) }); + assert_eq!(r, 10); +} |
