-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: unexpected panic when running go test on particular package without test files #25789
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
Comments
The go tool does now build and run the test binary even if there aren't any tests. If this didn't happen in 1.10, it happens on tip most likely because of #24570. It does seem simpler to handle things consistently, rather than having a special case when there are no tests. |
Go 1.11 and higher execute the init() function when tests are run, even if no tests exist in the package. This caused problems since tlsrestrict_nss_tool's init() function produces errors when options aren't explicitly provided by the user via command-line flags or a config file. See golang/go#25789 for more info. This commit moves that code from init() to main().
5c5bee4 Fix test failures on Go 1.11 and higher. (JeremyRand) Pull request description: Go 1.11 and higher execute the `init()` function when tests are run, even if no tests exist in the package. This caused problems since `tlsrestrict_nss_tool`'s `init()` function produces errors when options aren't explicitly provided by the user via command-line flags or a config file. See golang/go#25789 for more info. This commit moves that code from `init()` to `main()`. Tree-SHA512: 27eed58a85a5dba26669a4f3f8dd337a966e5020a86f0d3fdc773fc1db3b56d056b1011bb92b552507440da2932500d0fae54ca7abe03bca555567f1f801fca0
Duplicate (now) of #26242, which we will fix for Go 1.11. |
Change https://golang.org/cl/122518 mentions this issue: |
Original CL description: When using test -cover or -coverprofile the output for "no test files" is the same format as for "no tests to run". Reverting because this CL changed cmd/go to build test binaries for packages that have no tests, leading to extra work and confusion. Updates #24570 Fixes #25789 Fixes #26157 Fixes #26242 Change-Id: Ibab1307d39dfaec0de9359d6d96706e3910c8efd Reviewed-on: https://go-review.googlesource.com/122518 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I tested with go1.10.1 and it does not reproduce.
What operating system and processor architecture are you using (
go env
)?What did you do?
I created a repository that you can clone to reproduce this issue: https://github.com/mark-rushakoff/testpanic
I am sure the repro case could be stripped down quite a bit, but I do not have time to minimize it any further right now.
That repository's main.go contains only the following code:
Then I ran
go test .
What did you expect to see?
I expected to see the same output that I see in go 1.10:
What did you see instead?
I saw a panic from an init function, that I would not have expected to run on account of there being no test files:
The text was updated successfully, but these errors were encountered: