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