Skip to content

Commit

Permalink
fix MergeWith option (#1601)
Browse files Browse the repository at this point in the history
* fix MergeWith (net8.0 and net7.0)

* use range operator

* add JsonSerializerOptions

* consolidate nuget package versions

* incorporate review comments

* sanitize report path for all output variations

---------

Co-authored-by: David Müller <muellerdavid4@gmail.com>
  • Loading branch information
Bertk and daveMueller committed Feb 14, 2024
1 parent 16b9883 commit 16eda38
Show file tree
Hide file tree
Showing 31 changed files with 273 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.2.0",
"version": "5.2.1",
"commands": [
"reportgenerator"
]
Expand Down
19 changes: 19 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@
<MicrosoftBuildUtilitiesCorePackageVersion>15.9.20</MicrosoftBuildUtilitiesCorePackageVersion>
<SystemReflectionMetadataVersion>1.6.0</SystemReflectionMetadataVersion>
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>

<!-- some additional information about dependency management limitations for MSBuild tasks (coverlet.msbuild.tasks)
- msBuild task with dependencies https://natemcmaster.com/blog/2017/11/11/msbuild-task-with-dependencies/
- Aligning versions with MSBuild
- If you need a dependency that is also used in MSBuild itself, you have to align with the version MSBuild uses.
- This includes System.Reflection.Metadata, System.Collections.Immutable, NuGet, Newtonsoft.Json, and others.
- See example: dependencies.props (https://github.com/aspnet/BuildTools/blob/1f3f14382764e06b7e691e5ee89d12a280249284/build/dependencies.props#L19-L29)"
.NET 8.0.3xx (MSBuild) core-sdk-tasks version details https://github.com/dotnet/installer/blob/release/8.0.3xx/src/core-sdk-tasks/core-sdk-tasks.csproj
ALIGN PACKAGE VERSIONS of coverlet.core with coverlet.collector (vstest) and coverlet.msbuild.tasks (.NET SDK MSBuild)
e.g. candidates for version conflicts:
<MicrosoftBuildTaskVersion>15.7.179</MicrosoftBuildTaskVersion>
<MicrosoftBuildTaskUtilitiesCoreVersion>15.7.179</MicrosoftBuildTaskUtilitiesCoreVersion>
<NuGetBuildTasksPackageVersion>6.9.0-rc.86</NuGetBuildTasksPackageVersion>
<MicrosoftBuildTaskSystemReflectionMetaData>1.4.2</MicrosoftBuildTaskSystemReflectionMetaData>
<MicrosoftBuildTaskSystemCollectionImmutable>1.5.0</MicrosoftBuildTaskSystemCollectionImmutable> >= 1.3.1
-->
</PropertyGroup>

</Project>
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
vstest 17.8 version
NuGetFrameworksVersion is defined here https://github.com/microsoft/vstest/blob/9a0c41811637edf4afe0e265e08fdd1cb18109ed/eng/Versions.props#L94C1-L94C1
-->
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NuGet.Frameworks" Version="6.8.0" />
<PackageVersion Include="NuGet.Packaging" Version="6.8.0" />
<PackageVersion Include="NuGet.Versioning" Version="6.8.0" />
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="Moq" Version="4.20.69" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="ReportGenerator.Core" Version="5.2.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="ReportGenerator.Core" Version="5.2.1" />
<!--For test issue 809 https://github.com/coverlet-coverage/coverlet/issues/809-->
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="7.1.4" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
Expand All @@ -44,11 +44,11 @@
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.1" />
<PackageVersion Include="Tmds.ExecFunction" Version="0.7.1" />
<PackageVersion Include="xunit" Version="2.6.5" />
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.assemblyfixture" Version="2.2.0" />
<PackageVersion Include="xunit.assert" Version="2.6.5" />
<PackageVersion Include="xunit.assert" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageVersion Include="System.Buffers" Version="4.5.1" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
9 changes: 9 additions & 0 deletions Documentation/MSBuildIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ To specify a directory where all results will be written to (especially if using
dotnet test /p:CollectCoverage=true /p:CoverletOutput='./results/'
```

_Note: escape characters might produce some unexpected results._

|status| msbuild parameter |
|---|---|
|:heavy_check_mark:|`/p:CoverletOutput="C:/GitHub/coverlet/artifacts/Reports/coverlet.core/"`|
|:heavy_check_mark:|`/p:CoverletOutput="C:\\GitHub\\coverlet\\artifacts\\Reports\\coverlet.core\\"`|
|:heavy_check_mark:|`/p:CoverletOutput="C:\GitHub\coverlet\artifacts\Reports\coverlet.core\\"`|
|:x:|`/p:CoverletOutput="C:\GitHub\coverlet\artifacts\Reports\coverlet.core\"`|

The Coverlet MSBuild task sets the `CoverletReport` MSBuild item so that you can easily use the produced coverage reports. For example, using [ReportGenerator](https://github.com/danielpalme/ReportGenerator#usage--command-line-parameters) to generate an html coverage report.

```xml
Expand Down
2 changes: 1 addition & 1 deletion eng/publish-coverage-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
script: |
dotnet tool restore --add-source https://api.nuget.org/v3/index.json
dotnet tool list
dotnet reportgenerator -reports:"${{parameters.reports}}" -targetdir:"$(Build.SourcesDirectory)\artifacts\CoverageReport" -reporttypes:"Html;HtmlInline_AzurePipelines_Dark;Cobertura" -assemblyfilters:"${{parameters.assemblyfilters}}" -classfilters:"${{parameters.classfilters}}" -verbosity:Verbose --minimumCoverageThresholds:lineCoverage=${{parameters.minimumLineCoverage}}
dotnet reportgenerator -reports:"${{parameters.reports}}" -targetdir:"$(Build.SourcesDirectory)\artifacts\CoverageReport" -reporttypes:"HtmlInline_AzurePipelines_Dark;Cobertura" -assemblyfilters:"${{parameters.assemblyfilters}}" -classfilters:"${{parameters.classfilters}}" -verbosity:Verbose --minimumCoverageThresholds:lineCoverage=${{parameters.minimumLineCoverage}}
- publish: '$(Build.SourcesDirectory)/artifacts/CoverageReport'
displayName: 'Publish CoverageReport Artifact'
Expand Down
7 changes: 2 additions & 5 deletions src/coverlet.collector/DataCollection/AttachmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.ComponentModel;
using System.IO;
using coverlet.collector.Resources;
using Coverlet.Collector.Utilities;
using Coverlet.Collector.Utilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
Expand Down Expand Up @@ -109,8 +108,7 @@ private string SaveCoverageReport(string report, string reportFileName)
}
catch (Exception ex)
{
string errorMessage = string.Format(Resources.FailedToSaveCoverageReport, CoverletConstants.DataCollectorName, reportFileName, _reportDirectory);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to save coverage report '{reportFileName}' in directory '{_reportDirectory}'", ex);
}
}

Expand Down Expand Up @@ -168,8 +166,7 @@ private void CleanupReportDirectory()
}
catch (Exception ex)
{
string errorMessage = string.Format(Resources.FailedToCleanupReportDirectory, CoverletConstants.DataCollectorName, _reportDirectory);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to cleanup report directory: '{_reportDirectory}'", ex);
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/coverlet.collector/DataCollection/CoverageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using coverlet.collector.Resources;
using Coverlet.Collector.Utilities;
using Coverlet.Collector.Utilities.Interfaces;
using Coverlet.Core;
Expand Down Expand Up @@ -68,8 +67,7 @@ public void InstrumentModules()
}
catch (Exception ex)
{
string errorMessage = string.Format(Resources.InstrumentationException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to instrument modules", ex);
}
}

Expand All @@ -96,8 +94,7 @@ private CoverageResult GetCoverageResult()
}
catch (Exception ex)
{
string errorMessage = string.Format(Resources.CoverageResultException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to get coverage result", ex);
}
}

Expand All @@ -114,8 +111,7 @@ private IEnumerable<(string report, string fileName)> GetCoverageReports(Coverag
}
catch (Exception ex)
{
string errorMessage = string.Format(Resources.CoverageReportException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to get coverage report", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using coverlet.collector.Resources;
using Coverlet.Collector.Utilities;

namespace Coverlet.Collector.DataCollection
Expand Down Expand Up @@ -72,8 +71,7 @@ private static string ParseTestModule(IEnumerable<string> testModules)
// Validate if at least one source present.
if (testModules == null || !testModules.Any())
{
string errorMessage = string.Format(Resources.NoTestModulesFound, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: No test modules found");
}

// Note:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;
using coverlet.collector.Resources;
using Coverlet.Collector.Utilities;
using Coverlet.Core.Instrumentation;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
Expand Down Expand Up @@ -76,8 +75,7 @@ public void TestSessionEnd(TestSessionEndArgs testSessionEndArgs)
if (_enableExceptionLog)
{
_eqtTrace.Error("{0}: Failed to unload module with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
string errorMessage = string.Format(Resources.FailedToUnloadModule, CoverletConstants.InProcDataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.InProcDataCollectorName}: Failed to unload module", ex);
}
}
}
Expand Down
126 changes: 0 additions & 126 deletions src/coverlet.collector/Resources/Resources.Designer.cs

This file was deleted.

Loading

0 comments on commit 16eda38

Please sign in to comment.