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: unclear when packages have missing test coverage with 1.22 #65262

Closed
rashokkumartce opened this issue Jan 24, 2024 · 10 comments
Closed
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rashokkumartce
Copy link

rashokkumartce commented Jan 24, 2024

Go version

go1.22rc1 darwin/amd64

Output of go env in your module/workspace:

N/A

What did you do?

Created a go file with a couple of interfaces with some method signatures and a variable declaration only

What did you see happen?

[no test files]

What did you expect to see?

coverage: 0.0% of statements

@Jorropo
Copy link
Member

Jorropo commented Jan 24, 2024

Can you show the output of tree in your project and the CLI command you used ?

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 24, 2024
@rashokkumartce
Copy link
Author

Go1.22_Issues.docx
Please check the file for the detailed information

@mvdan
Copy link
Member

mvdan commented Jan 25, 2024

A word document is not a good way to show what you're doing.

Did you try to search past issues about this? For example #24570, but in particular #25492. It seems to me like this is working as expected.

I'm going to close this as a duplicate of #25492 for now.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
@ChrisHines
Copy link
Contributor

@mvdan I am not sure this should be closed for those reasons because the issue is against Go 1.22rc1 and the draft release notes say:

go test -cover now prints coverage summaries for covered packages that do not have their own test files. Prior to Go 1.22 a go test -cover run for such a package would report

? mymod/mypack [no test files]

and now with Go 1.22, functions in the package are treated as uncovered:

mymod/mypack coverage: 0.0% of statements

@mvdan
Copy link
Member

mvdan commented Jan 25, 2024

That seems to be from https://go-review.googlesource.com/c/go/+/495447, which is for #24570, one of the earlier issues I linked. This seems to be working as intended; the author here doesn't mention any declared functions with bodies, so there aren't any lines to be covered. Although it's hard to tell because they haven't been very clear about what they are actually doing.

cc @thanm, perhaps the release notes should be made clearer. I'll reopen the issue for that purpose.

@mvdan mvdan reopened this Jan 25, 2024
@mvdan mvdan changed the title import/path: issue titl cmd/go: unclear when packages have missing test coverage with 1.22 Jan 25, 2024
@ChrisHines
Copy link
Contributor

@mvdan Thanks. I work with the issue author. They are new to Go and this is the first issue they have submitted. :) We'll get the proper details added here soon.

@ChrisHines
Copy link
Contributor

The end result may turn out to be working-as-intended, but we weren't sure.

@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 28, 2024
@rashokkumartce
Copy link
Author

Here is the sample code that is giving the [no test files] as coverage result

sampleInterface.go

package main

import "sync"

type shape interface {
	area(wc *sync.WaitGroup)
	volume()
}

var x = 4

Upon executing the following command
$ go test -count=1 -coverprofile cover.out
and i'm getting the following result printed
? mydomain.com [no test files]

The package just contains the interface and we are trying to execute the command against the package, we are getting the above said result
sampleinterface.go.zip

@thanm
Copy link
Contributor

thanm commented Feb 5, 2024

@rashokkumartce thanks for posting the code in question.

As @mvdan mentioned earlier, this Go file doesn't contain any executable statements, so we can't really meaningfully express a code coverage percentage for it. Code coverage is (at some abstract level) N / M, where N is the number of statement lines executed when the tests are run, and M is the number of statement lines defined. For this case M is zero, which renders the N/M ratio invalid.

If were were to report "mymod/mypack coverage: 0.0% of statements" for this package, this would imply (incorrectly) that the package does contain some executable code and the tests for the package don't trigger the execution of that code, which is definitely not the case for this package.

I'll send a CL to tweak the release notes.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/561337 mentions this issue: relnotes: tweak coverage testing notes

@dmitshur dmitshur added Documentation NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 6, 2024
@dmitshur dmitshur added this to the Go1.22 milestone Feb 6, 2024
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
Clarify the section in the "go" command notes that deals with the
changes to "go test -cover" for packages without tests, adding a note
that if a package has not tests and no executable code, you still get
a "package has no test files" diagnostic.

Fixes golang#65262.

Change-Id: Ie960871f9d5c1a1965090738644eace28fc3e156
Reviewed-on: https://go-review.googlesource.com/c/go/+/561337
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chris Hines <chris.cs.guy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

9 participants