Go version
go version go1.21.9 darwin/amd64
Output of go env
in your module/workspace:
$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOOS='darwin'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.9'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
What did you do?
i write a build tag for my code, like below:
.
├── a.go
├── a_a.go
├── a_test.go
└── go.mod
a.go
// note: i write wrong format for // +build
//go:build rgoinjec
// +build rgoinject
package test2
import "fmt"
func A() {
fmt.Println("a")
}
a_a.go
package test2
import "fmt"
func A() {
fmt.Println("a")
}
a_test.go
package test2
import "testing"
func TestA(t *testing.T) {
A()
}
go build ./...
build successgo test ./...
test failed
What did you see happen?
I write the wrong format build tag for a.go
. It will compile successfully by go build ./...
, but it will fail by go test ./...
What did you expect to see?
I think go test
& go build
both to report the wrong format for my code.
Comment From: gabyhelp
Similar Issues
- +build tags not honored #31878
- cmd/go: `go test` trips over "commented" build tags, when `go build` does not. #31938
- fmt: skip checking the number of args in format for go build and different from go test #29849
- cmd/go: build tags do not work quite as expected using devel version of Go #66299
- cmd/go/internal/test: compile error for `go test` on package with no test files does not output package-level "FAIL" error #64286
- cmd/go: test with coverage unexpect fail #43242
- go/build: imports from cgo files included in Imports when CGO_ENABLED=0 #35946
- build go from source failed on macos #36397
- affected/package: fmt #56713
- No #24279
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: ianlancetaylor
The error is being reported by go vet
. Running go test
automatically runs go vet
. Running go build
does not. This is working as documented and expected, so closing. Thanks for reporting it.