Skip to content

Commit e3c5737

Browse files
Opt-in reachability helper (#1061)
Opt-in reachability helper
1 parent 070f2b4 commit e3c5737

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

Documentation/Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Fixed
10+
11+
-Fix multi-line lambda coverage regression [#1060](https://github.com/coverlet-coverage/coverlet/pull/1060)
12+
-Opt-in reachability helper to mitigate resolution issue [#1061](https://github.com/coverlet-coverage/coverlet/pull/1061)
13+
714
## Release date 2021-01-16
815
### Packages
916
coverlet.msbuild 3.0.1

Documentation/MSBuildIntegration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Syntax: `/p:SkipAutoProps=true`
173173

174174
### Methods that do not return
175175

176-
Methods that do not return can be marked with attributes to cause statements after them to be excluded from coverage. `DoesNotReturnAttribute` is included by default.
176+
Methods that do not return can be marked with attributes to cause statements after them to be excluded from coverage.
177177

178178
Attributes can be specified with the following syntax.
179179
Syntax: `/p:DoesNotReturnAttribute="DoesNotReturnAttribute,OtherAttribute"`

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Instrumenter(
8181
_fileSystem = fileSystem;
8282
_sourceRootTranslator = sourceRootTranslator;
8383
_cecilSymbolHelper = cecilSymbolHelper;
84-
_doesNotReturnAttributes = PrepareAttributes(doesNotReturnAttributes, nameof(DoesNotReturnAttribute));
84+
_doesNotReturnAttributes = PrepareAttributes(doesNotReturnAttributes);
8585
_skipAutoProps = skipAutoProps;
8686
}
8787

test/coverlet.core.tests/Coverage/CoverageTests.DoesNotReturn.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void NoBranches_DoesNotReturnAttribute_InstrumentsCorrect()
2323
catch (Exception) { }
2424
return Task.CompletedTask;
2525

26-
}, persistPrepareResultToFile: pathSerialize[0]);
26+
}, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" });
2727

2828
return 0;
2929

@@ -183,7 +183,7 @@ public void CallsGenericMethodDoesNotReturn_DoesNotReturnAttribute_InstrumentsCo
183183
catch (Exception) { }
184184
return Task.CompletedTask;
185185

186-
}, persistPrepareResultToFile: pathSerialize[0]);
186+
}, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" });
187187

188188
return 0;
189189

@@ -215,7 +215,7 @@ public void CallsGenericClassDoesNotReturn_DoesNotReturnAttribute_InstrumentsCor
215215
catch (Exception) { }
216216
return Task.CompletedTask;
217217

218-
}, persistPrepareResultToFile: pathSerialize[0]);
218+
}, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" });
219219

220220
return 0;
221221

@@ -247,7 +247,7 @@ public void WithLeave_DoesNotReturnAttribute_InstrumentsCorrect()
247247
catch (Exception) { }
248248
return Task.CompletedTask;
249249

250-
}, persistPrepareResultToFile: pathSerialize[0]);
250+
}, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" });
251251

252252
return 0;
253253

@@ -279,7 +279,7 @@ public void FiltersAndFinallies_DoesNotReturnAttribute_InstrumentsCorrect()
279279
catch (Exception) { }
280280
return Task.CompletedTask;
281281

282-
}, persistPrepareResultToFile: pathSerialize[0]);
282+
}, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" });
283283

284284
return 0;
285285

test/coverlet.core.tests/Coverage/InstrumenterHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static CoverageResult GetCoverageResult(string filePath)
7070
async public static Task<CoveragePrepareResult> Run<T>(Func<dynamic, Task> callMethod,
7171
Func<string, string[]> includeFilter = null,
7272
Func<string, string[]> excludeFilter = null,
73+
Func<string, string[]> doesNotReturnAttributes = null,
7374
string persistPrepareResultToFile = null,
7475
bool disableRestoreModules = false,
7576
bool skipAutoProps = false)
@@ -111,7 +112,8 @@ async public static Task<CoveragePrepareResult> Run<T>(Func<dynamic, Task> callM
111112
SingleHit = false,
112113
MergeWith = string.Empty,
113114
UseSourceLink = false,
114-
SkipAutoProps = skipAutoProps
115+
SkipAutoProps = skipAutoProps,
116+
DoesNotReturnAttributes = doesNotReturnAttributes?.Invoke(fileName)
115117
};
116118

117119
// Instrument module

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false, stri
252252
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object, new SourceRootTranslator(new Mock<ILogger>().Object, new FileSystem()));
253253

254254
module = Path.Combine(directory.FullName, destModule);
255-
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, Array.Empty<string>(), false, false,
255+
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, new string[] { "DoesNotReturnAttribute" }, false, false,
256256
_mockLogger.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper());
257257
return new InstrumenterTest
258258
{
@@ -590,7 +590,7 @@ public int SampleMethod()
590590
excludedAttributes, Array.Empty<string>(), false, false, loggerMock.Object, instrumentationHelper, partialMockFileSystem.Object, new SourceRootTranslator(loggerMock.Object, new FileSystem()), new CecilSymbolHelper());
591591

592592
InstrumenterResult result = instrumenter.Instrument();
593-
if(expectedExcludes)
593+
if (expectedExcludes)
594594
{
595595
Assert.Empty(result.Documents);
596596
loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>()));
@@ -783,6 +783,6 @@ public void TestReachabilityHelper()
783783
instrumenterTest.Directory.Delete(true);
784784
}
785785

786-
786+
787787
}
788788
}

0 commit comments

Comments
 (0)