我有一些創建/讀取/寫入/洗掉檔案的測驗,并且我總是在每個測驗中使用相同的檔案名,因此我需要按順序運行它們以避免同時對同一檔案進行操作。在命令列中我可以這樣做
cargo test -- --test-threads=1
但是在 VSCode 運行/除錯選單中,它似乎不起作用。我將自動生成的配置與 Rust Analyzer 一起使用,以及這些額外的引數用于順序運行。
這是我的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'my-project'",
"cargo": {
"args": [
"build",
"--bin=my-project",
"--package=my-project"
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'my-project'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin my-project",
"--package my-project",
"--", // here I've added the arguments
"--test-threads=1", // here I've added the arguments
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
這是我在運行第二個命令(呼叫的命令cargo test)時得到的輸出:
Running `cargo test --no-run --bin my-project --package my-project --message-format=json -- --test-threads=1`...
error: Found argument '--bin my-project' which wasn't expected, or isn't valid in this context
Did you mean '--bin'?
If you tried to supply `--bin my-project` as a value rather than a flag, use `-- --bin my-project`
USAGE:
cargo.exe test --no-run --bin [<NAME>]
For more information try --help
uj5u.com熱心網友回復:
VSCode 使用兩步流程:
- 它呼叫
cargo test --no-run編譯測驗可執行檔案和 - 它直接呼叫測驗可執行檔案。
您應該放入--test-threads=1最后一個args陣列:
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'my-project'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=my-project",
"--package=my-project",
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [ "--test-threads=1" ],
"cwd": "${workspaceFolder}"
}
uj5u.com熱心網友回復:
每個引數應該是陣列中的一個條目。-- --test-threads=1由兩個引陣列成:--和--test-threads=1。因此,您需要陣列中的兩個條目。
這也適用于--bin my-project和--package my-project。他們的另一個解決方案就像在第一個條目中一樣,使用--bin=my-projectand --package=my-project。
"args": [
"test",
"--no-run",
"--bin",
"my-project",
"--package",
"my-project",
"--",
"--test-threads=1",
],
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/477573.html
