Skip to content

Commit

Permalink
change Filter property to Exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed May 13, 2018
1 parent ebedd70 commit 9ed0864
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public class Coverage
private string _module;
private string _identifier;
private string[] _filters;
private string[] _excludes;
private string[] _rules;
private List<InstrumenterResult> _results;

public Coverage(string module, string identifier, string[] filters, string[] excludes)
public Coverage(string module, string identifier, string[] filters, string[] rules)
{
_module = module;
_identifier = identifier;
_filters = filters;
_excludes = excludes;
_rules = rules;
_results = new List<InstrumenterResult>();
}

public void PrepareModules()
{
string[] modules = InstrumentationHelper.GetCoverableModules(_module);
string[] excludedFiles = InstrumentationHelper.GetExcludedFiles(_excludes);
string[] excludedFiles = InstrumentationHelper.GetExcludedFiles(_rules);

foreach (var module in modules)
{
Expand Down Expand Up @@ -211,4 +211,4 @@ private void CalculateCoverage()
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ public static bool IsTypeExcluded(string module, string type, string[] filters)
return isMatch;
}

public static string[] GetExcludedFiles(string[] excludes)
public static string[] GetExcludedFiles(string[] rules)
{
const string RELATIVE_KEY = nameof(RELATIVE_KEY);
string parentDir = Directory.GetCurrentDirectory();

if (excludes == null || !excludes.Any()) return Array.Empty<string>();
if (rules == null || !rules.Any()) return Array.Empty<string>();

var matcherDict = new Dictionary<string, Matcher>() { { RELATIVE_KEY, new Matcher() } };
foreach (var excludeRule in excludes)
foreach (var excludeRule in rules)
{
if (Path.IsPathRooted(excludeRule))
{
Expand Down
14 changes: 7 additions & 7 deletions src/coverlet.msbuild.tasks/InstrumentationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class InstrumentationTask : Task
{
private static Coverage _coverage;
private string _path;
private string _filter;
private string _exclude;
private string _excludeByFile;

internal static Coverage Coverage
Expand All @@ -24,10 +24,10 @@ public string Path
set { _path = value; }
}

public string Filter
public string Exclude
{
get { return _filter; }
set { _filter = value; }
get { return _exclude; }
set { _exclude = value; }
}

public string ExcludeByFile
Expand All @@ -40,10 +40,10 @@ public override bool Execute()
{
try
{
var excludes = _excludeByFile?.Split(',');
var filters = _filter?.Split(',');
var rules = _excludeByFile?.Split(',');
var filters = _exclude?.Split(',');

_coverage = new Coverage(_path, Guid.NewGuid().ToString(), filters, excludes);
_coverage = new Coverage(_path, Guid.NewGuid().ToString(), filters, rules);
_coverage.PrepareModules();
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion src/coverlet.msbuild/coverlet.msbuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CoverletOutputDirectory Condition="$(CoverletOutputDirectory) == ''">$(MSBuildProjectDirectory)</CoverletOutputDirectory>
<CoverletOutputName Condition=" '$(CoverletOutputName)' == '' ">coverage</CoverletOutputName>
<CoverletOutput>$([MSBuild]::EnsureTrailingSlash('$(CoverletOutputDirectory)'))$(CoverletOutputName)</CoverletOutput>
<Filter Condition="$(Filter) == ''"></Filter>
<Exclude Condition="$(Exclude) == ''"></Exclude>
<ExcludeByFile Condition="$(ExcludeByFile) == ''"></ExcludeByFile>
<Threshold Condition="$(Threshold) == ''">0</Threshold>
<ThresholdType Condition="$(ThresholdType) == ''">line,branch,method</ThresholdType>
Expand Down
3 changes: 2 additions & 1 deletion src/coverlet.msbuild/coverlet.msbuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
<Target Name="InstrumentModulesNoBuild" BeforeTargets="VSTest">
<Coverlet.MSbuild.Tasks.InstrumentationTask
Condition="'$(VSTestNoBuild)' == 'true' and $(CollectCoverage) == 'true'"
Exclude="$(Exclude)"
ExcludeByFile="$(ExcludeByFile)"
Path="$(TargetPath)" />
</Target>

<Target Name="InstrumentModulesAfterBuild" AfterTargets="BuildProject">
<Coverlet.MSbuild.Tasks.InstrumentationTask
Condition="'$(VSTestNoBuild)' != 'true' and $(CollectCoverage) == 'true'"
Filter="$(Filter)"
Exclude="$(Exclude)"
ExcludeByFile="$(ExcludeByFile)"
Path="$(TargetPath)" />
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public void TestGetExcludedFilesUsingAbsFile()
{
var file = Path.GetRandomFileName();
File.Create(file).Dispose();
var excludeFiles = InstrumentationHelper.GetExcludedFiles(
var excludedFiles = InstrumentationHelper.GetExcludedFiles(
new string[] { Path.Combine(Directory.GetCurrentDirectory(), file) }
);
File.Delete(file);
Assert.Single(excludeFiles);
Assert.Single(excludedFiles);
}

[Fact]
Expand All @@ -116,15 +116,15 @@ public void TestGetExcludedFilesUsingGlobbing()
File.Create(path).Dispose();
}

var excludeFiles = InstrumentationHelper.GetExcludedFiles(
var excludedFiles = InstrumentationHelper.GetExcludedFiles(
new string[] { $"*.{fileExtension}" });

foreach (var path in paths)
{
File.Delete(path);
}

Assert.Equal(paths.Length, excludeFiles.Count());
Assert.Equal(paths.Length, excludedFiles.Count());
}
}
}
Expand Down

0 comments on commit 9ed0864

Please sign in to comment.