Skip to content

Commit e808d16

Browse files
author
Paulo Janotti
committed
Attempt to improve coverage of CoreLibMetadataImporterProvider
1 parent 3092142 commit e808d16

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ public void TestInstrument()
4646
instrumenterTest.Directory.Delete(true);
4747
}
4848

49+
[Fact]
50+
public void TestInstrumentCoreLib()
51+
{
52+
var instrumenterTest = CreateInstrumentor(fakeCoreLibModule: true);
53+
54+
var result = instrumenterTest.Instrumenter.Instrument();
55+
56+
Assert.Equal(Path.GetFileNameWithoutExtension(instrumenterTest.Module), result.Module);
57+
Assert.Equal(instrumenterTest.Module, result.ModulePath);
58+
59+
instrumenterTest.Directory.Delete(true);
60+
}
61+
4962
[Theory]
5063
[InlineData(typeof(ClassExcludedByCodeAnalysisCodeCoverageAttr))]
5164
[InlineData(typeof(ClassExcludedByCoverletCodeCoverageAttr))]
@@ -63,18 +76,30 @@ public void TestInstrument_ClassesWithExcludeAttributeAreExcluded(Type excludedT
6376
instrumenterTest.Directory.Delete(true);
6477
}
6578

66-
private InstrumenterTest CreateInstrumentor()
79+
private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false)
6780
{
6881
string module = GetType().Assembly.Location;
6982
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
7083
string identifier = Guid.NewGuid().ToString();
7184

7285
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), identifier));
7386

74-
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
75-
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);
87+
string destModule, destPdb;
88+
if (fakeCoreLibModule)
89+
{
90+
destModule = "System.Private.CoreLib.dll";
91+
destPdb = "System.Private.CoreLib.pdb";
92+
}
93+
else
94+
{
95+
destModule = Path.GetFileName(module);
96+
destPdb = Path.GetFileName(pdb);
97+
}
98+
99+
File.Copy(module, Path.Combine(directory.FullName, destModule), true);
100+
File.Copy(pdb, Path.Combine(directory.FullName, destPdb), true);
76101

77-
module = Path.Combine(directory.FullName, Path.GetFileName(module));
102+
module = Path.Combine(directory.FullName, destModule);
78103
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>());
79104
return new InstrumenterTest
80105
{

0 commit comments

Comments
 (0)