cmd/cover: lines that are unreached (due to panic() ) appear as covered by test #48147
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When running tests with coverage, the lines after calling a panicking function appear to be covered, even though the test could never reach them. They are not executed, just appear to be covered. This happens to every line until a branching statement is reached as can be seen when adding regular statements above the branching statement.
An example can be found at https://github.com/mazanec202/go-wrong-panic-coverage. In this case I had to place the panicking function to a separate package, however on my personal project was the logic complex enough not to be marked by
go vet
as unused while residing in a single package.Using the following commands on the project, it's possible to verify the problem:
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
I believe this issue could provide a false sense of safety and could therefore lead to potential security issues.
What did you expect to see?
Only a line 16 (main.go) containing
panic.DoPanic(true)
to be marked as covered. Line 17 (main.go) containingshouldBeZero = 1
should be marked as not covered.What did you see instead?
Line 17 (main.go) containing
shouldBeZero = 1
is marked as covered, even though the tests prove that the panic was executed and value ofshouldBeZero
is unchanged -0
.The text was updated successfully, but these errors were encountered: