|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using System.IO; |
| 6 | +using System.Linq; |
| 7 | +using System.Text.Json; |
6 | 8 | using Coverlet.Core.Abstractions; |
7 | 9 | using Coverlet.Core.Helpers; |
8 | 10 | using Coverlet.Core.Symbols; |
@@ -94,7 +96,7 @@ public void TestCoverageWithTestAssembly() |
94 | 96 | } |
95 | 97 |
|
96 | 98 | [Fact] |
97 | | - public void TestCoverageWrongMergeWith() |
| 99 | + public void TestCoverageWrongMergeWithParameter() |
98 | 100 | { |
99 | 101 | string module = GetType().Assembly.Location; |
100 | 102 | string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb"); |
@@ -130,5 +132,44 @@ public void TestCoverageWrongMergeWith() |
130 | 132 |
|
131 | 133 | directory.Delete(true); |
132 | 134 | } |
| 135 | + |
| 136 | + [Fact] |
| 137 | + public void TestCoverageMergeWithParameter() |
| 138 | + { |
| 139 | + string module = GetType().Assembly.Location; |
| 140 | + string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb"); |
| 141 | + |
| 142 | + DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); |
| 143 | + |
| 144 | + File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true); |
| 145 | + File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true); |
| 146 | + |
| 147 | + // TODO: Find a way to mimick hits |
| 148 | + var instrumentationHelper = |
| 149 | + new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object, |
| 150 | + new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter())); |
| 151 | + |
| 152 | + var parameters = new CoverageParameters |
| 153 | + { |
| 154 | + IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" }, |
| 155 | + IncludeDirectories = Array.Empty<string>(), |
| 156 | + ExcludeFilters = Array.Empty<string>(), |
| 157 | + ExcludedSourceFiles = Array.Empty<string>(), |
| 158 | + ExcludeAttributes = Array.Empty<string>(), |
| 159 | + IncludeTestAssembly = false, |
| 160 | + SingleHit = false, |
| 161 | + MergeWith = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), "MergeWith.coverage.json").First(), |
| 162 | + UseSourceLink = false |
| 163 | + }; |
| 164 | + |
| 165 | + var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper()); |
| 166 | + coverage.PrepareModules(); |
| 167 | + |
| 168 | + string result = JsonSerializer.Serialize(coverage.GetCoverageResult()); |
| 169 | + |
| 170 | + Assert.Contains("DeepThought.cs", result); |
| 171 | + |
| 172 | + directory.Delete(true); |
| 173 | + } |
133 | 174 | } |
134 | 175 | } |
0 commit comments