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

Comments

Projects
None yet
7 participants
@dlsniper
Copy link
Contributor

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 this to the Go1.12 milestone Jul 18, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2018

Marking as Go 1.12 since the behavior is not new.

CC @rsc @bcmills

@josharian

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2018

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

@dlsniper

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2018

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.

@ysmolsky

This comment has been minimized.

Copy link
Member

commented Jul 19, 2018

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2018

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2018

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

@ysmolsky

This comment has been minimized.

Copy link
Member

commented Jul 19, 2018

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

This comment has been minimized.

Copy link

commented Jul 20, 2018

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

@dvyukov

This comment has been minimized.

Copy link
Member

commented Aug 23, 2018

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

@iWdGo

This comment has been minimized.

Copy link
Contributor

commented Oct 21, 2018

Issue cannot be reproduced when using go 1.11.1

@dlsniper

This comment has been minimized.

Copy link
Contributor Author

commented Oct 22, 2018

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 join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.