Skip to content

Commit

Permalink
Fix file mtime test
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jul 25, 2023
1 parent ce5c917 commit 33c7d85
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crates/ruff_cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,22 @@ mod tests {
test_cache.write_source_file("source.py", source);
assert_eq!(cache.new_files.lock().unwrap().len(), 0);

let expected_diagnostics = test_cache
test_cache
.lint_file_with_cache("source.py", &cache)
.expect("Failed to lint test file");

cache.store().unwrap();
let cache = test_cache.open();

// Write the same contents to the source file (updating the modified time)
test_cache.write_source_file("source.py", source);
// Write new contents to the source file (updating the modified time)
// Note we cannot just write the same content because some file systems will not perform the write
// Once https://doc.rust-lang.org/std/fs/struct.File.html#method.set_modified is stable we can
// just update the modified time without appending content which will allow us to assert that
// the diagnostics have not changed.
let new_content: &[u8] = b"# new content\n";
test_cache.write_source_file("source.py", &[source, new_content].concat());

let got_diagnostics = test_cache
test_cache
.lint_file_with_cache("source.py", &cache)
.expect("Failed to lint test file");

Expand All @@ -528,11 +533,6 @@ mod tests {
1,
"Cache should not be used, the file should be treated as new and added to the cache"
);

assert!(
expected_diagnostics == got_diagnostics,
"The diagnostics should not change"
);
}

#[test]
Expand Down

0 comments on commit 33c7d85

Please sign in to comment.