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 with coverage unexpect fail #43242

Closed
forsaken628 opened this issue Dec 17, 2020 · 5 comments
Closed

cmd/go: test with coverage unexpect fail #43242

forsaken628 opened this issue Dec 17, 2020 · 5 comments
Labels
FrozenDueToAge 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

@forsaken628
Copy link

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

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/Users/michael/Projects/golang/bin"
GOCACHE="/Users/michael/Library/Caches/go-build"
GOENV="/Users/michael/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/michael/Projects/golang/pkg/mod"
GONOPROXY="git.netisdev.com"
GONOSUMDB="git.netisdev.com"
GOOS="darwin"
GOPATH="/Users/michael/Projects/golang"
GOPRIVATE="git.netisdev.com"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/Cellar/go/1.15.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bd/rnhtmc553vvcm_ty8nt2tv4c0000gn/T/go-build535277532=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

run test at dir like this

bar
  bar/bar.go
  bar/bar_test.go
nogo
  nogo/nogo_test.go
go test ./... -coverpkg=./... -coverprofile=out

What did you expect to see?

test pass

What did you see instead?

go build xxx/foo: no non-test Go files in /xxx/nogo
FAIL    xxx/bar [build failed]
ok      xxx/nogo    0.604s  coverage: [no statements] [no tests to run]
FAIL
@gopherbot
Copy link

Change https://golang.org/cl/278892 mentions this issue: cmd/go: exclude empty cover package

@mvdan
Copy link
Member

mvdan commented Dec 17, 2020

What is in your "bar" directory? Please provide clear steps to reproduce this issue.

@mvdan mvdan added 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. labels Dec 17, 2020
@forsaken628
Copy link
Author

empty

bar.go

package bar

bar_test.go

package bar

@mvdan
Copy link
Member

mvdan commented Dec 17, 2020

Okay, here is a full reproducer:

$ cat test.txt
go test -v -coverpkg=./... ./...

-- go.mod --
module test
-- bar/bar.go --
package bar
-- bar/bar_test.go --
package bar
-- nogo/nogo_test.go --
package nogo
$ testscript test.txt

> go test -v -coverpkg=./... ./...
[stdout]
FAIL	test/bar [build failed]
testing: warning: no tests to run
PASS
coverage: [no statements]
ok  	test/nogo	(cached)	coverage: [no statements] [no tests to run]
FAIL

[stderr]
go build test/nogo: no non-test Go files in $WORK/nogo

[exit status 1]
FAIL: /tmp/testscript999122747/0/script.txt:1: unexpected go command failure
error running test.txt in /tmp/testscript999122747/0

It seems like a bug to me, since go test ./... succeeds. Perhaps @bcmills @jayconrod @matloob can chime in.

Also, please add a test to your patch.

@jayconrod
Copy link
Contributor

Yep, this is a bug. Duplicate of #27333 though.

There are a number of problems with -coverpkg, and I'd hesitate to accept a one-off fix. The approach in CL 164198 is a little narrower: that just avoids importing empty packages from the generated test main.

In any case, there needs to be a pretty thorough regression test. @forsaken628 if you're interested in writing that, see src/cmd/go/testdata/script/README.

forsaken628 added a commit to forsaken628/go that referenced this issue Dec 17, 2020
forsaken628 added a commit to forsaken628/go that referenced this issue Dec 17, 2020
@golang golang locked and limited conversation to collaborators Dec 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

Successfully merging a pull request may close this issue.

4 participants