Skip to content

Commit

Permalink
Enable test coverage (dotnet#2230)
Browse files Browse the repository at this point in the history
* Revert "exclude test folder from codecov. (dotnet#2227)"

This reverts commit eed91b9.

* Use a fake target path to avoid coverlet-coverage/coverlet#318

* Manually apply codecov flags through multiple uploads

Eventually codecov.io should support the automatic application of flags
based on directory structure. In the meantime, upload the coverage
report twice and allow the server to filter and apply the desired flags.

* Show production code numbers when coverage is reported
  • Loading branch information
sharwell authored and codemzs committed Jan 24, 2019
1 parent eed91b9 commit 5de82ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Daily NuGet builds of the project are also available in our [MyGet](https://dotn

To build ML.NET from source please visit our [developers guide](docs/project-docs/developer-guide.md).

[![codecov](https://codecov.io/gh/dotnet/machinelearning/branch/master/graph/badge.svg)](https://codecov.io/gh/dotnet/machinelearning)
[![codecov](https://codecov.io/gh/dotnet/machinelearning/branch/master/graph/badge.svg?flag=production)](https://codecov.io/gh/dotnet/machinelearning)

| | Debug | Release |
|:---|----------------:|------------------:|
Expand Down
16 changes: 13 additions & 3 deletions build/Codecoverage.proj
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@
<_CodecovArgs Include="--branch;$(_BranchName)" Condition="'$(_BranchName)' != ''" />
<_CodecovArgs Include="-c;$(BUILD_SOURCEVERSION)" Condition="'$(BUILD_SOURCEVERSION)' != ''" />
<_CodecovArgs Include="-n;$(BUILD_DEFINITIONNAME)" Condition="'$(BUILD_DEFINITIONNAME)' != ''" />
<_CodecovArgs Include="--flag;$(Configuration)" Condition="'$(Configuration)' != ''" />
<_CodecovArgs Include="-t;$(CodeCovToken)" Condition="'$(CodeCovToken)' != ''" />

<_CodecovFlags Include="$(Configuration)" Condition="'$(Configuration)' != ''" />
<_CodecovProductionFlags Include="@(_CodecovFlags)" />
<_CodecovProductionFlags Include="production" />
<_CodecovTestFlags Include="@(_CodecovFlags)" />
<_CodecovTestFlags Include="test" />
</ItemGroup>

<Message Importance="high" Text="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ')" />
<Exec Command="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ')" />
<!-- Upload the coverage file with a 'production' flag, which will be filtered by codecov.io to production code -->
<Message Importance="high" Text="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovProductionFlags, ',')" />
<Exec Command="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovProductionFlags, ',')" />

<!-- Upload the coverage file with a 'test' flag, which will be filtered by codecov.io to test code -->
<Message Importance="high" Text="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovTestFlags, ',')" />
<Exec Command="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovTestFlags, ',')" />
</Target>

</Project>
4 changes: 1 addition & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ coverage:
default: false
fixes:
- "build/::/"
ignore:
- "test"

comment:
layout: "diff"
layout: "diff,flags"

flags:
production:
Expand Down
14 changes: 14 additions & 0 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@

<Import Project="..\Directory.Build.targets" />

<!-- Workaround for https://github.com/tonerdo/coverlet/pull/318 -->
<Target Name="UpdateTargetPathForCoverage" BeforeTargets="InstrumentModulesNoBuild;InstrumentModulesAfterBuild">
<PropertyGroup>
<_CoverletOriginalTargetPath>$(TargetPath)</_CoverletOriginalTargetPath>
<TargetPath>$([System.IO.Path]::GetDirectoryName($(TargetPath)))\NonExistent.dll</TargetPath>
</PropertyGroup>
</Target>

<Target Name="UpdateTargetPathAfterCoverage" AfterTargets="InstrumentModulesNoBuild;InstrumentModulesAfterBuild">
<PropertyGroup>
<TargetPath>$(_CoverletOriginalTargetPath)</TargetPath>
</PropertyGroup>
</Target>

</Project>

0 comments on commit 5de82ed

Please sign in to comment.