diff --git a/src/lib.rs b/src/lib.rs index 90c7f53..c5c5fe8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,34 +95,48 @@ pub struct Metadata { #[macro_export] macro_rules! setup_panic { ($meta:expr) => { + #[allow(unused_imports)] use std::panic::{self, PanicInfo}; + #[allow(unused_imports)] use $crate::{handle_dump, print_msg, Metadata}; - panic::set_hook(Box::new(move |info: &PanicInfo| { - let file_path = handle_dump(&$meta, info); - - print_msg(file_path, &$meta) - .expect("human-panic: printing error message to console failed"); - })); + #[cfg(not(debug_assertions))] + match ::std::env::var("RUST_BACKTRACE") { + Err(_) => { + panic::set_hook(Box::new(move |info: &PanicInfo| { + let file_path = handle_dump(&$meta, info); + print_msg(file_path, &$meta) + .expect("human-panic: printing error message to console failed"); + })); + } + Ok(_) => {} + } }; () => { + #[allow(unused_imports)] use std::panic::{self, PanicInfo}; + #[allow(unused_imports)] use $crate::{handle_dump, print_msg, Metadata}; - let meta = Metadata { - version: env!("CARGO_PKG_VERSION").into(), - name: env!("CARGO_PKG_NAME").into(), - authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), - homepage: env!("CARGO_PKG_HOMEPAGE").into(), - }; - - panic::set_hook(Box::new(move |info: &PanicInfo| { - let file_path = handle_dump(&meta, info); - - print_msg(file_path, &meta) - .expect("human-panic: printing error message to console failed"); - })); + #[cfg(not(debug_assertions))] + match ::std::env::var("RUST_BACKTRACE") { + Err(_) => { + let meta = Metadata { + version: env!("CARGO_PKG_VERSION").into(), + name: env!("CARGO_PKG_NAME").into(), + authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), + homepage: env!("CARGO_PKG_HOMEPAGE").into(), + }; + + panic::set_hook(Box::new(move |info: &PanicInfo| { + let file_path = handle_dump(&meta, info); + print_msg(file_path, &meta) + .expect("human-panic: printing error message to console failed"); + })); + } + Ok(_) => {} + } }; } diff --git a/tests/custom-panic/tests/integration.rs b/tests/custom-panic/tests/integration.rs index 7fc8e2b..199fc09 100644 --- a/tests/custom-panic/tests/integration.rs +++ b/tests/custom-panic/tests/integration.rs @@ -1,8 +1,8 @@ extern crate assert_cli; #[test] -fn integration() { - assert_cli::Assert::main_binary() +fn release() { + assert_cli::Assert::command(&["cargo", "run", "--release"]) .stderr() .contains("custom-panic-test") .stderr() @@ -14,3 +14,12 @@ fn integration() { .fails_with(101) .unwrap(); } + +#[test] +fn debug() { + assert_cli::Assert::command(&["cargo", "run"]) + .stderr() + .contains("OMG EVERYTHING IS ON FIRE!!!") + .fails_with(101) + .unwrap(); +} diff --git a/tests/single-panic/tests/integration.rs b/tests/single-panic/tests/integration.rs index b242e22..e2b629d 100644 --- a/tests/single-panic/tests/integration.rs +++ b/tests/single-panic/tests/integration.rs @@ -1,8 +1,8 @@ extern crate assert_cli; #[test] -fn integration() { - assert_cli::Assert::main_binary() +fn release() { + assert_cli::Assert::command(&["cargo", "run", "--release"]) .stderr() .contains("single-panic-test") .stderr() @@ -12,3 +12,12 @@ fn integration() { .fails_with(101) .unwrap(); } + +#[test] +fn debug() { + assert_cli::Assert::command(&["cargo", "run"]) + .stderr() + .contains("OMG EVERYTHING IS ON FIRE!!!") + .fails_with(101) + .unwrap(); +}