Skip to content
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

feat: Run test mod from anywhere in parent file #13045

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

DorianListens
Copy link
Contributor

The "Run" feature of rust-analyzer is super useful, especially for running
individual tests or test-modules during development.

One common pattern in rust development is to develop tests in the same file as
production code, inside a module (usually called test or tests) marked with
#[cfg(test)]. Unforunately, this pattern is not well supported by r-a today,
as a test module won't show up as a runnable unless the cursor is inside it.

In my experience, it is quite common to want to run the tests associated with
some production code immediately after editing it, not only after editing the
tests themselves. As such it would be better if test modules were available
from the "Run" menu even when the cursor is outside the test module.

This change updates the filtration logic for runnables in
handlers::handle_runnables to special case RunnableKind::TestMod, making
test modules available regardless of the cursor location. Other RunnableKinds
are unnaffected.

Fixes #9589

The "Run" feature of rust-analyzer is super useful, especially for running
individual tests or test-modules during development.

One common pattern in rust development is to develop tests in the same file as
production code, inside a module (usually called `test` or `tests`) marked with
`#[cfg(test)]`.  Unforunately, this pattern is not well supported by r-a today,
as a test module won't show up as a runnable unless the cursor is inside it.

In my experience, it is quite common to want to run the tests associated with
some production code immediately after editing it, not only after editing the
tests themselves. As such it would be better if test modules were available
from the "Run" menu even when the cursor is outside the test module.

This change updates the filtration logic for runnables in
`handlers::handle_runnables` to special case `RunnableKind::TestMod`, making
test modules available regardless of the cursor location. Other `RunnableKind`s
are unnaffected.

Fixes rust-lang#9589
@Veykril
Copy link
Member

Veykril commented Aug 18, 2022

sounds good to me 👍
@bors r+

@bors
Copy link
Collaborator

bors commented Aug 18, 2022

📌 Commit 85b9568 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Aug 18, 2022

⌛ Testing commit 85b9568 with merge 1d36aba...

@bors
Copy link
Collaborator

bors commented Aug 18, 2022

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 1d36aba to master...

@bors bors merged commit 1d36aba into rust-lang:master Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] extend "Rust Analyzer: Run" to include test-mod when _outside_ mod tests
3 participants