You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: coverage calculation is wrong when runtime error occurs #62258
changed the title [-]testing/cover: If an error occurs in a line of code while calculating code coverage, the code that follows this line within the same code block will still be included in the coverage calculation.[/-][+]testing/cover: Coverage calculation is wrong when runtime error occurs[/+]on Aug 24, 2023
changed the title [-]testing/cover: Coverage calculation is wrong when runtime error occurs[/-][+]testing: coverage calculation is wrong when runtime error occurs[/+]on Aug 24, 2023
Can you include the code for parsecover.go? Which command are you running to retrieve coverage data?
The code posted above is parsecover.go.
I use go build -cover -o myprogram parsecover.go GOCOVERDIR=./hhh ./myprogram go tool covdata textfmt -i=hhh -o profile.txt go tool cover -func=profile.txt
Since coverage calculation is block-based, it assumes that all statements in a (branch-free) block will be executed. Without making the generated coverage code more fine-grained and inefficient, this would be hard to fix. It is an unusual enough case that it doesn't seem worth fixing.
Activity
[-]testing/cover: If an error occurs in a line of code while calculating code coverage, the code that follows this line within the same code block will still be included in the coverage calculation.[/-][+]testing/cover: Coverage calculation is wrong when runtime error occurs[/+][-]testing/cover: Coverage calculation is wrong when runtime error occurs[/-][+]testing: coverage calculation is wrong when runtime error occurs[/+]cagedmantis commentedon Aug 24, 2023
Can you include the code for parsecover.go? Which command are you running to retrieve coverage data?
Eiwinda commentedon Aug 25, 2023
The code posted above is parsecover.go.
I use
go build -cover -o myprogram parsecover.goGOCOVERDIR=./hhh ./myprogramgo tool covdata textfmt -i=hhh -o profile.txtgo tool cover -func=profile.txtrobpike commentedon Aug 25, 2023
Since coverage calculation is block-based, it assumes that all statements in a (branch-free) block will be executed. Without making the generated coverage code more fine-grained and inefficient, this would be hard to fix. It is an unusual enough case that it doesn't seem worth fixing.