2021-09-08 13:19:14 +00:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
|
|
|
|
2019-12-22 21:49:59 +00:00
|
|
|
use std::path::PathBuf;
|
2019-07-28 04:41:25 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2019-06-25 04:43:38 +00:00
|
|
|
#[test]
|
|
|
|
fn fmt() {
|
2020-02-07 21:24:41 +00:00
|
|
|
if option_env!("RUSTC_TEST_SUITE").is_some() || option_env!("NO_FMT_TEST").is_some() {
|
2019-06-25 04:43:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:01:08 +00:00
|
|
|
// Skip this test if nightly rustfmt is unavailable
|
2021-11-20 00:43:31 +00:00
|
|
|
let rustup_output = Command::new("rustup").args(&["component", "list"]).output().unwrap();
|
2019-07-28 04:41:25 +00:00
|
|
|
assert!(rustup_output.status.success());
|
|
|
|
let component_output = String::from_utf8_lossy(&rustup_output.stdout);
|
|
|
|
if !component_output.contains("rustfmt") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-22 21:49:59 +00:00
|
|
|
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
2019-07-28 04:41:25 +00:00
|
|
|
let output = Command::new("cargo")
|
2020-08-25 03:53:28 +00:00
|
|
|
.current_dir(root_dir)
|
|
|
|
.args(&["dev", "fmt", "--check"])
|
2019-06-25 04:43:38 +00:00
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("status: {}", output.status);
|
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
|
|
|
|
2019-06-26 04:08:33 +00:00
|
|
|
assert!(
|
|
|
|
output.status.success(),
|
2020-01-30 07:33:48 +00:00
|
|
|
"Formatting check failed. Run `cargo dev fmt` to update formatting."
|
2019-06-26 04:08:33 +00:00
|
|
|
);
|
2019-06-25 04:43:38 +00:00
|
|
|
}
|