golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.85k stars 738 forks source link

Vscode debug test and run test use two and more go.buildTags fail #1836

Open ken0911208818 opened 2 years ago

ken0911208818 commented 2 years ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go1.16.6 darwin/arm64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - Build info ---------- golang.org/x/tools/gopls v0.7.2 golang.org/x/tools/gopls@v0.7.2 h1:kRKKdvA8GOzra8rhSFDClOR7hV/x8v0J0Vm4C/gWq8s= github.com/BurntSushi/toml@v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sys@v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= golang.org/x/tools@v0.1.6-0.20210908190839-cf92b39a962c h1:C0nyHiBU2m0cR6hDiUORWqQIt3h37wsp1255QBSSXqY= golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE= mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA= mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I= * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - Version: 1.60.2 (Universal) Commit: 7f6ab5485bbc008386c4386d08766667e155244e Date: 2021-09-22T11:59:27.195Z Electron: 13.1.8 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin arm64 20.4.0 * Check your installed extensions to get the version of the VS Code Go extension - * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. -

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

one go.buildTags can run run test and debug test two and more build tags Cannot be executed at the same time when using run test debug test

Steps to reproduce the behavior:

  1. Go to set settings.json go.buildTags "sqlite sqlite_unlock_notify"
  2. Click on run test debug test
  3. See error

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

problem

Vscode use run test and debug test I use build tags to run test func build tags: sqlite, sqlite_unlock_notify

In Vscode settings go.buiildTags use sqlite sqlite_unlock_notify run test can work but debug test not work

In Vscode settings go.buiildTags use 'sqlite sqlite_unlock_notify' run test not work but debug test can work

I need a method so that the above run test debug test can be executed together

vboulineau commented 2 years ago

Hello,

Came across the exact same issue today and it was not straightforward to identify the failure was related to this as the errors message were only:

package jmx is not in GOROOT (/usr/local/opt/go/libexec/src/jmx)
package jetson is not in GOROOT (/usr/local/opt/go/libexec/src/jetson)
...
package zlib is not in GOROOT (/usr/local/opt/go/libexec/src/zlib)

Each package being one of the build tags. On top of that there's no significant diff between the command run:

/usr/local/opt/go/libexec/bin/go test -timeout 30s -tags ec2 jmx jetson orchestrator zlib systemd etcd consul secrets containerd cri docker apm kubelet python kubeapiserver gce netcgo zk process test -run

And with debug test:

go test -c -o /var/folders/h4/xp6zgrvd5_32n33jl3v53wt00000gn/T/__debug_bin3762757146 -gcflags all=-N -l -tags ec2 jmx jetson orchestrator zlib systemd etcd consul secrets containerd cri docker apm kubelet python kubeapiserver gce netcgo zk process test .

I guess that when passed through to Delve, the values do not belong to a single arg[] anymore and thus require some quoting but a quick look at the code did not allow me to find where this happens in the code exactly.

hkolvenbach commented 1 year ago

Any update on this? I am running into the exact same issue with multiple tags and @vboulineau describes the problem well: the build tags are not quoted and as such treated as individual arguments.

If one of the maintainers could point me to the location where the command line arguments are assembled, I could give it a shot with a PR. Is https://github.com/golang/vscode-go/blob/master/src/testUtils.ts#L136 the right place to look at?

Edit: An ugly workaround would be to quote testTags yourself like this in settings.json

  "go.testTags": "'sqllite sqlite_unlock_notify'"

This allows debugging the tests, but running them fails unless the quotes are removed again.

hyangah commented 1 year ago

Does the problem still exist if a comma-separated build tag list is used? From go command doc, space-separated list is deprecated.

        -tags tag,list
                a comma-separated list of additional build tags to consider satisfied
                during the build. For more information about build tags, see
                'go help buildconstraint'. (Earlier versions of Go used a
                space-separated list, and that form is deprecated but still recognized.)

I think https://github.com/golang/vscode-go/blob/32a643f674ca4e3d322ccffc22f28cf93a9c1f82/src/goTest.ts#L268 and https://github.com/golang/vscode-go/blob/32a643f674ca4e3d322ccffc22f28cf93a9c1f82/src/goTest.ts#L292 are relevant lines to fiddle with the debug args.

Or, once we make a progress in https://github.com/go-delve/delve/issues/2718 passing the build flag as []string is another option.

hkolvenbach commented 1 year ago

Sorry for the late reply. Yes, comma-separated works, thank you!