-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OsSystem
support to mdtests
#16518
base: micha/case-sensitive-module-resolver-tests
Are you sure you want to change the base?
Add OsSystem
support to mdtests
#16518
Conversation
cf2929f
to
ebb484a
Compare
@@ -321,7 +321,7 @@ mod tests { | |||
|
|||
system | |||
.memory_file_system() | |||
.write_files([(root.join("foo.py"), ""), (root.join("bar.py"), "")]) | |||
.write_files_all([(root.join("foo.py"), ""), (root.join("bar.py"), "")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very fond of this name. The MemoryFileSystem::write_files
and write_file
methods used to create any missing directories. This is inconsistent with what other systems do but is very convenient in tests.
That's why I renamed the existing write_files
and write_file
methods to write_files_all
and write_file_all
(in resemblence of create_dir_all
) and created a new write_file
method that errors when the parent directory doesn't exist. However, I don't think it's a very good name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other options that come to mind are significantly more verbose; write_files_mkdirs
, write_files_with_parents
... I think write_files_all
is OK.
ebb484a
to
72c7c23
Compare
aebf24a
to
ad5e00e
Compare
a60c6a1
to
a57bb2f
Compare
a57bb2f
to
edcb9e6
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -255,7 +255,7 @@ mod tests { | |||
use crate::files::Index; | |||
use crate::ProjectMetadata; | |||
use ruff_db::files::system_path_to_file; | |||
use ruff_db::system::{DbWithTestSystem, SystemPathBuf}; | |||
use ruff_db::system::{DbWithWritableSystem as _, SystemPathBuf}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the as _
needed here?
/// ## Panics | ||
/// If the db isn't using the [`InMemorySystem`]. | ||
fn write_file(&mut self, path: impl AsRef<SystemPath>, content: impl ToString) -> Result<()> { | ||
fn write_file(&mut self, path: impl AsRef<SystemPath>, content: impl AsRef<str>) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the naming adjustments throughout this PR, I'm confused why a method named write_file
explicitly creates all parent directories here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's fair. The thinking was that this trait is only used for testing where this seems the right default. But I can see how it is confusing in the bigger picture.
@@ -321,7 +321,7 @@ mod tests { | |||
|
|||
system | |||
.memory_file_system() | |||
.write_files([(root.join("foo.py"), ""), (root.join("bar.py"), "")]) | |||
.write_files_all([(root.join("foo.py"), ""), (root.join("bar.py"), "")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other options that come to mind are significantly more verbose; write_files_mkdirs
, write_files_with_parents
... I think write_files_all
is OK.
let db = Self { | ||
project_root, | ||
Self { | ||
system: MdtestSystem::in_memory(SystemPathBuf::from("/")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever create an MdtestSystem
with any cwd other than /
? Should that just be built-in?
in_memory.fs().remove_all(); | ||
} | ||
MdtestSystemInner::Os { .. } => { | ||
self.system = MdtestSystem::in_memory(SystemPathBuf::from("/")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems surprising at first that "resetting" a real fs just means throwing it away and replacing it with an in-memory fs. But I guess it makes sense.
pub(crate) fn with_tempdir_fs(&mut self, cwd: SystemPathBuf, temp_dir: TempDir) { | ||
self.system.with_os(cwd, temp_dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the with_*
naming is surprising for methods that mutate in-place; that name strongly suggests an immutable builder pattern where self
is cloned and the updated one is returned. (Because in that case the method name describes the returned object.)
For in-place mutation I would expect e.g. set_tempdir_fs
and set_os
instead.
pub(crate) fn project_root(&self) -> &SystemPath { | ||
&self.project_root | ||
pub(crate) fn reset_fs(&mut self) { | ||
match &*self.system.0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe delegate to a self.system.reset_fs()
instead of digging so much into MdTestSystem
internals from outside?
Summary
This PR introduces a new mdtest option
system
that can either bein-memory
oros
where
in-memory
is the default.The motivation for supporting
os
is so that we can write OS/system specific testswith mdtests. Specifically, I want to write mdtests for the module resolver,
testing that module resolution is case sensitive.
Test Plan
I tested that the case-sensitive module resolver test start failing when setting
system = "os"