mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Fix stale File status in tests (#15030)
## Summary Fixes https://github.com/astral-sh/ruff/issues/15027 The `MemoryFileSystem::write_file` API automatically creates non-existing ancestor directoryes but we failed to update the status of the now created ancestor directories in the `Files` data structure. ## Test Plan Tested that the case in https://github.com/astral-sh/ruff/issues/15027 now passes regardless of whether the *Simple* case is commented out or not
This commit is contained in:
parent
7c2e7cf25e
commit
dcb99cc817
3 changed files with 25 additions and 10 deletions
|
@ -73,6 +73,15 @@ enum SystemOrVendoredPathRef<'a> {
|
|||
Vendored(&'a VendoredPath),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SystemOrVendoredPathRef<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
SystemOrVendoredPathRef::System(system) => system.fmt(f),
|
||||
SystemOrVendoredPathRef::Vendored(vendored) => vendored.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the module for the file with the given id.
|
||||
///
|
||||
/// Returns `None` if the file is not a module locatable via any of the known search paths.
|
||||
|
|
|
@ -124,7 +124,6 @@ pub(crate) fn infer_definition_types<'db>(
|
|||
let file = definition.file(db);
|
||||
let _span = tracing::trace_span!(
|
||||
"infer_definition_types",
|
||||
definition = ?definition.as_id(),
|
||||
range = ?definition.kind(db).range(),
|
||||
file = %file.path(db)
|
||||
)
|
||||
|
|
|
@ -175,19 +175,26 @@ pub trait DbWithTestSystem: Db + Sized {
|
|||
///
|
||||
/// # Panics
|
||||
/// If the system isn't using the memory file system.
|
||||
fn write_file(
|
||||
&mut self,
|
||||
path: impl AsRef<SystemPath>,
|
||||
content: impl ToString,
|
||||
) -> crate::system::Result<()> {
|
||||
fn write_file(&mut self, path: impl AsRef<SystemPath>, content: impl ToString) -> Result<()> {
|
||||
let path = path.as_ref();
|
||||
let result = self
|
||||
.test_system()
|
||||
.memory_file_system()
|
||||
.write_file(path, content);
|
||||
|
||||
let memory_fs = self.test_system().memory_file_system();
|
||||
|
||||
let sync_ancestors = path
|
||||
.parent()
|
||||
.is_some_and(|parent| !memory_fs.exists(parent));
|
||||
let result = memory_fs.write_file(path, content);
|
||||
|
||||
if result.is_ok() {
|
||||
File::sync_path(self, path);
|
||||
|
||||
// Sync the ancestor paths if the path's parent
|
||||
// directory didn't exist before.
|
||||
if sync_ancestors {
|
||||
for ancestor in path.ancestors() {
|
||||
File::sync_path(self, ancestor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue