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: test -coverpkg: compilation error when file only contains interface definitions #61709

Closed
pchmieli opened this issue Aug 2, 2023 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@pchmieli
Copy link

pchmieli commented Aug 2, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.6 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\username\AppData\Local\go-build
set GOENV=C:\Users\username\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\username\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\username\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.6
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\USERNAME\AppData\Local\Temp\go-build2060490568=/tmp/go-build -gno-record-gcc-switches

What did you do?

I try to run unit tests with coverage

GOROOT=C:\Program Files\Go #gosetup
GOPATH=C:\Users\username\go #gosetup
"C:\Program Files\Go\bin\go.exe" test -c -coverpkg=../../../../../repo-name/... -covermode=atomic -o C:\Users\username\AppData\Local\JetBrains\IntelliJIdea2023.1\tmp\GoLand\___binary-name.exe package-name/project-name/pkg/feature_tests #gosetup

I've got multiple packages with executable code in my project. Additionally, there is one package with single file and single interface inside and this very file causes the issue:

package api

type Foo interface {
	Bar(x, y string) ([]string, error)
}

What did you expect to see?

Test coverage report

What did you see instead?

Compilation error

(...) api.go:1:21: "sync/atomic" imported as _cover_atomic_ and not used

Compilation finished with exit code 1

Workaround

Error is gone once I add some executable code to api.go. It might be whatever function, even empty and unused:

package api

type Foo interface {
	Bar(x, y string) ([]string, error)
}

func xyz() {
}

Possibly related issues:

#17817 cmd/cover: Avoid importing atomic package if not used
#18486 cmd/go: go test -coverpkg=./... -race does not rebuild sync/atomic

@thediveo
Copy link

thediveo commented Aug 2, 2023

Can you please give the complete source, because there's an error about an unused import.

Ah, I see: -cover does insert the import. Now I'm wondering why I don't see this error on my own modules? Does this also happen for you for Go 1.20.5?

@seankhliao
Copy link
Member

Can you provide a self contained reproducer please.

@seankhliao seankhliao changed the title go test -coverpkg: compilation error when file contains interface only (no executable code_ cmd/go: test -coverpkg: compilation error when file only contains interface definitions Aug 2, 2023
@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 2, 2023
@pchmieli
Copy link
Author

pchmieli commented Aug 3, 2023

I've just tried to prepare smallest possible example and bug does not appear there :(

Cannot disclose my real example as it is proprietary. Will come back to you once I have self contained reproducer.

@pchmieli pchmieli closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants