Ignore expansion test if cargo-expand subcommand isn't present

This commit is contained in:
Evgenii P 2019-11-03 20:31:08 +08:00
parent 640f8e0e82
commit 9a0e4e0176
3 changed files with 30 additions and 0 deletions

View File

@ -4,6 +4,7 @@ version = "0.0.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
publish = false
build = "build.rs"
[features]
unstable = ["serde/unstable"]

28
test_suite/build.rs Normal file
View File

@ -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");
}
}

View File

@ -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");