Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1) Store alternative paths when hashes matched

2) Check alternative paths when testing for tracking
#19 #23
  • Loading branch information...
commit b407a6eb7caba07bf684408496223d73727e5cde 1 parent 4f3c3b3
@sawilde sawilde authored
View
9 main/OpenCover.Framework/Model/InstrumentationModelBuilder.cs
@@ -36,7 +36,14 @@ public Module BuildModuleModel()
{
hash = HashFile(_symbolManager.ModulePath);
}
- var module = new Module {ModuleName = _symbolManager.ModuleName, FullName = _symbolManager.ModulePath, Files = _symbolManager.GetFiles(), ModuleHash = hash};
+ var module = new Module
+ {
+ ModuleName = _symbolManager.ModuleName,
+ FullName = _symbolManager.ModulePath,
+ Files = _symbolManager.GetFiles(),
+ ModuleHash = hash
+ };
+ module.Aliases.Add(_symbolManager.ModulePath);
module.Classes = _symbolManager.GetInstrumentableTypes();
foreach (var @class in module.Classes)
{
View
14 main/OpenCover.Framework/Model/Module.cs
@@ -17,11 +17,25 @@ namespace OpenCover.Framework.Model
public class Module
{
/// <summary>
+ /// simple constructor
+ /// </summary>
+ public Module()
+ {
+ Aliases = new List<string>();
+ }
+
+ /// <summary>
/// The full path name to the module
/// </summary>
public string FullName { get; set; }
/// <summary>
+ /// A list of aliases
+ /// </summary>
+ [XmlIgnore]
+ public IList<string> Aliases { get; private set; }
+
+ /// <summary>
/// The name of the module
/// </summary>
public string ModuleName { get; set; }
View
18 main/OpenCover.Framework/Persistance/BasePersistance.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using OpenCover.Framework.Model;
@@ -21,7 +22,16 @@ public void PersistModule(Module module)
{
if (_commandLine.MergeByHash)
{
- if ((CoverageSession.Modules ?? new Module[0]).Any(x => x.ModuleHash == module.ModuleHash)) return;
+ var modules = CoverageSession.Modules ?? new Module[0];
+ if (modules.Any(x => x.ModuleHash == module.ModuleHash))
+ {
+ var existingModule = modules.First(x => x.ModuleHash == module.ModuleHash);
+ if (!existingModule.Aliases.Any(x=>x.Equals(module.FullName, StringComparison.InvariantCultureIgnoreCase)))
+ {
+ existingModule.Aliases.Add(module.FullName);
+ }
+ return;
+ }
}
var list = new List<Module>(CoverageSession.Modules ?? new Module[0]) { module };
CoverageSession.Modules = list.ToArray();
@@ -30,7 +40,7 @@ public void PersistModule(Module module)
public bool IsTracking(string modulePath)
{
if (CoverageSession.Modules == null) return false;
- return CoverageSession.Modules.Any(x => x.FullName == modulePath);
+ return CoverageSession.Modules.Any(x => x.Aliases.Any(path => path.Equals(modulePath, StringComparison.InvariantCultureIgnoreCase)));
}
public virtual void Commit()
@@ -55,7 +65,7 @@ private Method GetMethod(string modulePath, int functionToken, out Class @class)
@class = null;
//c = null;
if (CoverageSession.Modules == null) return null;
- var module = CoverageSession.Modules.Where(x => x.FullName == modulePath).FirstOrDefault();
+ var module = CoverageSession.Modules.FirstOrDefault(x => x.Aliases.Any(path => path.Equals(modulePath, StringComparison.InvariantCultureIgnoreCase)));
if (module == null) return null;
foreach (var c in module.Classes)
{
View
17 main/OpenCover.Test/Framework/Persistance/BasePersistenceTests.cs
@@ -35,8 +35,12 @@ public void Can_Add_SeveralModules_To_Session()
Assert.IsNull(Instance.CoverageSession.Modules);
// act
- Instance.PersistModule(new Module() { ModuleHash = "123" });
- Instance.PersistModule(new Module() { ModuleHash = "123" });
+ var module1 = new Module() { ModuleHash = "123", FullName = "Path1" };
+ module1.Aliases.Add("Path1");
+ var module2 = new Module() { ModuleHash = "123", FullName = "Path2" };
+ module2.Aliases.Add("Path2");
+ Instance.PersistModule(module1);
+ Instance.PersistModule(module2);
// assert
Assert.AreEqual(2, Instance.CoverageSession.Modules.Count());
@@ -53,9 +57,12 @@ public void Can_Merge_Modules_In_Session_When_HashMatched()
Assert.IsNull(Instance.CoverageSession.Modules);
// act
- Instance.PersistModule(new Module() { ModuleHash = "123" });
- Instance.PersistModule(new Module() { ModuleHash = "123" });
-
+ var module1 = new Module() { ModuleHash = "123", FullName = "Path1" };
+ module1.Aliases.Add("Path1");
+ var module2 = new Module() { ModuleHash = "123", FullName = "Path2" };
+ module2.Aliases.Add("Path2");
+ Instance.PersistModule(module1);
+ Instance.PersistModule(module2);
// assert
Assert.AreEqual(1, Instance.CoverageSession.Modules.Count());
}
View
13 main/OpenCover.Test/Framework/Persistance/FilePersistenceTests.cs
@@ -45,10 +45,12 @@ public void TearDown()
public void IsTracking_True_IfModuleKnown()
{
// arrange
- _persistence.PersistModule(new Module(){FullName = "ModuleName"});
+ var module = new Module() {FullName = "ModulePath"};
+ module.Aliases.Add("ModulePath");
+ _persistence.PersistModule(module);
// act
- var tracking = _persistence.IsTracking("ModuleName");
+ var tracking = _persistence.IsTracking("ModulePath");
// assert
Assert.IsTrue(tracking);
@@ -58,11 +60,14 @@ public void IsTracking_True_IfModuleKnown()
public void GetSequencePoints_GetsPoints_When_ModuleAndFunctionKnown()
{
// arrange
- _persistence.PersistModule(new Module() { FullName = "ModuleName", Classes = new []{new Class(){Methods = new []{new Method(){MetadataToken = 1, SequencePoints = new []{new SequencePoint(){VisitCount = 1000} }}}}}});
+ var module = new Module() { FullName = "ModulePath", Classes = new[] { new Class() { Methods = new[] { new Method() { MetadataToken = 1, SequencePoints = new[] { new SequencePoint() { VisitCount = 1000 } } } } } } };
+
+ module.Aliases.Add("ModulePath");
+ _persistence.PersistModule(module);
// act
SequencePoint[] points;
- _persistence.GetSequencePointsForFunction("ModuleName", 1, out points);
+ _persistence.GetSequencePointsForFunction("ModulePath", 1, out points);
// assert
Assert.IsNotNull(points);
Please sign in to comment.
Something went wrong with that request. Please try again.