Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Decoupling file excludability from mutant spans #2645

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Stryker.Core.DiffProviders;
using Stryker.Core.Exceptions;
using Stryker.Core.Options;
using Stryker.Core.ProjectComponents;
using Xunit;

namespace Stryker.Core.UnitTest.DiffProviders
Expand Down Expand Up @@ -213,7 +214,7 @@ public void ScanDiff_Throws_Stryker_Input_Exception_When_Commit_null()
public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles()
{
// Arrange
var diffIgnoreFiles = new[] { new FilePattern(Glob.Parse("/c/Users/JohnDoe/Project/Tests/Test.cs"), false, null) };
var diffIgnoreFiles = new[] { new ExcludableString("/c/Users/JohnDoe/Project/Tests/Test.cs") };
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

var basePath = FilePathUtils.NormalizePathSeparators("/c/Users/JohnDoe/Project/Tests");
var options = new StrykerOptions()
Expand Down Expand Up @@ -289,7 +290,7 @@ public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles()
public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles_Single_Asterisk()
{
// Arrange
var diffIgnoreFiles = new[] { new FilePattern(Glob.Parse("/c/Users/JohnDoe/Project/*/Test.cs"), false, null) };
var diffIgnoreFiles = new[] { new ExcludableString("/c/Users/JohnDoe/Project/*/Test.cs") };

var basePath = FilePathUtils.NormalizePathSeparators("/c/Users/JohnDoe/Project/Tests");
var options = new StrykerOptions()
Expand Down Expand Up @@ -365,7 +366,7 @@ public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles_Singl
public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles_Multi_Asterisk()
{
// Arrange
var diffIgnoreFiles = new[] { new FilePattern(Glob.Parse("**/Test.cs"), false, null) };
var diffIgnoreFiles = new[] { new ExcludableString("**/Test.cs") };

var basePath = FilePathUtils.NormalizePathSeparators("/c/Users/JohnDoe/Project/Tests");
var options = new StrykerOptions()
Expand Down Expand Up @@ -441,7 +442,7 @@ public void ScanDiffReturnsListOfFiles_ExcludingTestFilesInDiffIgnoreFiles_Multi
public void ScanDiffReturnsListOfFiles_ExcludingFilesInDiffIgnoreFiles_Multi_Asterisk()
{
// Arrange
var diffIgnoreFiles = new[] { new FilePattern(Glob.Parse("**/file.cs"), false, null) };
var diffIgnoreFiles = new[] { new ExcludableString("**/file.cs") };

var basePath = FilePathUtils.NormalizePathSeparators("/c/Users/JohnDoe/Project/Tests");
var options = new StrykerOptions()
Expand Down
335 changes: 335 additions & 0 deletions src/Stryker.Core/Stryker.Core.UnitTest/Helpers/RangeHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
using System.Linq;
using FSharp.Compiler.Text;
using Shouldly;
using Stryker.Core.Helpers;
using Xunit;

namespace Stryker.Core.UnitTest.Helpers
{
public class RangeHelperTests : TestBase
{
[Fact]
public void IsEmpty_ZeroRange()
{
var range = Range.Zero;

range.IsEmpty().ShouldBeTrue();
}

[Fact]
public void IsEmpty_HollowRange()
{
var range = GetRange((42, 42), (42, 42));

range.IsEmpty().ShouldBeTrue();
}

[Fact]
public void IsEmpty_NotEmptyRange()
{
var range = GetRange((0, 0), (42, 42));

range.IsEmpty().ShouldBeFalse();
}

[Fact]
public void Max_Greater()
{
var position1 = PositionModule.mkPos(42, 42);
var position2 = PositionModule.pos0;

var actual = RangeHelper.Max(position1, position2);

actual.ShouldBe(position1);
}

[Fact]
public void Max_Equal()
{
var position1 = PositionModule.pos0;
var position2 = PositionModule.pos0;

var actual = RangeHelper.Max(position1, position2);

actual.ShouldBe(position1);
}

[Fact]
public void Max_Less()
{
var position1 = PositionModule.pos0;
var position2 = PositionModule.mkPos(42, 42);

var actual = RangeHelper.Max(position1, position2);

actual.ShouldBe(position2);
}

[Fact]
public void Min_Greater()
{
var position1 = PositionModule.mkPos(42, 42);
var position2 = PositionModule.pos0;

var actual = RangeHelper.Min(position1, position2);

actual.ShouldBe(position2);
}

[Fact]
public void Min_Equal()
{
var position1 = PositionModule.pos0;
var position2 = PositionModule.pos0;

var actual = RangeHelper.Min(position1, position2);

actual.ShouldBe(position2);
}

[Fact]
public void Min_Less()
{
var position1 = PositionModule.pos0;
var position2 = PositionModule.mkPos(42, 42);

var actual = RangeHelper.Min(position1, position2);

actual.ShouldBe(position1);
}

[Fact]
public void OverlapsWith_Overlapping_Left()
{
var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (33, 33));

range1.OverlapsWith(range2).ShouldBeTrue();
}

[Fact]
public void OverlapsWith_Overlapping_Right()
{
var range1 = GetRange((11, 11), (33, 33));
var range2 = GetRange((0, 0), (22, 22));

range1.OverlapsWith(range2).ShouldBeTrue();
}

[Fact]
public void OverlapsWith_Overlapping_Between()
{
var range1 = GetRange((0, 0), (33, 33));
var range2 = GetRange((11, 11), (22, 22));

range1.OverlapsWith(range2).ShouldBeTrue();
}

[Fact]
public void OverlapsWith_NotOverlapping()
{
var range1 = GetRange((0, 0), (11, 11));
var range2 = GetRange((22, 22), (33, 33));

range1.OverlapsWith(range2).ShouldBeFalse();
}

[Fact]
public void OverlapsWith_Empty_Left()
{
var range1 = GetRange((0, 0), (42, 42));
var range2 = Range.Zero;

range1.OverlapsWith(range2).ShouldBeFalse();
}

[Fact]
public void OverlapsWith_Empty_Right()
{
var range1 = Range.Zero;
var range2 = GetRange((0, 0), (42, 42));

range1.OverlapsWith(range2).ShouldBeFalse();
}

[Fact]
public void OverlapsWith_Empty_Both()
{
var range1 = Range.Zero;
var range2 = Range.Zero;

range1.OverlapsWith(range2).ShouldBeFalse();
}

[Fact]
public void Overlap_Overlapping()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (33, 33));
var expectedOverlap = GetRange((11, 11), (22, 22));

range1.Overlap(range2, filePath).ShouldBe(expectedOverlap);
}

[Fact]
public void Overlap_NotOverlapping()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (11, 11));
var range2 = GetRange((22, 22), (33, 33));

range1.Overlap(range2, filePath).ShouldBeNull();
}

[Fact]
public void IntersectsWith_Intersecting_Left()
{
var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (33, 33));

range1.IntersectsWith(range2).ShouldBeTrue();
}

[Fact]
public void IntersectsWith_Intersecting_Right()
{
var range1 = GetRange((11, 11), (33, 33));
var range2 = GetRange((0, 0), (22, 22));

range1.IntersectsWith(range2).ShouldBeTrue();
}

[Fact]
public void IntersectsWith_Intersecting_Between()
{
var range1 = GetRange((0, 0), (33, 33));
var range2 = GetRange((11, 11), (22, 22));

range1.IntersectsWith(range2).ShouldBeTrue();
}

[Fact]
public void IntersectsWith_NoIntersection()
{
var range1 = GetRange((0, 0), (11, 11));
var range2 = GetRange((22, 22), (33, 33));

range1.IntersectsWith(range2).ShouldBeFalse();
}

[Fact]
public void Reduce_Zero()
{
var result = RangeHelper.Reduce("test.fs", Enumerable.Empty<Range>());

result.ShouldBeEmpty();
}

[Fact]
public void Reduce_One()
{
var filePath = "test.fs";

var range = GetRange((0, 0), (42, 42));

var ranges = new[] { range };

var result = RangeHelper.Reduce(filePath, ranges);

result.ShouldBe(ranges);
}

[Fact]
public void Reduce_Two_Intersecting()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (33, 33));
var expectedRange = GetRange((0, 0), (33, 33));

var result = RangeHelper.Reduce(filePath, new[] { range1, range2 });

result.ShouldBe(new[] { expectedRange });
}

[Fact]
public void Reduce_Two_NonIntersecting()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (11, 11));
var range2 = GetRange((22, 22), (33, 33));
var ranges = new[] { range1, range2 };

var actual = RangeHelper.Reduce(filePath, ranges);

actual.ShouldBe(ranges);
}

[Fact]
public void Reduce_Three_PartiallyIntersecting()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (33, 33));
var range3 = GetRange((44, 44), (55, 55));
var expectedIntersection = GetRange((0, 0), (33, 33));
var expectedRanges = new[] { expectedIntersection, range3 };

var result = RangeHelper.Reduce(filePath, new[] { range1, range2, range3 }); ;

result.ShouldBe(expectedRanges, ignoreOrder: true);
}

[Fact]
public void RemoveOverlap_Overlapping_Partially()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (22, 22));
var range2 = GetRange((11, 11), (22, 22));
var expectedRange = GetRange((0, 0), (11, 11));

var result = RangeHelper.RemoveOverlap(new[] { range1 }, new [] { range2 }, filePath);

result.ShouldBe(new[] { expectedRange });
}

[Fact]
public void RemoveOverlap_Overlapping_Completely()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (42, 42));
var range2 = GetRange((0, 0), (42, 42));

var result = RangeHelper.RemoveOverlap(new[] { range1 }, new[] { range2 }, filePath);

result.ShouldBeEmpty();
}

[Fact]
public void RemoveOverlap_NotOverlapping()
{
var filePath = "test.fs";

var range1 = GetRange((0, 0), (11, 11));
var range2 = GetRange((22, 22), (33, 33));

var result = RangeHelper.RemoveOverlap(new[] { range1 }, new[] { range2 }, filePath);

result.ShouldBe(new[] { range1 });
}

private static Range GetRange((int Line, int Column) start, (int Line, int Column) end) =>
RangeModule.mkRange(
"test.fs",
PositionModule.mkPos(start.Line, start.Column),
PositionModule.mkPos(end.Line, end.Column));
}
}
Loading
Loading