Skip to content

Commit

Permalink
test: add test case information in abort_on_panic macros
Browse files Browse the repository at this point in the history
Closes: #360
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Jul 5, 2023
1 parent 2adbfde commit a83a9ae
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
};
Expand Down

0 comments on commit a83a9ae

Please sign in to comment.