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: unresolved import masks vet warnings in 'go test' and 'go vet' #43095

Open
CzBiX opened this issue Dec 9, 2020 · 3 comments
Open

cmd/go: unresolved import masks vet warnings in 'go test' and 'go vet' #43095

CzBiX opened this issue Dec 9, 2020 · 3 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@CzBiX
Copy link

CzBiX commented Dec 9, 2020

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

$ go version
go version go1.15.6 linux/amd64

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build241876888=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ find
.
./foo
./foo/bar.go
$ cat foo/bar.go
// +build windows
package foo

import _ "golang.org/x/sys/windows"

$ go test ./...
package ./foo
        imports golang.org/x/sys/windows: build constraints exclude all Go files in /go/src/golang.org/x/sys/windows

What did you expect to see?

test success, test ignore files with tags.

What did you see instead?

test failed.

@bcmills
Copy link
Contributor

bcmills commented Dec 9, 2020

Your // +build windows comment has no newline after it, so it is interpreted as a package comment instead of a build constraint.

There is a vet check for that mistake, and go test runs that vet check implicitly. However, it appears that in this case the build error is masking the clearer vet warning.

CC @jayconrod @matloob

@bcmills bcmills changed the title Test should follow build constraint tags cmd/go: build error masks vet warnings in 'go test' Dec 9, 2020
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 9, 2020
@bcmills bcmills added this to the Backlog milestone Dec 9, 2020
@bcmills bcmills added the GoCommand cmd/go label Dec 9, 2020
@bcmills
Copy link
Contributor

bcmills commented Dec 9, 2020

This is somewhat related to #37803.

@CzBiX
Copy link
Author

CzBiX commented Dec 9, 2020

Thanks.
BTW, go vet ./... got the same error.

@bcmills bcmills changed the title cmd/go: build error masks vet warnings in 'go test' cmd/go: unresolved import masks vet warnings in 'go test' and 'go vet' Dec 9, 2020
@timothy-king timothy-king added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants