lintcheck: add test

This commit is contained in:
Matthias Krüger 2021-03-04 22:33:22 +01:00
parent 7be3a32f25
commit 37c4b11a84
2 changed files with 35 additions and 1 deletions

View file

@ -503,6 +503,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
/// check if the latest modification of the logfile is older than the modification date of the /// check if the latest modification of the logfile is older than the modification date of the
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck /// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool { fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
if !lintcheck_logs_path.exists() {
return true;
}
let clippy_modified: std::time::SystemTime = { let clippy_modified: std::time::SystemTime = {
let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| { let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| {
std::fs::metadata(p) std::fs::metadata(p)
@ -665,7 +669,6 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
let file_content: String = match std::fs::read_to_string(file_path).ok() { let file_content: String = match std::fs::read_to_string(file_path).ok() {
Some(content) => content, Some(content) => content,
None => { None => {
eprintln!("RETURND");
return HashMap::new(); return HashMap::new();
}, },
}; };
@ -734,3 +737,30 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
println!("{} {} => 0", old_key, old_value); println!("{} {} => 0", old_key, old_value);
}); });
} }
#[test]
fn lintcheck_test() {
let args = [
"run",
"--target-dir",
"clippy_dev/target",
"--package",
"clippy_dev",
"--bin",
"clippy_dev",
"--manifest-path",
"clippy_dev/Cargo.toml",
"--features",
"lintcheck",
"--",
"lintcheck",
"--crates-toml",
"clippy_dev/test_sources.toml",
];
let status = std::process::Command::new("cargo")
.args(&args)
.current_dir("../" /* repo root */)
.status();
assert!(status.unwrap().success());
}

View file

@ -0,0 +1,4 @@
[crates]
cc = {name = "cc", versions = ['1.0.67']}
home = {name = "home", git_url = "https://github.com/brson/home", git_hash = "32044e53dfbdcd32bafad3109d1fbab805fc0f40"}
rustc_tools_util = {name = "rustc_tools_util", versions = ['0.2.0']}