parent
63acf90044
commit
4fecede7fd
@ -375,21 +375,43 @@ fn idempotence_tests() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run rustfmt on itself. This operation must be idempotent. We also check that
|
||||||
|
// no warnings are emitted.
|
||||||
|
// Issue-3443: these tests require nightly
|
||||||
#[nightly_only_test]
|
#[nightly_only_test]
|
||||||
#[test]
|
#[test]
|
||||||
fn self_tests() {
|
fn self_tests() {
|
||||||
let get_exe_path = |name| {
|
init_log();
|
||||||
let mut path = env::current_exe().unwrap();
|
let mut files = get_test_files(Path::new("tests"), false);
|
||||||
path.pop();
|
let bin_directories = vec!["cargo-fmt", "git-rustfmt", "bin", "format-diff"];
|
||||||
path.set_file_name(format!("{name}{}", env::consts::EXE_SUFFIX));
|
for dir in bin_directories {
|
||||||
path
|
let mut path = PathBuf::from("src");
|
||||||
};
|
path.push(dir);
|
||||||
let status = Command::new(get_exe_path("cargo-fmt"))
|
path.push("main.rs");
|
||||||
.args(["--check", "--all"])
|
files.push(path);
|
||||||
.env("RUSTFMT", get_exe_path("rustfmt"))
|
}
|
||||||
.status()
|
files.push(PathBuf::from("src/lib.rs"));
|
||||||
.unwrap();
|
|
||||||
assert!(status.success());
|
let (reports, count, fails) = check_files(files, &Some(PathBuf::from("rustfmt.toml")));
|
||||||
|
let mut warnings = 0;
|
||||||
|
|
||||||
|
// Display results.
|
||||||
|
println!("Ran {} self tests.", count);
|
||||||
|
assert_eq!(fails, 0, "{} self tests failed", fails);
|
||||||
|
|
||||||
|
for format_report in reports {
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
FormatReportFormatterBuilder::new(&format_report).build()
|
||||||
|
);
|
||||||
|
warnings += format_report.warning_count();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
warnings, 0,
|
||||||
|
"Rustfmt's code generated {} warnings",
|
||||||
|
warnings
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user