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

reopen Run Test and Debug execute the code in different working directories #13208

Open
dnut opened this issue Sep 8, 2022 · 5 comments
Open
Labels
A-vscode vscode plugin issues C-bug Category: bug

Comments

@dnut
Copy link

dnut commented Sep 8, 2022

There is already an issue for this but it was closed by mistake and I am unable to reopen it. Several people have replied that the issue was not fixed and yet it remains closed.

#4705

@johannescpk
Copy link

Also related: #6661

@Veykril Veykril added the C-bug Category: bug label Feb 9, 2023
@d00z3l
Copy link

d00z3l commented May 10, 2023

I have struggled with the same issue, I wanted to use a relative path for a source file for my tests and have it work using run/debug in VS Code and also using cargo test --all. My workaround is as follows:

  1. Create a local settings.json file, i.e. ./.vscode/settings.json
  2. Add the following to the settings file:
{
    "rust-analyzer.runnableEnv": {
        "ENV_ROOT_DIR": "${workspaceFolder}"
    }
}
  1. Create a test function create the path:
    pub fn test_data_path() -> String {
        static FILE_PATH : &str = "./tests/my-file-name.csv";
        match std::env::var("ENV_ROOT_DIR") {
            Ok(path) => {
                Path::new(&path).join(FILE_PATH).display().to_string()
            },
            Err(_) => {
                Path::new(&std::env::current_dir().unwrap()).join("../").join(FILE_PATH).display().to_string()
            }
        }
    }

ENV_ROOT_DIR is used in VS Code and the working directory for cargo test

@Marwes
Copy link

Marwes commented Jun 20, 2023

Also seeing this issue, Run Test seems to correctly execute the test in ./WORKSPACE/PACKAGE whereas Run Debug executes in ./WORKSPACE

@tanveerbadar
Copy link

The work-around @d00z3l mentioned works, for the time being until the issue is really fixed.

@kriswuollett
Copy link

If test cases are run from same workspace as they are compiled, then for a workaround perhaps using env!("CARGO_MANIFEST_DIR") as the relative directory reference point may be a more direct and stable workaround under refactoring crate location conditions.

@Veykril Veykril added the A-vscode vscode plugin issues label Jul 30, 2023
bors added a commit that referenced this issue Aug 15, 2023
Add status bar button to toggle check on save state

Closes #15440
cc #13208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vscode vscode plugin issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

7 participants