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

Tests fails when saving a file (a symbolic link) with testOnSave enabled

Open marefr opened this issue 1 year ago • 1 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.21.3 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

    • golang.org/x/tools/gopls v0.14.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.85.2
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.40.3
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    • Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /home/marcus/go GOROOT: /usr/local/go1.21.3.linux-amd64 PATH: /home/marcus/.nvm/versions/node/v20.9.0/bin:/home/marcus/.wasmedge/bin:/home/marcus/.cargo/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/marcus/go/bin:/usr/local/go/bin

    go: /usr/local/go/bin/go: go version go1.21.3 linux/amd64

    gopls: /home/marcus/go/bin/gopls (version: v0.14.2 built with go: go1.21.3) gotests: /home/marcus/go/bin/gotests (version: v1.6.0 built with go: go1.21.3) gomodifytags: /home/marcus/go/bin/gomodifytags (version: v1.16.0 built with go: go1.21.3) impl: /home/marcus/go/bin/impl (version: v1.1.0 built with go: go1.21.3) goplay: /home/marcus/go/bin/goplay (version: v1.0.0 built with go: go1.21.3) dlv: /home/marcus/go/bin/dlv (version: v1.22.0 built with go: go1.21.3) golangci-lint: /home/marcus/go/bin/golangci-lint (version: v1.53.3 built with go: go1.21.3)

go env Workspace Folder (a): /home/marcus/go/src/github.com/marefr/symlink-go-test/a GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/marcus/.cache/go-build' GOENV='/home/marcus/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/marcus/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/home/marcus/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/go1.21.3.linux-amd64' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/go1.21.3.linux-amd64/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.3' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/home/marcus/go/src/github.com/marefr/symlink-go-test/a/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4172497021=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited

{
    "go.testOnSave": true,
    "gopls": {
        "build.buildFlags": [
            "-tags=integration",
        ],
        "ui.semanticTokens": true
    },
    "go.coverOnTestPackage": false,
    "go.useLanguageServer": true
}

Describe the bug

I have a setup with two repositories, A and B, where Go code from B repo are symlinked into the A repo. Then the A repo are used as the workspace in vs code. When having the feature testOnSave enabled, then navigating to one of the symlinked files and then save it, the test tool are automatically run as expected, but fails with the following error:

Running tool: /usr/local/go/bin/go test github.com/marefr/symlink-go-test/a/pkg/extensions/something

no required module provides package github.com/marefr/symlink-go-test/a/pkg/extensions/something: go.mod file not found in current directory or any parent directory; see 'go help modules'

I expect the tests to run successfully since coping the command from the output, open a terminal, paste and run it works as expected.

Steps to reproduce the behavior:

See https://github.com/marefr/symlink-go-test for details, reproduction and detailed steps.

marefr avatar Feb 02 '24 18:02 marefr

CC @hyangah.

findleyr avatar Feb 15 '24 21:02 findleyr