Skip to content

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

@vrv3814

Description

@vrv3814

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/gopls@v0.20.0 h1:fxOYZXKl6IsOTKIh6IgjDbIDHlr5btOtOUkrGOgFDB4=
               github.com/BurntSushi/toml@v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
               github.com/fatih/camelcase@v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
               github.com/fatih/gomodifytags@v1.17.1-0.20250423142747-f3939df9aa3c h1:dDSgAjoOMp8da3egfz0t2S+t8RGOpEmEXZubcGuc0Bg=
               github.com/fatih/structtag@v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
               github.com/fsnotify/fsnotify@v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
               github.com/google/go-cmp@v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
               golang.org/x/exp/typeparams@v0.0.0-20250620022241-b7579e27df2b h1:KdrhdYPDUvJTvrDK9gdjfFd6JTk8vA1WJoldYSi0kHo=
               golang.org/x/mod@v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
               golang.org/x/sync@v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
               golang.org/x/sys@v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
               golang.org/x/telemetry@v0.0.0-20250710130107-8d8967aff50b h1:DU+gwOBXU+6bO0sEyO7o/NeMlxZxCZEvI7v+J4a1zRQ=
               golang.org/x/text@v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
               golang.org/x/tools@v0.35.1-0.20250728180453-01a3475a31bc h1:ZRKyKRJl/YEWl9ScZwd6Ua6xSt7DE6tHp1I3ucMroGM=
               golang.org/x/vuln@v1.1.4 h1:Ju8QsuyhX3Hk8ma3CesTbO8vfJD9EvUBgHvkxHBzj0I=
               honnef.co/go/tools@v0.7.0-0.dev.0.20250523013057-bbc2f4dd71ea h1:fj8r9irJSpolAGUdZBxJIRY3lLc4jH2Dt4lwnWyWwpw=
               mvdan.cc/gofumpt@v0.8.0 h1:nZUCeC2ViFaerTcYKstMmfysj6uhQrA2vJe+2vwGU6k=
               mvdan.cc/xurls/v2@v2.6.0 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions