Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public void TestCoreLibInstrumentation()
Assert.NotNull(result);
}

[Fact]
public void TestInstrument()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void TestInstrument(bool singleHit)
{
var instrumenterTest = CreateInstrumentor();
var instrumenterTest = CreateInstrumentor(singleHit: singleHit);

var result = instrumenterTest.Instrumenter.Instrument();

Expand All @@ -55,10 +57,12 @@ public void TestInstrument()
instrumenterTest.Directory.Delete(true);
}

[Fact]
public void TestInstrumentCoreLib()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void TestInstrumentCoreLib(bool singleHit)
{
var instrumenterTest = CreateInstrumentor(fakeCoreLibModule: true);
var instrumenterTest = CreateInstrumentor(fakeCoreLibModule: true, singleHit: singleHit);

var result = instrumenterTest.Instrumenter.Instrument();

Expand Down Expand Up @@ -144,7 +148,7 @@ public void TestInstrument_ClassesWithPropertyWithCustomExcludeAttributeAreExclu
instrumenterTest.Directory.Delete(true);
}

private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false, string[] attributesToIgnore = null)
private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false, string[] attributesToIgnore = null, string[] excludedFiles = null, bool singleHit = false)
{
string module = GetType().Assembly.Location;
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
Expand All @@ -168,7 +172,8 @@ private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false, stri
File.Copy(pdb, Path.Combine(directory.FullName, destPdb), true);

module = Path.Combine(directory.FullName, destModule);
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, false, new Mock<ILogger>().Object);
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), excludedFiles, attributesToIgnore, singleHit, new Mock<ILogger>().Object);

return new InstrumenterTest
{
Instrumenter = instrumenter,
Expand Down Expand Up @@ -253,5 +258,14 @@ public void SkipEmbeddedPpdbWithoutLocalSource()
loggerMock.VerifyNoOtherCalls();
}

[Fact]
public void TestInstrument_MissingModule()
{
var loggerMock = new Mock<ILogger>();
var instrumenter = new Instrumenter("test", "_test_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object);
Assert.False(instrumenter.CanInstrument());
loggerMock.Verify(l => l.LogWarning(It.IsAny<string>()));
}

}
}
}
13 changes: 13 additions & 0 deletions test/coverlet.core.tests/Samples/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ public class ClassWithPropertyExcludedByObsoleteAttr
public string Property { get; set; }
}

public class ClassWithSetterOnlyPropertyExcludedByObsoleteAttr
{
[Obsolete]
public string Property {
set => _ = string.Empty;
}
}

public abstract class ClassWithEmptyMethod
{
public abstract void EmptyMethod();
}

public class ExceptionFilter
{
public void Test()
Expand Down