Skip to content

Commit 37c4b11

Browse files
committed
lintcheck: add test
1 parent 7be3a32 commit 37c4b11

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

clippy_dev/src/lintcheck.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
503503
/// check if the latest modification of the logfile is older than the modification date of the
504504
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
505505
fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
506+
if !lintcheck_logs_path.exists() {
507+
return true;
508+
}
509+
506510
let clippy_modified: std::time::SystemTime = {
507511
let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| {
508512
std::fs::metadata(p)
@@ -665,7 +669,6 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
665669
let file_content: String = match std::fs::read_to_string(file_path).ok() {
666670
Some(content) => content,
667671
None => {
668-
eprintln!("RETURND");
669672
return HashMap::new();
670673
},
671674
};
@@ -734,3 +737,30 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
734737
println!("{} {} => 0", old_key, old_value);
735738
});
736739
}
740+
741+
#[test]
742+
fn lintcheck_test() {
743+
let args = [
744+
"run",
745+
"--target-dir",
746+
"clippy_dev/target",
747+
"--package",
748+
"clippy_dev",
749+
"--bin",
750+
"clippy_dev",
751+
"--manifest-path",
752+
"clippy_dev/Cargo.toml",
753+
"--features",
754+
"lintcheck",
755+
"--",
756+
"lintcheck",
757+
"--crates-toml",
758+
"clippy_dev/test_sources.toml",
759+
];
760+
let status = std::process::Command::new("cargo")
761+
.args(&args)
762+
.current_dir("../" /* repo root */)
763+
.status();
764+
765+
assert!(status.unwrap().success());
766+
}

clippy_dev/test_sources.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[crates]
2+
cc = {name = "cc", versions = ['1.0.67']}
3+
home = {name = "home", git_url = "https://github.com/brson/home", git_hash = "32044e53dfbdcd32bafad3109d1fbab805fc0f40"}
4+
rustc_tools_util = {name = "rustc_tools_util", versions = ['0.2.0']}

0 commit comments

Comments
 (0)