From a83a9ae9726777019c4a9af926ee99d24c282240 Mon Sep 17 00:00:00 2001 From: Phoeniix Zhao Date: Wed, 5 Jul 2023 14:54:00 +0800 Subject: [PATCH] test: add test case information in abort_on_panic macros Closes: #360 Signed-off-by: Phoeniix Zhao --- test-macros/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-macros/src/lib.rs b/test-macros/src/lib.rs index daeccc94b..45ffa2f56 100644 --- a/test-macros/src/lib.rs +++ b/test-macros/src/lib.rs @@ -5,11 +5,12 @@ use syn::{parse_macro_input, ItemFn, Stmt}; #[proc_macro_attribute] pub fn abort_on_panic(_attr: TokenStream, item: TokenStream) -> TokenStream { let mut input: syn::ItemFn = parse_macro_input!(item as ItemFn); + let test_case = &input.sig.ident.to_string(); let panic_hook: Stmt = syn::parse_quote! { std::panic::set_hook(Box::new(|info| { let stacktrace = std::backtrace::Backtrace::force_capture(); - println!("Got panic.\n@info:\n{}\n@stackTrace:\n{}", info, stacktrace); + println!("`{}` panic! \n@info:\n{}\n@stackTrace:\n{}", #test_case, info, stacktrace); std::process::abort(); })); };