diff --git a/build.rs b/build.rs index e306f08ce..008ec09ab 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,6 @@ extern crate version_check; +use std::env; use version_check::is_min_version; fn main() { @@ -8,4 +9,9 @@ fn main() { if is_min_version("1.30").unwrap_or(false) { println!("cargo:rustc-cfg=has_error_source"); } + + // So we can get the build profile for has_backtrace_depending_on_env test + if let Ok(profile) = env::var("PROFILE") { + println!("cargo:rustc-cfg=build={:?}", profile); + } } diff --git a/src/bin/has_backtrace.rs b/examples/has_backtrace.rs similarity index 100% rename from src/bin/has_backtrace.rs rename to examples/has_backtrace.rs diff --git a/tests/tests.rs b/tests/tests.rs index 5a4b03504..175c3b9c7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -199,13 +199,21 @@ fn empty() { #[test] #[cfg(feature = "backtrace")] fn has_backtrace_depending_on_env() { - use std::path::Path; + use std::path::PathBuf; use std::process::Command; + let cmd_folder = if cfg!(build="debug") { + "debug" + } else if cfg!(build="release") { + "release" + } else { + panic!("Unknown build config"); + }; + let cmd_path = if cfg!(windows) { - Path::new("./target/debug/has_backtrace.exe") + PathBuf::from(format!("./target/{}/examples/has_backtrace.exe", cmd_folder)) } else { - Path::new("./target/debug/has_backtrace") + PathBuf::from(format!("./target/{}/examples/has_backtrace", cmd_folder)) }; let mut cmd = Command::new(cmd_path);