aboutsummaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-23 23:28:53 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-23 23:28:53 +0800
commitb8705f97fc3ef32ec98d3f77a8ccd28decbbaf50 (patch)
tree9c82ca453b8348844f131cf06d8519687c5a8417 /test/src
parentf9f879e488a62eba9c54c8e713cc94cc9f20e96e (diff)
feat(test): add fallback test crate for no-metadata buildsHEADmain
Add `might_be_async_test_fallback` crate in `test/no_metadata/` to verify macro behavior when the `metadata_async` feature is absent, covering sync/async select, invoke, and bare func attributes
Diffstat (limited to 'test/src')
-rw-r--r--test/src/test_fallback.rs54
1 files changed, 54 insertions, 0 deletions
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);
+}