Skip to content

Commit

Permalink
OpenCover#794 hide skipped methods (AutoImplementedProperty)
Browse files Browse the repository at this point in the history
also addressed Delegate and FSharpInternal
  • Loading branch information
sawilde committed Jan 8, 2019
1 parent 86a2ff1 commit 931ea35
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
10 changes: 9 additions & 1 deletion main/OpenCover.Framework/Persistance/BasePersistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ private void ProcessSkippedAction(SkippedMethod skippedMethod)
RemoveEmptyClasses();
break;
case SkippedMethod.AutoImplementedProperty:
RemoveSkippedMethods(SkippedMethod.Attribute);
RemoveSkippedMethods(SkippedMethod.AutoImplementedProperty);
RemoveEmptyClasses();
break;
case SkippedMethod.Delegate:
RemoveSkippedMethods(SkippedMethod.Delegate);
RemoveEmptyClasses();
break;
case SkippedMethod.FSharpInternal:
RemoveSkippedMethods(SkippedMethod.FSharpInternal);
RemoveEmptyClasses();
break;
}
Expand Down
83 changes: 38 additions & 45 deletions main/OpenCover.Test/Framework/Persistance/BasePersistenceTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using log4net;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -41,7 +40,10 @@ public class BasePersistenceTests :
private static readonly SkippedMethod[] _skippedReasonsMethods =
{
SkippedMethod.File,
SkippedMethod.Attribute
SkippedMethod.Attribute,
SkippedMethod.AutoImplementedProperty,
SkippedMethod.Delegate,
SkippedMethod.FSharpInternal
};

[Test]
Expand All @@ -53,7 +55,7 @@ public void CanNot_Add_Invalid_Module_To_Session()
Instance.PersistModule(null);

// assert
Assert.AreEqual(0, Instance.CoverageSession.Modules.Count());
Assert.AreEqual(0, Instance.CoverageSession.Modules.Length);
}

[Test]
Expand All @@ -70,7 +72,7 @@ public void Can_Add_SeveralModules_To_Session()
Instance.PersistModule(module2);

// assert
Assert.AreEqual(2, Instance.CoverageSession.Modules.Count());
Assert.AreEqual(2, Instance.CoverageSession.Modules.Length);
}

[Test]
Expand All @@ -83,15 +85,14 @@ public void Can_Add_Valid_Module_To_Session()
Instance.PersistModule(new Module {TrackedMethods = new TrackedMethod[0]});

// assert
Assert.AreEqual(2, Instance.CoverageSession.Modules.Count());
Assert.AreEqual(2, Instance.CoverageSession.Modules.Length);
}

[Test]
public void Can_GetBranchPoints_Of_MethodByToken()
{
// arrange
var target = new BranchPoint();
BranchPoint[] pts;
var module = new Module
{
ModulePath = "ModulePath",
Expand All @@ -116,7 +117,7 @@ public void Can_GetBranchPoints_Of_MethodByToken()
Instance.PersistModule(module);

// act
Instance.GetBranchPointsForFunction("ModulePath", 1001, out pts);
Instance.GetBranchPointsForFunction("ModulePath", 1001, out var pts);

// assert
Assert.AreEqual(target.UniqueSequencePoint, pts[0].UniqueSequencePoint);
Expand Down Expand Up @@ -150,7 +151,6 @@ public void Can_GetSequencePoints_Of_MethodByToken()
{
// arrange
var target = new SequencePoint();
InstrumentationPoint[] pts;
var module = new Module
{
ModulePath = "ModulePath",
Expand All @@ -176,7 +176,7 @@ public void Can_GetSequencePoints_Of_MethodByToken()
Instance.PersistModule(module);

// act
Instance.GetSequencePointsForFunction("ModulePath", 1001, out pts);
Instance.GetSequencePointsForFunction("ModulePath", 1001, out var pts);

// assert
Assert.AreEqual(target.UniqueSequencePoint, pts[0].UniqueSequencePoint);
Expand All @@ -199,7 +199,7 @@ public void Can_Merge_Modules_In_Session_When_HashMatched()
Instance.PersistModule(module2);

// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules.Length);
}

[Test]
Expand Down Expand Up @@ -449,12 +449,11 @@ public void GeBranchPoints_GetsZeroPoints_When_FunctionNotKnown()
Instance.PersistModule(module);

// act
BranchPoint[] points;
Instance.GetBranchPointsForFunction("ModuleName", 2, out points);
Instance.GetBranchPointsForFunction("ModuleName", 2, out var points);

// assert
Assert.IsNotNull(points);
Assert.AreEqual(0, points.Count());
Assert.AreEqual(0, points.Length);
}

[Test]
Expand Down Expand Up @@ -488,12 +487,11 @@ public void GetSequencePoints_GetsPoints_When_ModuleAndFunctionKnown_FirstPointI
Instance.PersistModule(module);

// act
InstrumentationPoint[] points;
Instance.GetSequencePointsForFunction("ModulePath", 1, out points);
Instance.GetSequencePointsForFunction("ModulePath", 1, out var points);

// assert
Assert.IsNotNull(points);
Assert.AreEqual(2, points.Count());
Assert.AreEqual(2, points.Length);
Assert.AreEqual(2000, points[0].VisitCount);
Assert.AreEqual(1000, points[1].VisitCount);
}
Expand Down Expand Up @@ -529,12 +527,11 @@ public void GetSequencePoints_GetsPoints_When_ModuleAndFunctionKnown_FirstPointI
Instance.PersistModule(module);

// act
InstrumentationPoint[] points;
Instance.GetSequencePointsForFunction("ModulePath", 1, out points);
Instance.GetSequencePointsForFunction("ModulePath", 1, out var points);

// assert
Assert.IsNotNull(points);
Assert.AreEqual(1, points.Count());
Assert.AreEqual(1, points.Length);
Assert.AreEqual(1000, points[0].VisitCount);
}

Expand All @@ -558,12 +555,11 @@ public void GetSequencePoints_GetsZeroPoints_When_FunctionNotKnown()
Instance.PersistModule(module);

// act
InstrumentationPoint[] points;
Instance.GetSequencePointsForFunction("ModuleName", 2, out points);
Instance.GetSequencePointsForFunction("ModuleName", 2, out var points);

// assert
Assert.IsNotNull(points);
Assert.AreEqual(0, points.Count());
Assert.AreEqual(0, points.Length);
}

[Test]
Expand Down Expand Up @@ -592,12 +588,11 @@ public void GetSequencePoints_GetsZeroPoints_When_ModuleNotKnown()
});

// act
InstrumentationPoint[] points;
Instance.GetSequencePointsForFunction("ModuleName1", 1, out points);
Instance.GetSequencePointsForFunction("ModuleName1", 1, out var points);

// assert
Assert.IsNotNull(points);
Assert.AreEqual(0, points.Count());
Assert.AreEqual(0, points.Length);
}

[Test]
Expand All @@ -616,8 +611,7 @@ public void GetTrackingMethod_RetrievesId_For_TrackedMethod()
Instance.PersistModule(module);

// act
uint trackedId ;
var result = Instance.GetTrackingMethod("ModulePath", "AssemblyName", 1234, out trackedId);
var result = Instance.GetTrackingMethod("ModulePath", "AssemblyName", 1234, out var trackedId);

// assert
Assert.IsTrue(result);
Expand All @@ -640,8 +634,7 @@ public void GetTrackingMethod_ReturnsFase_For_UnTrackedMethod()
Instance.PersistModule(module);

// act
uint trackedId;
var result = Instance.GetTrackingMethod("ModulePath", "AssemblyName", 2222, out trackedId);
var result = Instance.GetTrackingMethod("ModulePath", "AssemblyName", 2222, out var trackedId);

// assert
Assert.IsFalse(result);
Expand Down Expand Up @@ -695,8 +688,8 @@ public void HideSkipped_With_File_Removes_EmptyClasses()
Instance.Commit();

// assert
Assert.AreEqual(2, Instance.CoverageSession.Modules[0].Classes.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes[1].Methods.Count());
Assert.AreEqual(2, Instance.CoverageSession.Modules[0].Classes.Length);
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes[1].Methods.Length);
Assert.AreEqual("KeepMethod", Instance.CoverageSession.Modules[0].Classes[1].Methods[0].FullName);
}

Expand Down Expand Up @@ -730,19 +723,19 @@ public void HideSkipped_With_File_Removes_UnreferencedFiles()
}
});

Assert.AreEqual(2, Instance.CoverageSession.Modules[0].Files.Count());
Assert.AreEqual(2, Instance.CoverageSession.Modules[0].Files.Length);

// act
Instance.Commit();

// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Files.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Files.Length);
Assert.AreEqual("KeepFile", Instance.CoverageSession.Modules[0].Files[0].FullPath);
}

[Test]
public void HideSkipped_With_X_Removes_SkippedClasses(
[ValueSource("_skippedReasonsClasses")] SkippedMethod reason)
[ValueSource(nameof(_skippedReasonsClasses))] SkippedMethod reason)
{
// arrange
Container.GetMock<ICommandLine>()
Expand All @@ -765,13 +758,13 @@ public void HideSkipped_With_X_Removes_SkippedClasses(
Instance.Commit();

// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes.Length);
Assert.AreEqual("KeepClass", Instance.CoverageSession.Modules[0].Classes[0].FullName);
}

[Test]
public void HideSkipped_With_X_Removes_SkippedMethods(
[ValueSource("_skippedReasonsMethods")] SkippedMethod reason)
[ValueSource(nameof(_skippedReasonsMethods))] SkippedMethod reason)
{
// arrange
Container.GetMock<ICommandLine>()
Expand Down Expand Up @@ -807,14 +800,14 @@ public void HideSkipped_With_X_Removes_SkippedMethods(
Instance.Commit();

// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes[0].Methods.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes.Length);
Assert.AreEqual(1, Instance.CoverageSession.Modules[0].Classes[0].Methods.Length);
Assert.AreEqual("KeepMethod", Instance.CoverageSession.Modules[0].Classes[0].Methods[0].FullName);
}

[Test]
public void HideSkipped_With_X_Removes_SkippedModules(
[ValueSource("_skippedReasonsModules")] SkippedMethod reason)
[ValueSource(nameof(_skippedReasonsModules))] SkippedMethod reason)
{
// arrange
Container.GetMock<ICommandLine>()
Expand All @@ -830,7 +823,7 @@ public void HideSkipped_With_X_Removes_SkippedModules(
Instance.Commit();

// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules.Count());
Assert.AreEqual(1, Instance.CoverageSession.Modules.Length);
Assert.AreEqual("Keep", Instance.CoverageSession.Modules[0].ModulePath);
}

Expand Down Expand Up @@ -1011,7 +1004,7 @@ public void SaveVisitPoints_Aggregates_Visits()

var points = new[]
{pt1.UniqueSequencePoint, pt2.UniqueSequencePoint, pt2.UniqueSequencePoint, pt2.UniqueSequencePoint};
data.AddRange(BitConverter.GetBytes((UInt32) points.Count()));
data.AddRange(BitConverter.GetBytes((UInt32) points.Length));
foreach (uint point in points)
data.AddRange(BitConverter.GetBytes(point));

Expand All @@ -1033,7 +1026,7 @@ public void SaveVisitPoints_DoesNotProcessBufferWhenCountExceedsAvailableBufferS
var data = new List<byte>();

var points = new[] { pt1.UniqueSequencePoint, pt2.UniqueSequencePoint, pt2.UniqueSequencePoint, pt2.UniqueSequencePoint };
data.AddRange(BitConverter.GetBytes((UInt32)points.Count() + 1));
data.AddRange(BitConverter.GetBytes((UInt32)points.Length + 1));
foreach (uint point in points)
data.AddRange(BitConverter.GetBytes(point));

Expand Down Expand Up @@ -1061,7 +1054,7 @@ public void SaveVisitPoints_Aggregates_Visits_ForTrackedMethods()
2 | (uint) MSG_IdType.IT_MethodEnter, pt2.UniqueSequencePoint, pt2.UniqueSequencePoint,
2 | (uint) MSG_IdType.IT_MethodLeave
};
data.AddRange(BitConverter.GetBytes((UInt32) points.Count()));
data.AddRange(BitConverter.GetBytes((UInt32) points.Length));
foreach (uint point in points)
data.AddRange(BitConverter.GetBytes(point));

Expand All @@ -1071,9 +1064,9 @@ public void SaveVisitPoints_Aggregates_Visits_ForTrackedMethods()
// assert
Assert.AreEqual(1, InstrumentationPoint.GetVisitCount(pt1.UniqueSequencePoint));
Assert.AreEqual(3, InstrumentationPoint.GetVisitCount(pt2.UniqueSequencePoint));
Assert.AreEqual(1, pt1.TrackedMethodRefs.Count());
Assert.AreEqual(1, pt1.TrackedMethodRefs.Length);
Assert.AreEqual(1, pt1.TrackedMethodRefs[0].VisitCount);
Assert.AreEqual(2, pt2.TrackedMethodRefs.Count());
Assert.AreEqual(2, pt2.TrackedMethodRefs.Length);
Assert.AreEqual(1, pt2.TrackedMethodRefs[0].VisitCount);
Assert.AreEqual(2, pt2.TrackedMethodRefs[1].VisitCount);
}
Expand Down

0 comments on commit 931ea35

Please sign in to comment.