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 success
  • go 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 ./... Golang go build has unexpected behavior

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

(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.