Skip to content

goTest CodeLens: preserve buildFlags as array when debugging tests#4034

Closed
vrv3814 wants to merge 1 commit into
golang:masterfrom
vrv3814:master
Closed

goTest CodeLens: preserve buildFlags as array when debugging tests#4034
vrv3814 wants to merge 1 commit into
golang:masterfrom
vrv3814:master

Conversation

@vrv3814
Copy link
Copy Markdown

@vrv3814 vrv3814 commented May 21, 2026

debugTestAtCursor CodeLens previously joined go.buildFlags into a single space-separated string before passing them to the debug adapter. This corrupted flag values that contain spaces, such as -ldflags "-X pkg.version=v1.0": after joining, where delve sees -X and pkg.version=v1.0 as separate arguments and fails with with multiple packages, -o must refer to a directory or /dev/null.
Meanwhile, the run-test CodeLens passes each flag as a separate argument to go test, so the same go.buildFlags worked for "run test" but broke "debug test".

Fix

Changes are made to pass buildFlags as an array to startDebugging. The existing maybeJoinFlags helper in goDebugConfiguration.ts already handles both shapes: it joins for delve < 1.22.2 and preserves the array for newer delve, so each element reaches delve as a separate token. Also I've omitted buildFlags from the debug config when empty to keep behavior parity with the previous "" sentinel.

Fixes #3933

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 21, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@vrv3814 vrv3814 changed the title extension/src/goTest: preserve buildFlags as array when debugging tests goTest CodeLens: preserve buildFlags as array when debugging tests May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] go.buildFlags with -ldflags causes incompatible behavior between "run test" and "debug test" CodeLens

1 participant