Skip to content

Commit

Permalink
Fix errors when multiple assemblies points to same source file
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslorentz committed Feb 13, 2018
1 parent a3308d4 commit 8a2923b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/MiniCover/Model/InstrumentationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ public void AddExtraAssembly(string file)
{
ExtraAssemblies.Add(file);
}

public Dictionary<string, SourceFile> GetSourceFiles()
{
return Assemblies
.SelectMany(a => a.SourceFiles)
.GroupBy(kv => kv.Key, kv => kv.Value)
.ToDictionary(g => g.Key, g => SourceFile.Merge(g));
}
}
}
9 changes: 9 additions & 0 deletions src/MiniCover/Model/SourceFile.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using System.Collections.Generic;
using System.Linq;

namespace MiniCover.Model
{
public class SourceFile
{
public static SourceFile Merge(IEnumerable<SourceFile> sources)
{
return new SourceFile
{
Instructions = sources.SelectMany(s => s.Instructions).ToList()
};
}

public List<InstrumentedInstruction> Instructions = new List<InstrumentedInstruction>();
}
}
13 changes: 4 additions & 9 deletions src/MiniCover/Reports/BaseReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ public abstract class BaseReport
public virtual int Execute(InstrumentationResult result, float threshold)
{
var hits = File.Exists(result.HitsFile)
? File.ReadAllLines(result.HitsFile).Select(h => int.Parse(h)).ToHashSet()
: new HashSet<int>();

var files = result.Assemblies
.SelectMany(assembly => assembly.SourceFiles)
.ToDictionary(
x => x.Key,
x => x.Value
);
? File.ReadAllLines(result.HitsFile).Select(h => int.Parse(h)).ToHashSet()
: new HashSet<int>();

var files = result.GetSourceFiles();

SetFileColumnLength(files.Keys.Select(s => s.Length).Concat(new[] { 10 }).Max());

Expand Down

0 comments on commit 8a2923b

Please sign in to comment.