1 #![cfg(not(miri))]
2 #![warn(rust_2018_idioms, single_use_lifetimes)]
3
4 use std::{
5 env,
6 process::{Command, ExitStatus, Stdio},
7 };
8
9 const PATH: &str = "tests/expand/**/*.rs";
10
11 #[rustversion::attr(not(nightly), ignore)]
12 #[test]
expandtest()13 fn expandtest() {
14 let is_ci = env::var_os("CI").is_some();
15 let cargo = &*env::var("CARGO").unwrap_or_else(|_| "cargo".into());
16 if !has_command(&[cargo, "expand"]) || !has_command(&[cargo, "fmt"]) {
17 if is_ci {
18 panic!("expandtest requires rustfmt and cargo-expand");
19 }
20 return;
21 }
22
23 let args = &["--all-features"];
24 if is_ci {
25 macrotest::expand_without_refresh_args(PATH, args);
26 } else {
27 env::set_var("MACROTEST", "overwrite");
28 macrotest::expand_args(PATH, args);
29 }
30 }
31
has_command(command: &[&str]) -> bool32 fn has_command(command: &[&str]) -> bool {
33 Command::new(command[0])
34 .args(&command[1..])
35 .arg("--version")
36 .stdin(Stdio::null())
37 .stdout(Stdio::null())
38 .stderr(Stdio::null())
39 .status()
40 .as_ref()
41 .map(ExitStatus::success)
42 .unwrap_or(false)
43 }
44