-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/cover: cover mode "atomic" generates invalid code for files without a newline at EOF #58370
Comments
@thanm will probably be interested in this? |
Thanks for the report. I'll take a look. NB as in many other cases, you can help reduce the frequency of this sort of surprise by running your code through "gofmt". |
Change https://go.dev/cl/466115 mentions this issue: |
Not sure if this is backport-worthy. |
Since it only seems to affect Go 1.20 out of the box where the coverage redesign is in use by default, probably not. |
Fix a minor buglet in atomic mode fixup that would generate non-compilable code for a package containing only the "package X" clause with no trailing newline following the "X". Fixes golang#58370. Change-Id: I0d9bc4f2b687c6bd913595418f6db7dbe50cc5df Reviewed-on: https://go-review.googlesource.com/c/go/+/466115 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Fixes an "syntax error: unexpected var after top level declaration" error when running 'go test -cover -covermode=atomic ./...' with GO 1.20. Related to GO issue: golang/go#58370
this issue still exists even on 1.20.5, when running atomic coverage on test files with no new line at EOF🤔 |
That is expected, given that the bugfix hasn't been ported to the 1.20 release branch. |
Oh, thanks for letting me know. I was under the impression the fix was released since the issue was closed/merged PR. |
See https://github.com/golang/go/wiki/MinorReleases . "Our default decision should always be to not backport, but fixes for security issues, serious problems with no workaround, and documentation fixes are backported to the most recent two release branches, if applicable to that branch. " A “serious” problem is one that prevents a program from working at all. |
- see [cmd/cover: cover mode "atomic" generates invalid code for files without a newline at EOF](golang/go#58370)
* ci: fix wrong coverage result on badge * chore: adjust go test command * chore: disable `atomic` covermode to avoid go bug - see [cmd/cover: cover mode "atomic" generates invalid code for files without a newline at EOF](golang/go#58370)
* update entitlements to go1.20 * add whitespace to avoid bug: golang/go#58370 --------- Co-authored-by: Daniel Agbay <Daniel Agbay>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
GOEXPERIMENT=nocoverageredesign
and suggests the issue is possibly a regression related to cmd/cover: extend coverage testing to include applications #51430 -- thanks to @deltamualpha for discovering this.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran
go test -cover -covermode=atomic
on a package with a file that had a newline missing at EOF.All code referred to is also under https://github.com/nilium/go-issue-test/tree/38c0047d4219026ecccbb2f35f96162fef5478a7. Because it involves the trailing newline at EOF on sources, there isn't a good way to reproduce it in the playground as far as I can see.
A more or less empty file can be used to reproduce this provided the
empty.go
file does not have a newline at EOF:empty.go
package noeol
some_test.go (doesn't matter if this file has a newline at EOF to reproduce)
What did you expect to see?
For test output:
What did you see instead?
with the generated code for mode=atomic resembling the following:
The text was updated successfully, but these errors were encountered: