Skip to content

Commit

Permalink
move CoverageTracker class to separate assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Jun 24, 2018
1 parent cf9fb2b commit 807f7b1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 42 deletions.
17 changes: 16 additions & 1 deletion coverlet.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Expand All @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.core.tests", "test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.console", "src\coverlet.console\coverlet.console.csproj", "{F3DBE7C3-ABBB-4B8B-A6CB-A1D3D607163E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "coverlet.tracker", "src\coverlet.tracker\coverlet.tracker.csproj", "{F4273009-536D-4999-A126-B0A2E3AA3E70}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,18 @@ Global
{F3DBE7C3-ABBB-4B8B-A6CB-A1D3D607163E}.Release|x64.Build.0 = Release|Any CPU
{F3DBE7C3-ABBB-4B8B-A6CB-A1D3D607163E}.Release|x86.ActiveCfg = Release|Any CPU
{F3DBE7C3-ABBB-4B8B-A6CB-A1D3D607163E}.Release|x86.Build.0 = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|x64.ActiveCfg = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|x64.Build.0 = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|x86.ActiveCfg = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Debug|x86.Build.0 = Debug|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|Any CPU.Build.0 = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|x64.ActiveCfg = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|x64.Build.0 = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|x86.ActiveCfg = Release|Any CPU
{F4273009-536D-4999-A126-B0A2E3AA3E70}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -81,6 +95,7 @@ Global
{FA73E423-9790-4F35-B018-3C4E3CA338BA} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
{E7637CC6-43F7-461A-A0BF-3C14562419BD} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{F3DBE7C3-ABBB-4B8B-A6CB-A1D3D607163E} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
{F4273009-536D-4999-A126-B0A2E3AA3E70} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9CA57C02-97B0-4C38-A027-EA61E8741F10}
Expand Down
10 changes: 4 additions & 6 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ public static bool HasPdb(string module)

public static void CopyCoverletDependency(string module)
{
var directory = Path.GetDirectoryName(module);
var moduleFileName = Path.GetFileName(module);

var assembly = typeof(Coverage).Assembly;
string name = Path.GetFileName(assembly.Location);
if (name == moduleFileName)
if (Path.GetFileName(typeof(Coverage).Assembly.Location) == moduleFileName)
return;

File.Copy(assembly.Location, Path.Combine(directory, name), true);
var directory = Path.GetDirectoryName(module);
var assembly = typeof(Coverlet.Tracker.CoverageTracker).Assembly;
File.Copy(assembly.Location, Path.Combine(directory, Path.GetFileName(assembly.Location)), true);
}

public static void BackupOriginalModule(string module, string identifier)
Expand Down
1 change: 1 addition & 0 deletions src/coverlet.core/Instrumentation/Instrumenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Coverlet.Core.Attributes;
using Coverlet.Core.Helpers;
using Coverlet.Core.Symbols;
using Coverlet.Tracker;

using Mono.Cecil;
using Mono.Cecil.Cil;
Expand Down
4 changes: 4 additions & 0 deletions src/coverlet.core/coverlet.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\coverlet.tracker\coverlet.tracker.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.Compression;
using Coverlet.Core.Attributes;
using Coverlet.Core.Extensions;

namespace Coverlet.Core
using Coverlet.Tracker.Extensions;

namespace Coverlet.Tracker
{
public static class CoverageTracker
{
private static Dictionary<string, List<string>> _markers;
private static Dictionary<string, int> _markerFileCount;

[ExcludeFromCoverage]
[ExcludeFromCodeCoverage]
static CoverageTracker()
{
_markers = new Dictionary<string, List<string>>();
Expand All @@ -21,7 +22,7 @@ static CoverageTracker()
AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_ProcessExit);
}

[ExcludeFromCoverage]
[ExcludeFromCodeCoverage]
public static void MarkExecuted(string path, string marker)
{
lock (_markers)
Expand All @@ -35,7 +36,7 @@ public static void MarkExecuted(string path, string marker)
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
{
foreach(var line in _markers[path])
foreach (var line in _markers[path])
{
sw.WriteLine(line);
}
Expand All @@ -46,7 +47,7 @@ public static void MarkExecuted(string path, string marker)
}
}

[ExcludeFromCoverage]
[ExcludeFromCodeCoverage]
public static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
lock (_markers)
Expand All @@ -57,7 +58,7 @@ public static void CurrentDomain_ProcessExit(object sender, EventArgs e)
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
{
foreach(var line in kvp.Value)
foreach (var line in kvp.Value)
{
sw.WriteLine(line);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using Coverlet.Core.Attributes;
using System.Diagnostics.CodeAnalysis;

namespace Coverlet.Core.Extensions
namespace Coverlet.Tracker.Extensions
{
internal static class DictionaryExtensions
{
[ExcludeFromCoverage]
[ExcludeFromCodeCoverage]
public static bool TryAdd<T, U>(this Dictionary<T, U> dictionary, T key, U value)
{
if (dictionary.ContainsKey(key))
Expand Down
7 changes: 7 additions & 0 deletions src/coverlet.tracker/coverlet.tracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
19 changes: 0 additions & 19 deletions test/coverlet.core.tests/Extensions/DictionaryExtensionsTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void TestCopyCoverletDependency()
var directory = Directory.CreateDirectory(Path.Combine(tempPath, "tempdir"));
InstrumentationHelper.CopyCoverletDependency(Path.Combine(directory.FullName, "somemodule.dll"));

Assert.True(File.Exists(Path.Combine(directory.FullName, "coverlet.core.dll")));
Assert.True(File.Exists(Path.Combine(directory.FullName, "coverlet.tracker.dll")));
Directory.Delete(directory.FullName, true);
}

Expand Down
6 changes: 2 additions & 4 deletions test/coverlet.core.tests/Samples/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public string Method(string input)

return input;
}
}

}

[ExcludeFromCodeCoverage]
public class ClassExcludedByCodeAnalysisCodeCoverageAttr
{
Expand All @@ -189,6 +189,4 @@ public string Method(string input)
return input;
}
}


}

0 comments on commit 807f7b1

Please sign in to comment.