|
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Reflection; |
| 6 | +using System.Runtime.CompilerServices; |
6 | 7 | using System.Threading; |
7 | 8 | using System.Threading.Tasks; |
| 9 | + |
8 | 10 | using Coverlet.Core.Abstracts; |
9 | 11 | using Coverlet.Core.Instrumentation; |
10 | 12 | using Coverlet.Core.Logging; |
| 13 | +using Coverlet.Core.Reporters; |
11 | 14 | using Microsoft.Extensions.DependencyInjection; |
12 | 15 | using Moq; |
13 | | -using Xunit; |
| 16 | +using Palmmedia.ReportGenerator.Core; |
14 | 17 | using Xunit.Sdk; |
15 | 18 |
|
16 | 19 | namespace Coverlet.Core.Tests |
@@ -107,6 +110,33 @@ public static Document AssertLinesCovered(this Document document, params (int li |
107 | 110 |
|
108 | 111 | public static class TestInstrumentationHelper |
109 | 112 | { |
| 113 | + /// <summary> |
| 114 | + /// caller sample: TestInstrumentationHelper.GenerateHtmlReport(result, sourceFileFilter: @"+**\Samples\Instrumentation.cs"); |
| 115 | + /// TestInstrumentationHelper.GenerateHtmlReport(result); |
| 116 | + /// </summary> |
| 117 | + public static void GenerateHtmlReport(CoverageResult coverageResult, IReporter reporter = null, string sourceFileFilter = "", [CallerMemberName]string directory = "") |
| 118 | + { |
| 119 | + reporter ??= new CoberturaReporter(); |
| 120 | + DirectoryInfo dir = Directory.CreateDirectory(directory); |
| 121 | + dir.Delete(true); |
| 122 | + dir.Create(); |
| 123 | + string reportFile = Path.Combine(dir.FullName, Path.ChangeExtension("report", reporter.Extension)); |
| 124 | + File.WriteAllText(reportFile, reporter.Report(coverageResult)); |
| 125 | + // i.e. reportgenerator -reports:"C:\git\coverlet\test\coverlet.core.tests\bin\Debug\netcoreapp2.0\Condition_If\report.cobertura.xml" -targetdir:"C:\git\coverlet\test\coverlet.core.tests\bin\Debug\netcoreapp2.0\Condition_If" -filefilters:+**\Samples\Instrumentation.cs |
| 126 | + new Generator().GenerateReport(new ReportConfiguration( |
| 127 | + new[] { reportFile }, |
| 128 | + dir.FullName, |
| 129 | + new string[0], |
| 130 | + null, |
| 131 | + new string[0], |
| 132 | + new string[0], |
| 133 | + new string[0], |
| 134 | + new string[0], |
| 135 | + string.IsNullOrEmpty(sourceFileFilter) ? new string[0] : new[] { sourceFileFilter }, |
| 136 | + null, |
| 137 | + null)); |
| 138 | + } |
| 139 | + |
110 | 140 | public static CoverageResult GetCoverageResult(string filePath) |
111 | 141 | { |
112 | 142 | using (var result = new FileStream(filePath, FileMode.Open)) |
|
0 commit comments