rust-clippy/tests/fmt.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

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() {
if option_env!("RUSTC_TEST_SUITE").is_some() {
return;
}
2019-07-28 04:41:25 +00:00
// Skip this test if rustup nightly is unavailable
let rustup_output = Command::new("rustup")
.args(&["component", "list", "--toolchain", "nightly"])
.output()
.unwrap();
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-06-25 04:43:38 +00:00
let dev_dir = root_dir.join("clippy_dev");
let target_dir = root_dir.join("target");
let target_dir = target_dir.to_str().unwrap();
2019-07-28 04:41:25 +00:00
let output = Command::new("cargo")
2019-06-25 04:43:38 +00:00
.current_dir(dev_dir)
.args(&["+nightly", "run", "--target-dir", target_dir, "--", "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(),
"Formatting check failed. Run `./util/dev fmt` to update formatting."
);
2019-06-25 04:43:38 +00:00
}