From 9a0e4e0176393d98fb0db23fd1958a9dabd7da0f Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Sun, 3 Nov 2019 20:31:08 +0800 Subject: [PATCH] Ignore expansion test if cargo-expand subcommand isn't present --- test_suite/Cargo.toml | 1 + test_suite/build.rs | 28 ++++++++++++++++++++++++++++ test_suite/tests/expandtest.rs | 1 + 3 files changed, 30 insertions(+) create mode 100644 test_suite/build.rs diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.toml index 5c0bdd8c..1bfecca4 100644 --- a/test_suite/Cargo.toml +++ b/test_suite/Cargo.toml @@ -4,6 +4,7 @@ version = "0.0.0" authors = ["Erick Tryzelaar ", "David Tolnay "] edition = "2018" publish = false +build = "build.rs" [features] unstable = ["serde/unstable"] diff --git a/test_suite/build.rs b/test_suite/build.rs new file mode 100644 index 00000000..eaaabcb2 --- /dev/null +++ b/test_suite/build.rs @@ -0,0 +1,28 @@ +use std::env; +use std::path::PathBuf; + +#[cfg(not(windows))] +const CARGO_EXPAND_BIN: &str = "cargo-expand"; + +#[cfg(windows)] +const CARGO_EXPAND_BIN: &str = "cargo-expand.exe"; + +/// Scans paths in PATH env variable for a presence of `CARGO_EXPAND_BIN` file. +fn is_cargo_expand_present() -> bool { + if let Ok(var) = env::var("PATH") { + for path in var.split(":").map(PathBuf::from) { + let cargo_expand_path = path.join(CARGO_EXPAND_BIN); + if cargo_expand_path.exists() { + return true; + } + } + } + + false +} + +pub fn main() { + if is_cargo_expand_present() { + println!("cargo:rustc-cfg=cargo_expand"); + } +} diff --git a/test_suite/tests/expandtest.rs b/test_suite/tests/expandtest.rs index 790576f9..b51ab054 100644 --- a/test_suite/tests/expandtest.rs +++ b/test_suite/tests/expandtest.rs @@ -1,5 +1,6 @@ #[cfg(not(target_os = "emscripten"))] #[rustversion::attr(not(nightly), ignore)] +#[cfg_attr(not(cargo_expand), ignore)] #[test] fn expandtest() { macrotest::expand("tests/expand/**/enum/*.rs");