-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Run Test
and Debug
execute the code in different working directories
#4705
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
Comments
cc @vsrs I think we should always execute the code with cwd set to the worksapce_root. |
At the moment |
Hm, turns out it is not so easy. Both commands correctly set cwd to So we just see how Cargo works with virtual workspaces:
So it is Cargo who sets cwd for metadata-34fd8c2a238a9d90. I think the root is here: And looks like there is no way to control this behavior and better not to use cwd in tests at all.
|
I'm unable to reproduce it. It seems it was fixed. |
I confirm this issue fixed with the same situation of @balintbalazs .
|
I'm getting this issue on vscode/nixos. Personally it seems like the |
I'm still affected by this. The behavior is exactly the same as described in the OP.
|
I have the same issue as well. Makes relative paths in tests very complicated. |
Workaround cargo launch configuration to emulate the debug link in a workspace, with correct {
"type": "lldb",
"request": "launch",
"name": "Cargo test test-file-name",
"cargo": {
"args": [
"test",
"-p",
"workspace-package-name",
"--test",
"test-file-name",
"--no-run"
],
"filter": { "name": "test-file-name" }
},
"program": "${cargo:program}",
"args": ["--nocapture"],
"cwd": "${workspaceFolder}/crates/workspace-package-name"
}, Needs to be configured per test, so Resources |
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
{
"rust-analyzer.runnableEnv": {
"ENV_ROOT_DIR": "${workspaceFolder}"
}
}
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()
}
}
}
|
In certain cases the vscode
Run Test
andDebug
buttons execute the code in different working directories.In this example I have a workspace in the
C:\Dev\rust\rust-project
folder, and a crate inside calledmetadata
.For this test in
C:\Dev\rust\rust-project\metadata\lib.rs
:when clicking
Run Test
I get the following output:But when clicking the
Debug
option it prints:This behavior can be fairly inconvenient when the test code needs to read some files, so it would be great if it would be consistent.
Thanks!
The text was updated successfully, but these errors were encountered: