Skip to content

Commit 4df43c4

Browse files
committed
Initial migration to wasmtime_test
This commit introduces the initial migration to the `wasmtime_test` macro. This change starts by migrating all the applicable `func.rs` integration tests and at the same time it removes all the duplicated integration tests in `winch.rs`. Additionally, this change introduces a slight change to how the macro works. Inspired by bytecodealliance#8622 (review) it defaults to including all the known configuration combinations and allows the macro user to opt-out where applicable. This makes the usage of the macro less verbose. The intention is to follow-up with subsequent PRs to migrate the all the applicable tests.
1 parent b7aacfc commit 4df43c4

File tree

3 files changed

+121
-335
lines changed

3 files changed

+121
-335
lines changed

crates/test-macros/src/lib.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Ok(())
1212
//! }
1313
use proc_macro::TokenStream;
14+
use proc_macro2::Span;
1415
use quote::{quote, ToTokens, TokenStreamExt};
1516
use syn::{
1617
braced,
@@ -21,7 +22,7 @@ use syn::{
2122
/// Test configuration.
2223
struct TestConfig {
2324
/// Supported compiler strategies.
24-
strategies: Vec<(String, Ident)>,
25+
strategies: Vec<Ident>,
2526
}
2627

2728
impl TestConfig {
@@ -43,7 +44,12 @@ impl TestConfig {
4344

4445
impl Default for TestConfig {
4546
fn default() -> Self {
46-
Self { strategies: vec![] }
47+
Self {
48+
strategies: vec![
49+
Ident::new("Cranelift", Span::call_site()),
50+
Ident::new("Winch", Span::call_site()),
51+
],
52+
}
4753
}
4854
}
4955

@@ -115,12 +121,18 @@ pub fn wasmtime_test(attrs: TokenStream, item: TokenStream) -> TokenStream {
115121
let config_parser = syn::meta::parser(|meta| {
116122
if meta.path.is_ident("strategies") {
117123
meta.parse_nested_meta(|meta| {
118-
if meta.path.is_ident("Winch") || meta.path.is_ident("Cranelift") {
119-
let id = meta.path.require_ident()?.clone();
120-
test_config.strategies.push((id.to_string(), id));
121-
Ok(())
124+
if meta.path.is_ident("not") {
125+
meta.parse_nested_meta(|meta| {
126+
if meta.path.is_ident("Winch") || meta.path.is_ident("Cranelift") {
127+
let id = meta.path.require_ident()?.clone();
128+
test_config.strategies.retain(|s| *s != id);
129+
Ok(())
130+
} else {
131+
Err(meta.error("Unknown strategy"))
132+
}
133+
})
122134
} else {
123-
Err(meta.error("Unknown strategy"))
135+
Err(meta.error("Unknown identifier"))
124136
}
125137
})?;
126138

@@ -142,7 +154,8 @@ fn expand(test_config: &TestConfig, func: Fn) -> Result<TokenStream> {
142154
let mut tests = vec![quote! { #func }];
143155
let attrs = &func.attrs;
144156

145-
for (strategy_name, ident) in &test_config.strategies {
157+
for ident in &test_config.strategies {
158+
let strategy_name = ident.to_string();
146159
// Winch currently only offers support for x64.
147160
let target = if strategy_name == "Winch" {
148161
quote! { #[cfg(target_arch = "x86_64")] }

0 commit comments

Comments
 (0)