Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Automatically handle `async` in `#[wasmtime_test]` (#12405)

Alex Crichtonf70298c80eab
diff --git a/crates/test-macros/src/wasmtime_test.rs b/crates/test-macros/src/wasmtime_test.rs
index d77e98e887..baeb695810 100644
--- a/crates/test-macros/src/wasmtime_test.rs
+++ b/crates/test-macros/src/wasmtime_test.rs
@@ -51,8 +51,6 @@ use wasmtime_test_util::wast::Compiler;
struct TestConfig {
strategies: Vec<Compiler>,
flags: wasmtime_test_util::wast::TestConfig,
- /// The test attribute to use. Defaults to `#[test]`.
- test_attribute: Option<proc_macro2::TokenStream>,
}
impl TestConfig {
@@ -113,12 +111,6 @@ impl TestConfig {
Ok(())
}
-
- fn test_attribute_from(&mut self, meta: &ParseNestedMeta) -> Result<()> {
- let v: syn::LitStr = meta.value()?.parse()?;
- self.test_attribute = Some(v.value().parse()?);
- Ok(())
- }
}
impl Default for TestConfig {
@@ -130,7 +122,6 @@ impl Default for TestConfig {
Compiler::CraneliftPulley,
],
flags: Default::default(),
- test_attribute: None,
}
}
}
@@ -204,8 +195,6 @@ pub fn run(attrs: TokenStream, item: TokenStream) -> TokenStream {
test_config.strategies_from(&meta)
} else if meta.path.is_ident("wasm_features") {
test_config.wasm_features_from(&meta)
- } else if meta.path.is_ident("with") {
- test_config.test_attribute_from(&meta)
} else {
Err(meta.error("Unsupported attributes"))
}
@@ -223,10 +212,11 @@ fn expand(test_config: &TestConfig, func: Fn) -> Result<TokenStream> {
let mut tests = vec![quote! { #func }];
let attrs = &func.attrs;
- let test_attr = test_config
- .test_attribute
- .clone()
- .unwrap_or_else(|| quote! { #[test] });
+ let test_attr = if func.sig.asyncness.is_some() {
+ quote! { #[tokio::test] }
+ } else {
+ quote! { #[test] }
+ };
for strategy in &test_config.strategies {
let strategy_name = format!("{strategy:?}");
diff --git a/tests/all/epoch_interruption.rs b/tests/all/epoch_interruption.rs
index ec1dbb0d6b..6a1c1ff7bb 100644
--- a/tests/all/epoch_interruption.rs
+++ b/tests/all/epoch_interruption.rs
@@ -79,7 +79,7 @@ async fn run_and_count_yields_or_trap<F: Fn(Arc<Engine>)>(
Ok(result.ok().map(|_| (yields, *store)))
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_yield_at_func_entry(config: &mut Config) -> Result<()> {
// Should yield at start of call to func $subfunc.
assert_eq!(
@@ -103,7 +103,7 @@ async fn epoch_yield_at_func_entry(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_yield_at_loop_header(config: &mut Config) -> Result<()> {
// Should yield at top of loop, once per five iters.
assert_eq!(
@@ -129,7 +129,7 @@ async fn epoch_yield_at_loop_header(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_yield_immediate(config: &mut Config) -> Result<()> {
// We should see one yield immediately when the initial deadline
// is zero.
@@ -151,7 +151,7 @@ async fn epoch_yield_immediate(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_yield_only_once(config: &mut Config) -> Result<()> {
// We should yield from the subfunction, and then when we return
// to the outer function and hit another loop header, we should
@@ -183,7 +183,7 @@ async fn epoch_yield_only_once(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_interrupt_infinite_loop(config: &mut Config) -> Result<()> {
assert_eq!(
None,
@@ -210,7 +210,7 @@ async fn epoch_interrupt_infinite_loop(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_interrupt_function_entries(config: &mut Config) -> Result<()> {
assert_eq!(
None,
@@ -334,7 +334,7 @@ async fn epoch_interrupt_function_entries(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_callback_continue(config: &mut Config) -> Result<()> {
assert_eq!(
Some((0, 1)),
@@ -361,7 +361,7 @@ async fn epoch_callback_continue(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_callback_yield(config: &mut Config) -> Result<()> {
assert_eq!(
Some((1, 1)),
@@ -389,7 +389,7 @@ async fn epoch_callback_yield(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_callback_yield_custom(config: &mut Config) -> Result<()> {
assert_eq!(
Some((1, 1)),
@@ -417,7 +417,7 @@ async fn epoch_callback_yield_custom(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn epoch_callback_trap(config: &mut Config) -> Result<()> {
assert_eq!(
None,
@@ -440,7 +440,7 @@ async fn epoch_callback_trap(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(with = "#[tokio::test]")]
+#[wasmtime_test]
async fn drop_future_on_epoch_yield(config: &mut Config) -> Result<()> {
let wasm = "
(module