Skip to content

Commit 6a5f5b0

Browse files
committed
tests: apply should_ignore beforehand in purge_caches tests
1 parent 0cf9d2a commit 6a5f5b0

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

tests/integration/purge_caches.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ fn test_purge_caches() -> Result<(), Error> {
4949

5050
/// Define which files should be ignored when comparing the two workspaces. If there are expected
5151
/// changes, update the function to match them.
52-
fn should_ignore(base: &Path, path: &Path) -> bool {
52+
fn should_compare(base: &Path, path: &Path) -> bool {
5353
let components = match path.strip_prefix(base) {
5454
Ok(stripped) => stripped
5555
.components()
5656
.map(|component| component.as_os_str().to_string_lossy().to_string())
5757
.collect::<Vec<_>>(),
58-
Err(_) => return false,
58+
Err(_) => return true,
5959
};
6060

6161
let components = components.iter().map(|c| c.as_str()).collect::<Vec<_>>();
6262
match components.as_slice() {
6363
// The indexes could be updated during the build. The index is not considered a cache
6464
// though, so it's fine to ignore it during the comparison.
65-
["cargo-home", "registry", "index", _, ".git", ..] => true,
66-
["cargo-home", "registry", "index", _, ".cargo-index-lock"] => true,
67-
["cargo-home", "registry", "index", _, ".last-updated"] => true,
65+
["cargo-home", "registry", "index", _, ".git", ..] => false,
66+
["cargo-home", "registry", "index", _, ".cargo-index-lock"] => false,
67+
["cargo-home", "registry", "index", _, ".last-updated"] => false,
6868

69-
_ => false,
69+
_ => true,
7070
}
7171
}
7272

@@ -80,7 +80,10 @@ impl WorkspaceContents {
8080
fn collect(path: &Path) -> Result<Self, Error> {
8181
let mut files = HashMap::new();
8282

83-
for entry in walkdir::WalkDir::new(path) {
83+
for entry in walkdir::WalkDir::new(path)
84+
.into_iter()
85+
.filter_entry(|entry| should_compare(path, entry.path()))
86+
{
8487
let entry = entry?;
8588
let metadata = entry.metadata()?;
8689

@@ -103,10 +106,6 @@ impl WorkspaceContents {
103106
println!("=== start directory differences ===");
104107

105108
for (path, start_digest) in self.files.into_iter() {
106-
if should_ignore(&self.base, &path) {
107-
continue;
108-
}
109-
110109
if let Some(end_digest) = other.files.remove(&path) {
111110
if start_digest != end_digest {
112111
println!("file {} changed its size", path.display());
@@ -119,10 +118,6 @@ impl WorkspaceContents {
119118
}
120119

121120
for (path, _) in other.files.into_iter() {
122-
if should_ignore(&other.base, &path) {
123-
continue;
124-
}
125-
126121
println!("file {} was added", path.display());
127122
same = false;
128123
}

0 commit comments

Comments
 (0)