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: go test links and runs tests for packages with no tests #26242

Closed
rsc opened this issue Jul 6, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@rsc
Copy link
Contributor

commented Jul 6, 2018

If asked to run "go test" on a directory with no *_test.go files, I expect "go test" not to build and run a test binary. Go 1.10 and earlier did not. But the current Go 1.11 tree does. Surprise!

$ mkdir $GOPATH/src/zz
$ cd $GOPATH/src/zz
$ echo package zz >zz.go
$ go1.10 test -x 2>&1 | grep '\.test'
$ go test -x 2>&1 | grep '\.test'
packagefile zz.test=/Users/rsc/Library/Caches/go-build/d2/d295e08103bd5a774940e8d5caad0cf7e2daa7c33c648984212f91ddcf9aae69-d
/Users/rsc/go/pkg/tool/darwin_amd64/link -o $WORK/b001/zz.test -importcfg $WORK/b001/importcfg.link -s -w -buildmode=exe -buildid=x_MweihetzP0Eun-VgUA/dX2Te_1YwK9j-BWgg7AH/tGS-MgIOLxh0lEea7iw_/x_MweihetzP0Eun-VgUA -extld=clang /Users/rsc/Library/Caches/go-build/d2/d295e08103bd5a774940e8d5caad0cf7e2daa7c33c648984212f91ddcf9aae69-d
$WORK/b001/zz.test
$ 

If you run 'go test -badflag' then you can see the difference quite clearly: if the test doesn't run, nothing detects the bad flag, so it succeeds.

A more reasonable example is if you have a test helper library you use for all your tests that defines some common flag. It used to work to run

go test my.tree/... -my.flag

assuming that all your tests imported the library defining -my.flag. But now if any packages in that tree have no tests at all, a dummy test binary gets run that of course does not know about -my.flag

This was originally reported as a bug against vgo in #26214.

@meirf

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2018

Looks like this may have started with 8396015 "cmd/link: set runtime.GOROOT default during link"

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2018

@rsc This change was made to fix #24570.

We can roll it back if you like.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2018

CC @kyroy

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2018

Also #26157.

@rsc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2018

Yes, please stop linking and running tests with no tests. :-)
We can fix #24570 by writing an empty coverage profile.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 6, 2018

Change https://golang.org/cl/122518 mentions this issue: cmd/go: revert "output coverage report even if there are no test files"

@gopherbot gopherbot closed this in 7254cfc Jul 9, 2018

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.