From 85bfbfcf5451463d285fd1ccd0b3ac0d8be7b949 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 6 May 2020 19:03:55 +0200 Subject: [PATCH] Re-enable xunit.console code coverage (#35894) Re-enable xunit console code coverage measurement until https://github.com/coverlet-coverage/coverlet/issues/834 is fixed. --- .config/dotnet-tools.json | 8 ++++++- docs/workflow/building/libraries/code-coverage.md | 4 ++-- eng/testing/coverage.targets | 26 ++++++++++++++++++++++- src/libraries/tests.proj | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index fd4f16b..49e4750 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -2,8 +2,14 @@ "version": 1, "isRoot": true, "tools": { + "coverlet.console": { + "version": "1.7.1", + "commands": [ + "coverlet" + ] + }, "dotnet-reportgenerator-globaltool": { - "version": "4.5.2", + "version": "4.5.8", "commands": [ "reportgenerator" ] diff --git a/docs/workflow/building/libraries/code-coverage.md b/docs/workflow/building/libraries/code-coverage.md index 7b77512..d9ab38a 100644 --- a/docs/workflow/building/libraries/code-coverage.md +++ b/docs/workflow/building/libraries/code-coverage.md @@ -36,7 +36,7 @@ This runs the tests and generates the full code coverage report. The resulting i You can also build and test with code coverage for a particular test project rather than for the whole repo with the `/p:Coverage=true` property: - dotnet test -f net5.0 /p:Coverage=true + dotnet build /t:Test /p:Coverage=true The results for this one library will then be available in this index.htm file, where $(OutDir) is the directory where the binaries were generated. @@ -44,7 +44,7 @@ The results for this one library will then be available in this index.htm file, For example, to build, test, and get code coverage results for the System.Diagnostics.Debug library, from the root of the repo one can do: - dotnet test src\libraries\System.Diagnostics.Debug -f net5.0 /p:Coverage=true + dotnet build src\System.Diagnostics.Debug\tests /t:Test /p:Coverage=true And then once the run completes: diff --git a/eng/testing/coverage.targets b/eng/testing/coverage.targets index 62e77ca..fd53a86 100644 --- a/eng/testing/coverage.targets +++ b/eng/testing/coverage.targets @@ -33,8 +33,32 @@ + + + + coverage.opencover.xml + $(CoverageOutputPath) + $([MSBuild]::NormalizeDirectory('$(OutDir)', 'report')) + + "$(DotNetTool)" tool run coverlet "$(TargetFileName)" --target "$(RunScriptHost)" --targetargs "$(RunScriptCommand.Replace('"$(RunScriptHost)"', ''))" --format "opencover" --output "$(CoverageOutputPath)" --verbosity "normal" --use-source-link + $(RunScriptCommand) --exclude-by-file @(CoverageExcludeByFile -> '"%(Identity)"', ' --exclude-by-file ') + $(RunScriptCommand) --include-directory @(CoverageIncludeDirectory -> '"$(RunScriptHostDir)%(Identity)"', ' --include-directory ') + $(RunScriptCommand) --include @(CoverageInclude -> '"[%(Identity)]*"', ' --include ') + "$(DotNetTool)" tool run reportgenerator "-reports:$(CoverageReportInputPath)" "-targetdir:$(CoverageReportDir.TrimEnd('\/'))" "-reporttypes:Html" "-verbosity:Info" + + + + + + + + + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 9863624..6e92a43 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -5,7 +5,7 @@ ErrorAndContinue BuildAllProjects=true - $(ArtifactsBinDir)*.Tests\TestResults\*\coverage.opencover.xml + $(ArtifactsBinDir)\*.Tests\**\coverage.opencover.xml $(ArtifactsDir)coverage true -- 2.7.4