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

[neotest] support test file for files without a single test module #623

Open
1 task
mrcjkb opened this issue Dec 18, 2024 · 2 comments
Open
1 task

[neotest] support test file for files without a single test module #623

mrcjkb opened this issue Dec 18, 2024 · 2 comments
Labels
enhancement New feature or request needs triage

Comments

@mrcjkb
Copy link
Owner

mrcjkb commented Dec 18, 2024

Feature description

For files without a test module, or with multiple test modules, testFile could potentially be supported by

  • Filtering the rust-analyzer testables buy entries that are in the file
    • check if this is doable without too much complexity
  • Construct a test command for all the entries
@mrcjkb mrcjkb added enhancement New feature or request needs triage labels Dec 18, 2024
@roycrippen4
Copy link

I found that running cargo +nightly test -- --list -Zunstable-options --format=json yields a json table that has exactly the data needed for this.

// $ cargo +nightly test -- --list -Zunstable-options --format=json
[
  {
    "type": "test",
    "event": "discovered",
    "name": "tests::it_works",
    "ignore": false,
    "ignore_message": "",
    "source_path": "src/lib.rs",
    "start_line": 40,
    "start_col": 8,
    "end_line": 40,
    "end_col": 16
  }
]

Benefits:

  • Solves the test discovery process in a simple way
  • Provides a useful json response to stdout
  • Filters out all files that do not contain tests
  • Json response includes documentation testing
  • Json response includes integration testing

Caveats:

  • Requires the nightly rust compiler to be installed on the system
  • Nightly (probably) would need to be recompiled each time there is an update to rustc's master branch

Note that nightly is only used transiently and does not become your default compiler

It would be trivial to close out this issue using this command, however I'm not sure if the trade-off is worth it.
Here's a repo I made for testing.

@mrcjkb
Copy link
Owner Author

mrcjkb commented Jan 26, 2025

@roycrippen4 thanks for the input.
That sounds like a good approach. But I would definitely want to wait for the feature to stabilize.
Perhaps the extra info will be added to the rust-analyzer experimental/runnables response schema then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage
Projects
None yet
Development

No branches or pull requests

2 participants