diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 8fa99bf11..756b13d4e 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,10 +3,10 @@ "isRoot": true, "tools": { "dotnet-reportgenerator-globaltool": { - "version": "5.1.24", + "version": "5.1.26", "commands": [ "reportgenerator" ] } } -} \ No newline at end of file +} diff --git a/DeterministicBuild.targets b/DeterministicBuild.targets deleted file mode 100644 index 13208d103..000000000 --- a/DeterministicBuild.targets +++ /dev/null @@ -1,23 +0,0 @@ - - - - - $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) - - - - - - - - - - - <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/> - - - diff --git a/Directory.Build.targets b/Directory.Build.targets index a2859274b..8c119d541 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,4 +1,2 @@ - - diff --git a/Documentation/DeterministicBuild.md b/Documentation/DeterministicBuild.md index 31fd2dae7..ea2d1c606 100644 --- a/Documentation/DeterministicBuild.md +++ b/Documentation/DeterministicBuild.md @@ -28,42 +28,6 @@ If you include `DeterministicReport` parameters for `msbuild` and `collectors` i ``` As you can see we have empty `` element and the `filename` start with well known deterministic fragment `/_/...` -**Deterministic build is supported without any workaround since version 3.1.100 of .NET Core SDK** - -## Workaround only for .NET Core SDK < 3.1.100 - -At the moment, deterministic build works thanks to the Roslyn compiler emitting deterministic metadata if `DeterministicSourcePaths` is enabled. Take a look [here](https://github.com/dotnet/sourcelink/tree/master/docs#deterministicsourcepaths) for more information. - -To allow Coverlet to correctly do its work, we need to provide information to translate deterministic paths to real local paths for every project referenced by the test project. The current workaround is to add at the root of your repo a `Directory.Build.targets` with a custom `target` that supports Coverlet resolution algorithm. - -```xml - - - - - $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) - - - - - - - - - - - <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/> - - - - -``` - -If you already have a `Directory.Build.targets` file on your repo root you can simply copy `DeterministicBuild.targets` (which can be found at the root of this repo) next to yours and import it in your targets file. This target will be used by Coverlet to generate, at build time, a file that contains mapping translation information, the file is named `CoverletSourceRootsMapping` and will be in the output folder of your project. You can follow our [step-by-step sample](Examples.md) diff --git a/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.sln b/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.sln index e5ea12eb9..958518178 100644 --- a/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.sln +++ b/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.sln @@ -9,7 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary1", "ClassLibra EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8AE3B75E-33BA-4E07-AD78-2DBCC3392262}" ProjectSection(SolutionItems) = preProject - DeterministicBuild.targets = DeterministicBuild.targets Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets HowTo.md = HowTo.md diff --git a/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.targets b/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.targets deleted file mode 100644 index 13208d103..000000000 --- a/Documentation/Examples/MSBuild/DeterministicBuild/DeterministicBuild.targets +++ /dev/null @@ -1,23 +0,0 @@ - - - - - $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) - - - - - - - - - - - <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/> - - - diff --git a/Documentation/Examples/MSBuild/DeterministicBuild/HowTo.md b/Documentation/Examples/MSBuild/DeterministicBuild/HowTo.md index 7afec0315..de6c38c0c 100644 --- a/Documentation/Examples/MSBuild/DeterministicBuild/HowTo.md +++ b/Documentation/Examples/MSBuild/DeterministicBuild/HowTo.md @@ -97,9 +97,9 @@ Calculating coverage result... +---------+------+--------+--------+ ``` -You should see on output folder the coverlet source root mapping file generated. +You should see on output folder the coverlet source root mapping file generated. The filename starts with 'CoverletSourceRootsMapping_'. This is the confirmation that you're running coverage on deterministic build. ```text -Documentation\Examples\MSBuild\DeterministicBuild\XUnitTestProject1\bin\Debug\net6.0\CoverletSourceRootsMapping +Documentation\Examples\MSBuild\DeterministicBuild\XUnitTestProject1\bin\Debug\net6.0\CoverletSourceRootsMapping_XUnitTestProject1 ``` diff --git a/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.sln b/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.sln index e5ea12eb9..958518178 100644 --- a/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.sln +++ b/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.sln @@ -9,7 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary1", "ClassLibra EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8AE3B75E-33BA-4E07-AD78-2DBCC3392262}" ProjectSection(SolutionItems) = preProject - DeterministicBuild.targets = DeterministicBuild.targets Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets HowTo.md = HowTo.md diff --git a/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.targets b/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.targets deleted file mode 100644 index 13208d103..000000000 --- a/Documentation/Examples/VSTest/DeterministicBuild/DeterministicBuild.targets +++ /dev/null @@ -1,23 +0,0 @@ - - - - - $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) - - - - - - - - - - - <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/> - - - diff --git a/Documentation/Examples/VSTest/DeterministicBuild/Directory.Build.targets b/Documentation/Examples/VSTest/DeterministicBuild/Directory.Build.targets index 95978e1e1..8c119d541 100644 --- a/Documentation/Examples/VSTest/DeterministicBuild/Directory.Build.targets +++ b/Documentation/Examples/VSTest/DeterministicBuild/Directory.Build.targets @@ -1,4 +1,2 @@ - - diff --git a/coverlet.sln b/coverlet.sln index 0bde166bf..314796fe9 100644 --- a/coverlet.sln +++ b/coverlet.sln @@ -31,7 +31,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution eng\azure-pipelines-nightly.yml = eng\azure-pipelines-nightly.yml eng\azure-pipelines.yml = eng\azure-pipelines.yml eng\build.yml = eng\build.yml - DeterministicBuild.targets = DeterministicBuild.targets Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets Directory.Packages.props = Directory.Packages.props diff --git a/eng/build.yml b/eng/build.yml index d1d20d456..feedc9281 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -19,10 +19,10 @@ steps: displayName: Pack - script: | - dotnet test test/coverlet.collector.tests/coverlet.collector.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.collector.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.collector.test.diag.log;tracelevel=verbose" - dotnet test test/coverlet.core.tests/coverlet.core.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.core.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.core.test.diag.log;tracelevel=verbose" - dotnet test test/coverlet.integration.tests/coverlet.integration.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.integration.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.integration.test.diag.log;tracelevel=verbose" - dotnet test test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.msbuild.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.msbuild.test.diag.log;tracelevel=verbose" + dotnet test test/coverlet.collector.tests/coverlet.collector.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.collector.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.collector.test.diag.log;tracelevel=verbose" + dotnet test test/coverlet.core.tests/coverlet.core.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.core.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.core.test.diag.log;tracelevel=verbose" + dotnet test test/coverlet.integration.tests/coverlet.integration.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.integration.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.integration.test.diag.log;tracelevel=verbose" + dotnet test test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.msbuild.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.msbuild.test.diag.log;tracelevel=verbose" displayName: Run tests with coverage - task: PublishTestResults@2 @@ -31,6 +31,7 @@ steps: testResultsFiles: '**/*.trx' mergeTestResults: false publishRunAttachments: true + failTaskOnFailedTests: true - template: publish-coverlet-result-files.yml @@ -38,6 +39,6 @@ steps: - template: publish-coverage-results.yml parameters: reports: $(Build.SourcesDirectory)/**/*.opencover.xml - condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Debug')) - assemblyfilters: '-xunit;-coverlet.testsubject;-Coverlet.Tests.ProjectSample.*' - classfilters: '-[coverlet.core.tests.samples.netstandard]*;-[coverlet.tests.xunit.extensions]*' + condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Debug'), eq(variables['agent.os'], 'Windows_NT')) + assemblyfilters: '-xunit;-coverlet.testsubject;-Coverlet.Tests.ProjectSample.*;-coverlet.core.tests.samples.netstandard;-coverlet.tests.xunit.extensions' + diff --git a/src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj b/src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj index d5dd08007..f5c468290 100644 --- a/src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj +++ b/src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj @@ -37,11 +37,11 @@ - + - + @@ -49,9 +49,9 @@ - - - + + + diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index 7b6884905..8088d0791 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -98,7 +98,7 @@ public void AsyncAwait_Issue_669_1() } } - [Fact] + [Fact (Skip= "Unhandled exception: System.InvalidOperationException: Sequence contains more than one matching element, InstrumenterHelper.cs:line 138 ")] public void AsyncAwait_Issue_669_2() { string path = Path.GetTempFileName(); diff --git a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs index f04233430..50617d62f 100644 --- a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs +++ b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs @@ -135,9 +135,11 @@ public static async Task Run(Func callM await callMethod(Activator.CreateInstance(asm.GetType(typeof(T).FullName))); // Flush tracker +#pragma warning disable CA1307 // Specify StringComparison for clarity Type tracker = asm.GetTypes().Single(n => n.FullName.Contains("Coverlet.Core.Instrumentation.Tracker")); +#pragma warning restore CA1307 // Specify StringComparison for clarity - // For debugging purpouse + // For debugging purpose // int[] hitsArray = (int[])tracker.GetField("HitsArray").GetValue(null); // string hitsFilePath = (string)tracker.GetField("HitsFilePath").GetValue(null); diff --git a/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj b/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj index 69208be7e..3958c1650 100644 --- a/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj +++ b/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj @@ -31,6 +31,7 @@ +