golang / golang/vscode-go

codelens: a way to use selected launch.json configuration in run test | debug test

Open
#855 10 comments 21 reactions 0 assignees View on GitHub
Debug debug/config
Dominant language
TypeScript
Stars
4.3k
Forks
929
PR merge metrics
No merged PRs in 30d

Description

Users complain that the handy `run test | debug test` links above their test functions ignore the flags they set in their launch configuration ([example](https://github.com/microsoft/vscode-go/issues/2894), [example](https://github.com/go-delve/delve/issues/496#issuecomment-653627364), [example](https://github.com/golang/vscode-go/issues/1450#issuecomment-832409441)). They can fallback on [`settings.json`](https://github.com/golang/vscode-go/blob/master/docs/settings.md) using `go.testFlags`, `go.delveConfig`, etc, but that is not obvious or intuitive and has surprised users with additional limitations for `debug test` vs `run test` (e.g. #1636, https://github.com/microsoft/vscode-go/issues/2894#issuecomment-554303825, https://github.com/microsoft/vscode-go/issues/2115#issuecomment-438137710).

According to @ramya-rao-a, a while back there was no way to feed current selected launch configuration into the codelens, so another set of dlv-related settings was supported as an alternative. Since then a new mechanism to support this could have been introduced, so we should investigate what is possible now.

Below is a quick way to reproduce the current behavior:

Test function:
```
func TestA(t *testing.T) {
log.Println("TestA running")
if !testing.Verbose() {
t.Fatal()
}
}
```
Selected launch configuration
```:
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"args": [
"-test.run", "TestA", // no impact with or without on `run/debug test`, which adds its own `-run ^TestA$`
"-test.v"
]
},
```

**Debug with `▷ Start Debugging` or `Run > Start Debugging (F5)`**

Uses `launch.json` configuration, so the test passes.
![image](https://user-images.githubusercontent.com/51177946/97472248-dc36a900-1906-11eb-8cb7-0edd14122c46.png)

**Debug with `debug test`**

Doesn't use `launch.json` configuration, so the test fails.
![image](https://user-images.githubusercontent.com/51177946/97477233-9846a280-190c-11eb-82fa-c912c2c58502.png)

**Run with `Run > Run Without Debugging (^F5)`**

Uses `launch.json` configuration, so the test passes. (Note that this actually goes through the debug adapter, which launches dlv - see #336)
![image](https://user-images.githubusercontent.com/51177946/97477706-3175b900-190d-11eb-9d4c-c92add921f6a.png)

**Run with `run test`**

Doesn't use `launch.json` configuration, so the test fails. (Note that this uses `go test` and bypasses dlv - see #336)
![image](https://user-images.githubusercontent.com/51177946/97478090-b660d280-190d-11eb-801e-886d1efaf492.png)

**Adding flags to `settings.json`**

```
"go.testFlags": ["-test.v"]
```
`run test` now passes, but `debug test` behavior is unchanged.
```
"go.testFlags": ["-args","-test.v"]
```
`run test` passes, but only prints "ok", no details. `debug test` works as expected.
```
"go.testFlags": ["-v", "-args","-test.v"]
```
Combining these makes both work as expected - pass and print verbose details.

Contributor guide

Open the contributing guide

Research direction

Start by investigating how the `run test` and `debug test` CodeLens commands resolve launch.json configurations, and compare that with `Start Debugging (F5)` and `Run Without Debugging`. Review the existing `go.testFlags` and `go.delveConfig` settings and the referenced VS Code launch behavior. Done means a selected launch configuration can consistently supply the intended test flags to both CodeLens actions, with coverage for the differing run and debug paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, typescript, vscode
Domain
developer-experience, testing, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.