Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow filtering on project file paths #67

12 changes: 7 additions & 5 deletions src/Core/Internal/Filtering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public static bool ShouldMutateProject(Project project, Config config)
return true;
}

var relativePath = RelativeFilePath(project.FilePath, config);

return config.ProjectFilters
.Any(f => Glob.Parse(f).IsMatch(project.Name));
.Any(f => Glob.Parse(f).IsMatch(project.Name) || Glob.Parse(f).IsMatch(relativePath));
}

public static bool ShouldMutateDocument(Document document, Config config)
Expand All @@ -33,7 +35,7 @@ private static bool ShouldMutateAccordingToFilters(Document document, Config con
return true;
}

var relativePath = RelativeDocumentPath(document, config);
var relativePath = RelativeFilePath(document.FilePath, config);

var matchesAnyFilter = config.SourceFileFilters
.Any(f => Glob.Parse(f).IsMatch(relativePath));
Expand All @@ -48,16 +50,16 @@ private static bool ShouldMutateAccordingToLocallyModifiedList(Document document
return true;
}

var relativePath = RelativeDocumentPath(document, config);
var relativePath = RelativeFilePath(document.FilePath, config);

return config.LocallyModifiedSourceFiles
.Any(f => string.Equals(f, relativePath, StringComparison.InvariantCultureIgnoreCase));
}

private static string RelativeDocumentPath(Document document, Config config)
private static string RelativeFilePath(string filePath, Config config)
{
var baseDir = config.GetSolutionFolder();
var relativePath = document.FilePath.Substring(baseDir.Length + 1);
var relativePath = filePath.Substring(baseDir.Length + 1);
return relativePath;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Tests/Core/Filtering/Projects_are_filtered.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

namespace Fettle.Tests.Core.Filtering
{
[TestFixture("HasSurvivingMutants.MoreImplementation")]
[TestFixture(@"MoreImplementation\HasSurvivingMutants.MoreImplementation.csproj")]
class Projects_are_filtered : Contexts.Default
{
public Projects_are_filtered()
public Projects_are_filtered(string projectFilter)
{
Given_a_partially_tested_app_in_which_a_mutant_will_survive();
Given_source_file_filters(null);

Given_project_filters("HasSurvivingMutants.MoreImplementation");
Given_project_filters(projectFilter);

When_mutation_testing_the_app();
}
Expand Down