diff --git a/test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs b/test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs index 2df5d546c..3f7c592ad 100644 --- a/test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs +++ b/test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs @@ -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(); @@ -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(); @@ -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"); @@ -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(), Array.Empty(), Array.Empty(), attributesToIgnore, false, new Mock().Object); + Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty(), Array.Empty(), excludedFiles, attributesToIgnore, singleHit, new Mock().Object); + return new InstrumenterTest { Instrumenter = instrumenter, @@ -253,5 +258,14 @@ public void SkipEmbeddedPpdbWithoutLocalSource() loggerMock.VerifyNoOtherCalls(); } + [Fact] + public void TestInstrument_MissingModule() + { + var loggerMock = new Mock(); + var instrumenter = new Instrumenter("test", "_test_instrumented", Array.Empty(), Array.Empty(), Array.Empty(), Array.Empty(), false, loggerMock.Object); + Assert.False(instrumenter.CanInstrument()); + loggerMock.Verify(l => l.LogWarning(It.IsAny())); + } + } -} \ No newline at end of file +} diff --git a/test/coverlet.core.tests/Samples/Samples.cs b/test/coverlet.core.tests/Samples/Samples.cs index 6873546eb..79fc35ad7 100644 --- a/test/coverlet.core.tests/Samples/Samples.cs +++ b/test/coverlet.core.tests/Samples/Samples.cs @@ -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()