Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go vet does not support -overlay #44957

Open
eandre opened this issue Mar 12, 2021 · 2 comments
Open

cmd/go: go vet does not support -overlay #44957

eandre opened this issue Mar 12, 2021 · 2 comments

Comments

@eandre
Copy link

@eandre eandre commented Mar 12, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/eandre/Library/Caches/go-build"
GOENV="/Users/eandre/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/eandre/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/eandre"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.16/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hc/w9bwjfwd69dd6_6thw6xqmkw0000gn/T/go-build2213810525=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Consider the following txtar:

-- go.mod --
module test.pkg
-- foo/foo_test.go --
package foo

import "testing"

func TestFoo(t *testing.T) { }
-- tmp/bar.go --
package foo
-- foo/overlay.json --
{"Replace": {"bar.go": "../tmp/bar.go"}}

I ran cd foo && go test -overlay=overlay.json . and expected the tests to pass.

What did you expect to see?

$ go test -overlay=overlay.json .
ok  	test.pkg/foo 0.123s

What did you see instead?

$ go test -overlay=overlay.json .
# test.pkg/foo
vet: open bar.go: no such file or directory
FAIL	test.pkg/foo [build failed]
FAIL
exit status 2

The issue is because the overlay is added to GoTestFiles but go vet does not support (or receive information about) overlays, so it tries to read the overlaid file directly from the filesystem where it does not exist.

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Mar 12, 2021

@vithalklrk
Copy link

@vithalklrk vithalklrk commented May 28, 2021

Hi, alldocs.go says this:
// -overlay file // read a JSON config file that provides an overlay for build operations. // The file is a JSON struct with a single field, named 'Replace', that // maps each disk file path (a string) to its backing file path, so that // a build will run as if the disk file path exists with the contents // given by the backing file paths, or as if the disk file path does not // exist if its backing file path is empty. Support for the -overlay flag // has some limitations: importantly, cgo files included from outside the // include path must be in the same directory as the Go package they are // included from, and **overlays will not appear when binaries and tests are // run through go run and go test** respectively.
Is the above description saying that this is not an issue? I am new, so I could be getting it wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants