Skip to content

Commit 75520dd

Browse files
daveMuellerMarcoRossignoli
authored andcommitted
Improve instrumentation tests (#527)
Improve instrumentation tests
1 parent a167c39 commit 75520dd

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public void TestCoreLibInstrumentation()
4242
Assert.NotNull(result);
4343
}
4444

45-
[Fact]
46-
public void TestInstrument()
45+
[Theory]
46+
[InlineData(true)]
47+
[InlineData(false)]
48+
public void TestInstrument(bool singleHit)
4749
{
48-
var instrumenterTest = CreateInstrumentor();
50+
var instrumenterTest = CreateInstrumentor(singleHit: singleHit);
4951

5052
var result = instrumenterTest.Instrumenter.Instrument();
5153

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

58-
[Fact]
59-
public void TestInstrumentCoreLib()
60+
[Theory]
61+
[InlineData(true)]
62+
[InlineData(false)]
63+
public void TestInstrumentCoreLib(bool singleHit)
6064
{
61-
var instrumenterTest = CreateInstrumentor(fakeCoreLibModule: true);
65+
var instrumenterTest = CreateInstrumentor(fakeCoreLibModule: true, singleHit: singleHit);
6266

6367
var result = instrumenterTest.Instrumenter.Instrument();
6468

@@ -144,7 +148,7 @@ public void TestInstrument_ClassesWithPropertyWithCustomExcludeAttributeAreExclu
144148
instrumenterTest.Directory.Delete(true);
145149
}
146150

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

170174
module = Path.Combine(directory.FullName, destModule);
171-
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, false, new Mock<ILogger>().Object);
175+
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), excludedFiles, attributesToIgnore, singleHit, new Mock<ILogger>().Object);
176+
172177
return new InstrumenterTest
173178
{
174179
Instrumenter = instrumenter,
@@ -253,5 +258,14 @@ public void SkipEmbeddedPpdbWithoutLocalSource()
253258
loggerMock.VerifyNoOtherCalls();
254259
}
255260

261+
[Fact]
262+
public void TestInstrument_MissingModule()
263+
{
264+
var loggerMock = new Mock<ILogger>();
265+
var instrumenter = new Instrumenter("test", "_test_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object);
266+
Assert.False(instrumenter.CanInstrument());
267+
loggerMock.Verify(l => l.LogWarning(It.IsAny<string>()));
268+
}
269+
256270
}
257-
}
271+
}

test/coverlet.core.tests/Samples/Samples.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ public class ClassWithPropertyExcludedByObsoleteAttr
227227
public string Property { get; set; }
228228
}
229229

230+
public class ClassWithSetterOnlyPropertyExcludedByObsoleteAttr
231+
{
232+
[Obsolete]
233+
public string Property {
234+
set => _ = string.Empty;
235+
}
236+
}
237+
238+
public abstract class ClassWithEmptyMethod
239+
{
240+
public abstract void EmptyMethod();
241+
}
242+
230243
public class ExceptionFilter
231244
{
232245
public void Test()

0 commit comments

Comments
 (0)