Skip to content

Commit

Permalink
fix(pallet-benchmarking): split test functions in v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Mar 5, 2024
1 parent c34ad77 commit 0944d5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion substrate/frame/benchmarking/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ macro_rules! impl_bench_name_tests {
// Same per-case logic as when all cases are run in the
// same function.
match std::panic::catch_unwind(|| {
$module::<$test>::[< test_benchmark_ $name >] ()
$module::<$test>::test_bench_by_name(stringify!($name).as_bytes())
}) {
Err(err) => {
panic!("{}: {:?}", stringify!($name), err);
Expand Down
25 changes: 25 additions & 0 deletions substrate/frame/support/procedural/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,29 @@ pub fn benchmarks(
benchmarks_by_name_mappings.push(quote!(#name_str => Self::#test_ident()))
}

let impl_test_function = if let Some(item) = content.iter_mut().find(|item| matches!(item, Item::Macro(_))) {
let Item::Macro(item_macro) = item else {
return Err(syn::Error::new(item.span(), "Expected an item macro, as found such item"));
};

if item_macro
.mac
.path
.segments
.iter()
.any(|s| s.ident == "impl_benchmark_test_suite")
{
let tokens = item_macro.mac.tokens.clone();
*item = Item::Verbatim(quote! {});

quote! { impl_test_function!((#( {} #benchmark_names )*)()()#tokens); }
} else {
quote! {}
}
} else {
quote! {}
};

// emit final quoted tokens
let res = quote! {
#(#mod_attrs)
Expand Down Expand Up @@ -676,6 +699,8 @@ pub fn benchmarks(
}
}
}

#impl_test_function
}
#mod_vis use #mod_name::*;
};
Expand Down

0 comments on commit 0944d5d

Please sign in to comment.