vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

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

Open vrv3814 opened this issue 3 weeks ago • 5 comments

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.
    • go version go1.25.3 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
          Build info
          ----------
          golang.org/x/tools/gopls v0.20.0
              golang.org/x/tools/[email protected] h1:fxOYZXKl6IsOTKIh6IgjDbIDHlr5btOtOUkrGOgFDB4=
              github.com/BurntSushi/[email protected] h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
              github.com/fatih/[email protected] h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
              github.com/fatih/[email protected] h1:dDSgAjoOMp8da3egfz0t2S+t8RGOpEmEXZubcGuc0Bg=
              github.com/fatih/[email protected] h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
              github.com/fsnotify/[email protected] h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
              github.com/google/[email protected] h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
              golang.org/x/exp/[email protected] h1:KdrhdYPDUvJTvrDK9gdjfFd6JTk8vA1WJoldYSi0kHo=
              golang.org/x/[email protected] h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
              golang.org/x/[email protected] h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
              golang.org/x/[email protected] h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
              golang.org/x/[email protected] h1:DU+gwOBXU+6bO0sEyO7o/NeMlxZxCZEvI7v+J4a1zRQ=
              golang.org/x/[email protected] h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
              golang.org/x/[email protected] h1:ZRKyKRJl/YEWl9ScZwd6Ua6xSt7DE6tHp1I3ucMroGM=
              golang.org/x/[email protected] h1:Ju8QsuyhX3Hk8ma3CesTbO8vfJD9EvUBgHvkxHBzj0I=
              honnef.co/go/[email protected] h1:fj8r9irJSpolAGUdZBxJIRY3lLc4jH2Dt4lwnWyWwpw=
              mvdan.cc/[email protected] h1:nZUCeC2ViFaerTcYKstMmfysj6uhQrA2vJe+2vwGU6k=
              mvdan.cc/xurls/[email protected] h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=
          go: go1.25.3
    
    
    
    
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    .106.3 bf9252a2fb45be6893dd8870c0bf37e2e1766d61 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • Version 0.50.0

Describe the bug

When using -ldflags in test configuration, the "run test" and "debug test" CodeLens buttons handle flags inconsistently, making it impossible to configure flags that work for both operations.

Scenario 1: Using go.buildFlags with quoted value
settings.json:

{
    "go.buildFlags": [
         "-ldflags", "'-X github.com/org/driver-device/internal/info.version=v25.8.0'"
    ]
}

✅ Debug test works
❌ Run test fails with:

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestReconcile_Function$ github.com/org/controller/internal/tefrol -ldflags '-X github.com/org/driver-device/internal/info.version=v25.8.0'

invalid value "'-X github.com/org/driver-device/internal/info.version=v25.8.0'" for flag -ldflags: parameter may not start with quote character '
usage: go test [build/test flags] [packages] [build/test flags & test binary flags]
Run 'go help test' and 'go help testflag' for details.

Scenario 2: Using go.buildFlags without quotes
settings.json:

{
    "go.buildFlags": [
         "-ldflags", "-X github.com/org/driver-device/internal/info.version=v25.8.0"
    ]
}

✅ Run test works
❌ Debug test fails in packages with subdirectories with:

Build Error: go test -c -o /home/user/controller/internal/tefrol/__debug_bin1049253809 -gcflags all=-N -l -ldflags -X github.com/org/driver-device/internal/info.version=v25.8.0 .
with multiple packages, -o must refer to a directory or /dev/null (exit status 1)

vrv3814 avatar Dec 03 '25 09:12 vrv3814