rust-lang / rust-lang/rust-analyzer

Run test/debug not working in dependent Crate tests in VSCode

Open
#13,409 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I have:

project/
   Cargo.toml
   libs/dep/
      Cargo.toml
      src/lib.rs  

project/Cargo.toml:

[package]
edition = "2021"
name = "placeholder"
version = "0.1.0"

[dependencies]
mydep = { path = "libs/dep" }

If I open libs/dep/ as a separate VSCode project & run a test in src/lib.rs everything works as expected. If I open project/ instead and then try to run a test from libs/dep/src/lib.rs, it fails:

  1. If I click "Debug test", it prints "could not find Cargo.toml in /home/vlovich or any parent directory"
  2. If I click "Run test", it runs the test command (Executing task: cargo test -- --exact --nocapture) but I think it's in the project/ folder instead of project/libs/dep because it builds but finds 0 tests to run and it lists "placeholder" as the package that was built.

Ideally I think rust-analyzer would scan up from the current file to find the directory of the Cargo.toml instead of assuming it's the workspace root.

rust-analyzer version: Tried & failed in the same way on 0.4.1242, 0.4.1237, and 0.3.1238. I saw #13404 but this looks like a different issue since it's still present on stable.

rustc version: rustc 1.64.0 (a55dd71d5 2022-09-19)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

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 project/Cargo.toml, libs/dep/Cargo.toml, and libs/dep/src/lib.rs open from the workspace root. Compare the Run test and Debug test commands and their working directories for the dependent crate. Done means both commands locate the dependency crate and execute its selected test rather than the root package.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.