rust-lang / rust-lang/rust-analyzer

`Run Doctest` button runs other tests with similar names

Open
#20,643 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have this code:

pub struct Struct;

impl Struct {
    ///```
    /// assert!(true);
    /// ```
    pub fn hello() {}
    ///```
    /// assert!(true);
    /// ```
    pub fn hello_world() {}
}

Pressing Run Doctest button above hello functions runs both hello and hello_world. Non-doc tests don't do this.

Run Doctest runs them with: cargo test --doc --package playground --all-features -- Struct::hello --show-output while Run Test button runs them with: cargo test --package playground --lib --all-features -- test::hello --exact --show-output.

As far as I can tell, difference is --exact, but it I was unable to make it work with doctest. Thanks to this issue I was ablt to run this specific test using cargo test --doc --package playground --all-features 'Struct::hello\ (\line\ 758)' -- --show-output. Note the need for test name escaping with '', whitespace escaping with \ and specified line.

I think this should be a default behavior, as it is in Run Test button.

I am ready to work on this issue if someone is willing to give me a direction.

rust-analyzer version: 0.3.2593
rustc version: 1.91.0-nightly
editor or extension: VSCode

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown Struct, then trace the command construction behind the Run Doctest button and compare it with the Run Test command. Confirm how doctest names are selected and escaped; done means running the button above hello executes only hello, not hello_world.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.