Skip to content

Conversation

@MichaReiser
Copy link
Member

Summary

This PR introduces a new mdtest option system that can either be in-memory or os
where in-memory is the default.

The motivation for supporting os is so that we can write OS/system specific tests
with 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"

@MichaReiser MichaReiser force-pushed the micha/mdtest-os-system branch from cf2929f to ebb484a Compare March 5, 2025 13:01
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Mar 5, 2025
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"), "")])
Copy link
Member Author

@MichaReiser MichaReiser Mar 5, 2025

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.

Copy link
Contributor

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.

@MichaReiser MichaReiser force-pushed the micha/mdtest-os-system branch from ebb484a to 72c7c23 Compare March 5, 2025 13:30
@MichaReiser MichaReiser force-pushed the micha/case-sensitive-module-resolver-tests branch 4 times, most recently from aebf24a to ad5e00e Compare March 5, 2025 13:49
@MichaReiser MichaReiser force-pushed the micha/mdtest-os-system branch 6 times, most recently from a57bb2f to edcb9e6 Compare March 5, 2025 14:31
@MichaReiser MichaReiser marked this pull request as ready for review March 5, 2025 14:38
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

use crate::ProjectMetadata;
use ruff_db::files::system_path_to_file;
use ruff_db::system::{DbWithTestSystem, SystemPathBuf};
use ruff_db::system::{DbWithWritableSystem as _, SystemPathBuf};
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not technically needed but it only makes the trait available in the module without importing it by name. That means you can call all the extension methods without binding the name locally.

/// ## 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<()> {
Copy link
Contributor

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.

Copy link
Member Author

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.

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"), "")])
Copy link
Contributor

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.

Base automatically changed from micha/case-sensitive-module-resolver-tests to main March 6, 2025 09:19
@MichaReiser MichaReiser force-pushed the micha/mdtest-os-system branch from edcb9e6 to 38e8267 Compare March 6, 2025 09:33
@MichaReiser MichaReiser merged commit ce0018c into main Mar 6, 2025
21 checks passed
@MichaReiser MichaReiser deleted the micha/mdtest-os-system branch March 6, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants