Skip to content

Commit

Permalink
Fixing coverage reporting (#396)
Browse files Browse the repository at this point in the history
Moved from MSBuild to Collector
Made a util which copies the report from some strange folder into the root
And now it sends normally this report to codecov
  • Loading branch information
WhiteBlackGoose authored Apr 26, 2021
1 parent b31f1cc commit 11e738f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CSharpBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: Build
run: |
cd Sources
dotnet build AngouriMath || dotnet build AngouriMath || dotnet build AngouriMath
dotnet build AngouriMath
15 changes: 11 additions & 4 deletions .github/workflows/CSharpTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ jobs:

- name: Build Tests # We need it to be able to retry
run: |
dotnet add "Sources/Tests/UnitTests" package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything
dotnet add "Sources/Tests/UnitTests" package GitHubActionsTestLogger
dotnet add "Sources/Tests/UnitTests" package coverlet.msbuild
dotnet build Sources/Tests/UnitTests || dotnet build Tests/UnitTests || dotnet build Tests/UnitTests
dotnet build Sources/Tests/UnitTests
- name: Test
- name: Test if not to send
if: ${{ matrix.os != 'windows-latest' }}
run: |
dotnet test "Sources/Tests/UnitTests" -c Release -l GitHubActions /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- name: Test if to send
if: ${{ matrix.os == 'windows-latest' }}
run: |
cd Sources/Tests/UnitTests
dotnet test --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
cd ../../Utils/Utils
dotnet run CopyCovReport
- name: Info about the coverage report
if: ${{ matrix.os == 'windows-latest' }}
run: dir ./Sources/Tests/UnitTests/coverage.opencover.xml
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ out/
/Sources/Wrappers/AngouriMath.CPP.Importing/out-x64
/Sources/Utils/Utils/Properties/launchSettings.json
out/
TestResults
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="coverlet.runsettings" />
<Compile Include="Functions.Sets.fs" />
<Compile Include="CoreTest.fs" />
<Compile Include="ShortcutsTest.fs" />
Expand All @@ -20,16 +21,22 @@
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0-preview-20210219-03" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

Expand Down
14 changes: 11 additions & 3 deletions Sources/Tests/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.Combinatorial" Version="1.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0" />
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\AngouriMath\AngouriMath.csproj" />
</ItemGroup>
Expand Down
59 changes: 59 additions & 0 deletions Sources/Utils/Utils/CopyCovReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
public static class CopyCovReport
{
private static void Log(string msg)
{
Console.WriteLine("CopyCovReport: " + msg);
}

public static void Do()
{
Log("We are in " + Path.GetFullPath("./"));
var sources = Path.GetFullPath(Program.GetPathIntoSources());
Log("Sources are " + sources);

var root = Path.Join(sources, "Tests", "UnitTests");
var testResults = Path.Join(root, "TestResults");
Log("Path to take results from: " + Path.GetFullPath(testResults));


var dirList = Directory.GetDirectories(testResults);
if (!dirList.Any())
throw new Exception("No directory found");
if (dirList.Count() > 1)
throw new Exception($"More than one directory found: {string.Join(", ", dirList)}");
var dir = dirList.First();
Log("Found dir: " + Path.GetFullPath(dir));


var fileList = Directory.GetFiles(dir);
if (!fileList.Any())
throw new Exception("No report found");
if (fileList.Count() > 1)
throw new Exception($"More than one report found: {string.Join(", ", fileList)}");
var file = fileList.First();
Log("Found file: " + Path.GetFullPath(file));

var fileName = Path.GetFileName(file);
var destination = Path.Join(root, fileName);
if (File.Exists(destination))
{
File.Delete(destination);
Log("The file was deleted: " + Path.GetFullPath(destination));
}


var source = file;
File.Copy(source, destination);
Log($"Copied from {Path.GetFullPath(source)} to {Path.GetFullPath(destination)}");
}
}
}

0 comments on commit 11e738f

Please sign in to comment.