From 26394f827fa80c059d5109664ca95d0b0be46831 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Tue, 15 Oct 2019 19:02:15 +0100 Subject: [PATCH 1/2] Move has_backtrace out of test and into examples --- {src/bin => examples}/has_backtrace.rs | 0 tests/tests.rs | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename {src/bin => examples}/has_backtrace.rs (100%) 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 26bf0366a..3767e92c3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -204,9 +204,9 @@ fn has_backtrace_depending_on_env() { use std::path::Path; let cmd_path = if cfg!(windows) { - Path::new("./target/debug/has_backtrace.exe") + Path::new("./target/debug/examples/has_backtrace.exe") } else { - Path::new("./target/debug/has_backtrace") + Path::new("./target/debug/examples/has_backtrace") }; let mut cmd = Command::new(cmd_path); From aa001e62ba5c68d9819a4b12640bb6d619645665 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Tue, 15 Oct 2019 21:45:53 +0100 Subject: [PATCH 2/2] Fix has_backtrace_depending_on_env path for release builds --- build.rs | 6 ++++++ tests/tests.rs | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) 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/tests/tests.rs b/tests/tests.rs index 3767e92c3..c85ec2db9 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -201,12 +201,20 @@ fn empty() { #[cfg(feature = "backtrace")] fn has_backtrace_depending_on_env() { use std::process::Command; - use std::path::Path; + use std::path::PathBuf; + + 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/examples/has_backtrace.exe") + PathBuf::from(format!("./target/{}/examples/has_backtrace.exe", cmd_folder)) } else { - Path::new("./target/debug/examples/has_backtrace") + PathBuf::from(format!("./target/{}/examples/has_backtrace", cmd_folder)) }; let mut cmd = Command::new(cmd_path);