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
Closed

cmd/go: go test links and runs tests for packages with no tests #26242

rsc opened this issue Jul 6, 2018 · 6 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc 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
Copy link
Contributor

meirf commented Jul 6, 2018

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

@ianlancetaylor
Copy link
Contributor

@rsc This change was made to fix #24570.

We can roll it back if you like.

@ianlancetaylor
Copy link
Contributor

CC @kyroy

@ianlancetaylor ianlancetaylor added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jul 6, 2018
@ianlancetaylor
Copy link
Contributor

Also #26157.

@rsc
Copy link
Contributor Author

rsc 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
Copy link

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

@golang golang locked and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants