rust-lang / rust-lang/rust-analyzer

Failed to "Run Test": run Cargo from wrong folder

Open
#11,834 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

summary

IDE: vscode
Analyzer Version: v0.2.993
A. No run commands are shown in the rust subfile, e.g. "Run test". Does this file have to be depended on?
B. The analyzer fails to run command in subfiles, such as test command.

Build test environment

> cargo new example
> cd example
example > cargo new --lib crates/worker

files structure

example > tree -I target
.
├── Cargo.lock
├── Cargo.toml
├── crates
│   └── worker
│       ├── Cargo.toml
│       └── src
│           └── lib.rs
└── src
    └── main.rs

4 directories, 5 files

lib.rs

// example > cat crates/worker/src/lib.rs
#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        let result = 2 + 2;
        assert_eq!(result, 4);
    }
}

Issue A

Open the folder example in vscode, but no run commands are shown in the rust crates/worker/src/lib.rs.

It appears after modifying dependencies.

Raw Cargo.toml:

# example > cat Cargo.toml 
[package]
name = "example"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Add dependencies:

# example > cat Cargo.toml 
[package]
name = "example"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
worker = {path = "crates/worker"}

Now, I can run command "Run Test" in crates/worker/src/lib.rs.
But it fails.

Issue B

The analyzer fails to run command "Run Test" in crates/worker/src/lib.rs.
This is similar to issue #7764.

Result:

> Executing task: cargo test -- tests::it_works --exact --nocapture <

error: could not find `Cargo.toml` in `/` or any parent directory
The terminal process "cargo 'test', '--', 'tests::it_works', '--exact', '--nocapture'" failed to launch (exit code: 101).

Terminal will be reused by tasks, press any key to close it.

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 report by opening the example workspace in VS Code, inspecting crates/worker/src/lib.rs, and using its Run Test command. Compare the workspace layout and Cargo.toml files with the generated cargo test task and its working directory. Done means tests in the subcrate expose the command and run successfully without the Cargo.toml error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.