Skip to content

Commit

Permalink
add serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk committed Jan 24, 2024
1 parent 58fe890 commit a63a325
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/coverlet.core.tests/Coverage/CoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using Coverlet.Core.Abstractions;
using Coverlet.Core.Helpers;
using Coverlet.Core.Symbols;
Expand Down Expand Up @@ -94,7 +96,7 @@ public void TestCoverageWithTestAssembly()
}

[Fact]
public void TestCoverageWrongMergeWith()
public void TestCoverageWrongMergeWithParameter()
{
string module = GetType().Assembly.Location;
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
Expand Down Expand Up @@ -130,5 +132,44 @@ public void TestCoverageWrongMergeWith()

directory.Delete(true);
}

[Fact]
public void TestCoverageMergeWithParameter()
{
string module = GetType().Assembly.Location;
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");

DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);

// TODO: Find a way to mimick hits
var instrumentationHelper =
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));

var parameters = new CoverageParameters
{
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" },
IncludeDirectories = Array.Empty<string>(),
ExcludeFilters = Array.Empty<string>(),
ExcludedSourceFiles = Array.Empty<string>(),
ExcludeAttributes = Array.Empty<string>(),
IncludeTestAssembly = false,
SingleHit = false,
MergeWith = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), "MergeWith.coverage.json").First(),
UseSourceLink = false
};

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());
coverage.PrepareModules();

string result = JsonSerializer.Serialize(coverage.GetCoverageResult());

Assert.Contains("DeepThought.cs", result);

directory.Delete(true);
}
}
}
43 changes: 43 additions & 0 deletions test/coverlet.core.tests/TestAssets/MergeWith.coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"coverletsamplelib.integration.template.dll": {
"C:\\GitHub\\coverlet\\artifacts\\bin\\coverlet.integration.tests\\debug_net7.0\\01021711\\Program.cs": {
"HelloWorld.Program": {
"System.Void HelloWorld.Program::Main(System.String[])": {
"Lines": {
"10": 1,
"11": 1,
"12": 1,
"13": 1,
"14": 1
},
"Branches": []
}
}
},
"C:\\GitHub\\coverlet\\artifacts\\bin\\coverlet.integration.tests\\debug_net7.0\\01021711\\DeepThought.cs": {
"Coverlet.Integration.Template.DeepThought": {
"System.Int32 Coverlet.Integration.Template.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()": {
"Lines": {
"6": 1,
"7": 1,
"8": 1
},
"Branches": []
}
}
},
"C:\\GitHub\\coverlet\\artifacts\\bin\\coverlet.integration.tests\\debug_net7.0\\01021711\\TemplateTest.cs": {
"Coverlet.Integration.Template.TemplateTest": {
"System.Void Coverlet.Integration.Template.TemplateTest::Answer()": {
"Lines": {
"9": 0,
"10": 0,
"11": 0,
"12": 0
},
"Branches": []
}
}
}
}
}
3 changes: 3 additions & 0 deletions test/coverlet.core.tests/coverlet.core.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<None Update="TestAssets\CoverletSourceRootsMappingTest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestAssets\MergeWith.coverage.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestAssets\multiple.frameworks.runtimeconfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit a63a325

Please sign in to comment.