coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

Pre-commit githooks

Open cobasajaxinpho opened this issue 3 years ago • 11 comments

Hi i was trying to setup a coverage checker whereby if fall under 80 %, they won't able to commit it.

somehow result specified is under 80% but still consider success. Need some suggestion is it a correct way to do that?

dotnet version: 7.0.100 OS: Mac OS ventura m1 Chip coverlet version: 3.2.0

code specified in pre-commit:

dotnet test /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line rc=$? if [[ $rc != 0 ]]; then echo "${RED}Unit tests failed, please fix and push again${NC}" echo "" exit $rc fi

Result:

+-----------------+-------+--------+--------+ | Module | Line | Branch | Method | +-----------------+-------+--------+--------+ | WebApplication2 | 15.9% | 16.66% | 20% | +-----------------+-------+--------+--------+

+---------+-------+--------+--------+ | | Line | Branch | Method | +---------+-------+--------+--------+ | Total | 15.9% | 16.66% | 20% | +---------+-------+--------+--------+ | Average | 15.9% | 16.66% | 20% | +---------+-------+--------+--------+

Successfully commited.

Thank you

cobasajaxinpho avatar Nov 23 '22 03:11 cobasajaxinpho

At first sight it seems correct what you are doing. Could you provide a small repro for that?

daveMueller avatar Nov 26 '22 00:11 daveMueller

At first sight it seems correct what you are doing. Could you provide a small repro for that?

Hi Dave.

https://github.com/cobasajaxinpho/Testor

Can try link above for your reference. Thank you. :)

cobasajaxinpho avatar Nov 28 '22 06:11 cobasajaxinpho

Thanks @cobasajaxinpho 🙏

daveMueller avatar Nov 28 '22 23:11 daveMueller

OK I continued investigating this a bit today. It seems like for the msbuild driver the parameters aren't passed to the CoverageResultTask anymore if there is a .NET 7 SDK installed. This is a known issue here https://github.com/coverlet-coverage/coverlet/issues/1391. Thus the Threshold currently is always 0.

In the link are also some workarounds if you need to use msbuild driver. As alternative you could also use the global tool where the Threshold feature is also working.

grafik

daveMueller avatar Dec 02 '22 23:12 daveMueller

Hi Dave,

Thanks for the response, you mean we need to install the coverlet console global version is it?

cobasajaxinpho avatar Dec 09 '22 06:12 cobasajaxinpho

You can also use the msbuild driver but then you currently need to do the workaround with the environment variables. I would most likely go with this here https://github.com/coverlet-coverage/coverlet/issues/1391#issuecomment-1333080663. But I don't have much experience with Mac OS and thus I'm not sure if e.g. a simple -e:CoverletOutputFormat='lcov' will work there.

daveMueller avatar Dec 10 '22 23:12 daveMueller

Hi, the issue was fixed by the microsoft guys with sdk 7.0.101 that was released last week microsoft/vstest#4014. I just checked it with your repro and it works fine. Please give it a try again.

daveMueller avatar Dec 21 '22 22:12 daveMueller

just tried on mac still having the same issue. haha.. you are using mac or windows ?

cobasajaxinpho avatar Dec 22 '22 06:12 cobasajaxinpho

I tried it on windows and linux. Are you sure sdk 7.0.101 is installed? Unfortunately I don't have a Mac and can't test it there.

Windows: grafik

Linux (basic docker image [mcr.microsoft.com/dotnet/sdk:7.0]): grafik

daveMueller avatar Dec 22 '22 23:12 daveMueller

@cobasajaxinpho Are you still facing this issue even though the sdk is now on 7.0.202?

daveMueller avatar Apr 10 '23 21:04 daveMueller