FineCodeCoverage icon indicating copy to clipboard operation
FineCodeCoverage copied to clipboard

False coverage for C# fixed statement

Open mbenningfield1 opened this issue 6 months ago • 6 comments

The following code:

byte[] b = Encoding.GetBytes(s);
fixed (byte* pb = b) {
  interop_call(pb, 4);
}

is cited as a 50% covered branch in the Cobertura.xml coverage results, on the line number of the fixed statement, and it shows yellow in the coverage margin.

mbenningfield1 avatar Jun 16 '25 10:06 mbenningfield1

FCC runs the coverage tools. We just surface the results. If you get the same results with RunMsCoverage No and Yes then the coverage will be correct.

tonyhallett avatar Jun 16 '25 14:06 tonyhallett

Well that's kinda my point. The coverage is not correct, because that isn't a branch. So you're saying I should raise the issue with Microsoft?

mbenningfield1 avatar Jun 16 '25 15:06 mbenningfield1

If you are using RunMsCodeCoverage Yes. Although we use the cobertura format and not the binary format which account for what you see.

No issues https://github.com/microsoft/codecoverage/issues?q=is%3Aissue state%3Aopen fixed statement

https://github.com/coverlet-coverage/coverlet/issues/1016

tonyhallett avatar Jun 16 '25 15:06 tonyhallett

https://chatgpt.com/c/68503cd8-2fdc-8003-aa54-d534b8932581

tonyhallett avatar Jun 16 '25 15:06 tonyhallett

OK, so I gather that it is still an open issue in Coverlet, and that nobody has raised the issue with Microsoft. I'm away from that machine at the moment, but later today I'll double check that I have RunMsCodeCoverage Yes (I'm almost positive I do) and either raise the issue with Microsoft, or bump the one in Coverlet.

mbenningfield1 avatar Jun 16 '25 16:06 mbenningfield1

There should be two cobertura files - the one you see and the original that is passed to report generator. Please check the original in case there is an issue with report generator.

tonyhallett avatar Jun 17 '25 11:06 tonyhallett

Definitely using ms code coverage, and both of the cobertura.xml files show the same error for what looks like every fixed statement in the code base.

mbenningfield1 avatar Jun 20 '25 13:06 mbenningfield1

OK, I have opened an issue with testfx at issue, so I'm closing this one.

mbenningfield1 avatar Jun 22 '25 14:06 mbenningfield1