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: vet checks do not run when compiling tests to output a binary #26451

Closed
dlsniper opened this issue Jul 18, 2018 · 11 comments
Closed

cmd/go: vet checks do not run when compiling tests to output a binary #26451

dlsniper opened this issue Jul 18, 2018 · 11 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dlsniper
Copy link
Contributor

dlsniper commented Jul 18, 2018

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

go version go1.10.3 linux/amd64
go version go1.11beta1 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

OS/ARCH independent

What did you do?

Using a simple broken build tag such as this, place the code in a demo_test.go file:

//+build hello
package demo

import "testing"

type Demo struct {
	Field string
}

func NewDemo(v string) *Demo {
	return &Demo{
		Field: v,
	}
}

func TestDemo(t *testing.T) {
	v := NewDemo("hello world")
	t.Log(v)
}

Run go test -c -o binary.name.

What did you expect to see?

I expect to see the following error:

.\file_test.go:1: +build comment must appear before package clause and be followed by a
blank line%!(EXTRA []interface {}=[])

What did you see instead?

Compilation and running tests from the test binary via binary.name -test.v works without issues.

This behavior is inconsistent and leads to issues when a user compiles the test binary to run it after. I would expect the test binary to be prevented from being created by the same vet checks.

@ianlancetaylor ianlancetaylor changed the title cmd/test: vet checks do not run when compiling tests to output a binary cmd/go: vet checks do not run when compiling tests to output a binary Jul 18, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 18, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jul 18, 2018
@ianlancetaylor
Copy link
Member

Marking as Go 1.12 since the behavior is not new.

CC @rsc @bcmills

@josharian
Copy link
Contributor

Additionally, the error you expected to see looks a bit broken to me—looks like a bad format string. cc @mvdan

@dlsniper
Copy link
Contributor Author

I think that the formatting error was fixed in the latest master but I'm still using 1.11 Beta 1. I'll revisit this for Beta 2 / RC 1.

@ysmolski
Copy link
Member

I cannot reproduce this on go version devel +d278f09333 Thu Jul 19 05:40:37 2018 +0000 darwin/amd64

...go/src/demo % cat demo.go
//+build hello
package demo

import "testing"

type Demo struct {
	Field string
}

func NewDemo(v string) *Demo {
	return &Demo{
		Field: v,
	}
}

func TestDemo(t *testing.T) {
	v := NewDemo("hello world")
	t.Log(v)
}
...go/src/demo % go test -c -o test.bin
# demo
./demo.go:1: +build comment must appear before package clause and be followed by a blank line
...go/src/demo % ls
demo.go

@dlsniper
Copy link
Contributor Author

This still seems to be an issue both on Windows and Linux using:

  • go version devel +d278f09333 Thu Jul 19 05:40:37 2018 +0000 windows/amd64
  • go version devel +d278f09333 Thu Jul 19 05:40:37 2018 +0000 linux/amd64

See the image below:
image

@dlsniper
Copy link
Contributor Author

@ysmolsky this is probably because the code was in a non _test.go file? In my case it was in such a file.

@ysmolski
Copy link
Member

Right. I am sorry! Here we go:

...go/src/demo % mv demo.go demo_test.go
...go/src/demo % go test -c -o test.bin
...go/src/demo % go test
# demo
./demo_test.go:1: +build comment must appear before package clause and be followed by a blank line
FAIL	demo [build failed]

Reproduced.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/125215 mentions this issue: cm/go/internal/test: make vet run when compiling

@dvyukov
Copy link
Member

dvyukov commented Aug 23, 2018

@iwdgo says this broke race detector on windows: #27089
Could somebody take a look please?

@iwdgo
Copy link
Contributor

iwdgo commented Oct 21, 2018

Issue cannot be reproduced when using go 1.11.1

@dlsniper
Copy link
Contributor Author

The issue is still present in Go 1.11.1. Place the code exactly as it's written in a _test.go file and the problem should be reproduced.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants