Skip to content

Commit 8adfb45

Browse files
committed
addressing first comments
1 parent d3b2db1 commit 8adfb45

File tree

6 files changed

+7
-13
lines changed

6 files changed

+7
-13
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Coverage
1515
private IEnumerable<string> _excludedFiles;
1616
private List<InstrumenterResult> _results;
1717

18-
public Coverage(string module, string identifier, IEnumerable<string> excludedFiles)
18+
public Coverage(string module, string identifier, IEnumerable<string> excludedFiles = null)
1919
{
2020
_module = module;
2121
_identifier = identifier;

src/coverlet.core/Helpers/InstrumentationHelper.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static void DeleteHitsFile(string path)
110110
}
111111

112112
public static string[] GetExcludedFiles(string[] exclusionRules, string parentDir) {
113-
if (exclusionRules == null || exclusionRules.Length == 0 ) return null;
113+
if (!(exclusionRules?.Length > 0) ) return null;
114114
var matcher = new Matcher();
115115
foreach (var exclusionRule in exclusionRules)
116116
{
@@ -121,11 +121,7 @@ public static string[] GetExcludedFiles(string[] exclusionRules, string parentDi
121121

122122
var fileMatchResult = matcher.Execute(new DirectoryInfoWrapper(directoryInfo));
123123
return fileMatchResult.Files
124-
.Select(
125-
f => System.IO.Path.GetFullPath(
126-
System.IO.Path.Combine(directoryInfo.ToString(), f.Path)
127-
)
128-
)
124+
.Select(f => Path.GetFullPath(Path.Combine(directoryInfo.ToString(), f.Path)))
129125
.ToArray();
130126
}
131127
}

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Instrumenter(string module, string identifier, IEnumerable<string> exclud
2424
{
2525
_module = module;
2626
_identifier = identifier;
27-
_excludedFiles = excludedFiles;
27+
_excludedFiles = excludedFiles ?? Enumerable.Empty<string>();
2828
}
2929

3030
public bool CanInstrument() => InstrumentationHelper.HasPdb(_module);
@@ -65,8 +65,8 @@ private void InstrumentModule()
6565

6666
foreach (var method in type.Methods)
6767
{
68-
var sourceFiles = method.DebugInformation.SequencePoints.Select(s => s.Document.Url).Distinct();
69-
if (_excludedFiles != null && sourceFiles.Any(_excludedFiles.Contains)) {
68+
var sourceFile = method.DebugInformation.SequencePoints.Select(s => s.Document.Url).FirstOrDefault();
69+
if (!string.IsNullOrEmpty(sourceFile) && _excludedFiles.Contains(sourceFile)) {
7070
continue;
7171
}
7272
if (!method.CustomAttributes.Any(a => a.AttributeType.Name == "ExcludeFromCoverageAttribute" || a.AttributeType.Name == "ExcludeFromCoverage"))

test/coverlet.core.tests/CoverageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void TestCoverage()
2121

2222
File.Copy(module, tempModule, true);
2323

24-
var coverage = new Coverage(tempModule, identifier, null);
24+
var coverage = new Coverage(tempModule, identifier);
2525
coverage.PrepareModules();
2626

2727
var result = coverage.GetCoverageResult();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Xunit;
55
using Coverlet.Core.Instrumentation;
6-
using Coverlet.MSbuild.Tasks;
76

87
namespace Coverlet.Core.Instrumentation.Tests
98
{

test/coverlet.core.tests/coverlet.core.tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<ItemGroup>
1919
<ProjectReference Include="..\..\src\coverlet.core\coverlet.core.csproj" />
20-
<ProjectReference Include="..\..\src\coverlet.msbuild.tasks\coverlet.msbuild.tasks.csproj" />
2120
</ItemGroup>
2221

2322
<Import Project="$(MSBuildThisFileDirectory)\..\..\build\$(Configuration)\coverlet.msbuild.targets" />

0 commit comments

Comments
 (0)