From 807f7b1bd5bea8158ffff343d5511cd16e0da9a0 Mon Sep 17 00:00:00 2001 From: Toni Solarin-Sodara Date: Sun, 24 Jun 2018 13:09:14 +0100 Subject: [PATCH] move CoverageTracker class to separate assembly --- coverlet.sln | 17 ++++++++++++++++- .../Helpers/InstrumentationHelper.cs | 10 ++++------ .../Instrumentation/Instrumenter.cs | 1 + src/coverlet.core/coverlet.core.csproj | 4 ++++ .../CoverageTracker.cs | 17 +++++++++-------- .../Extensions/DictionaryExtensions.cs | 6 +++--- src/coverlet.tracker/coverlet.tracker.csproj | 7 +++++++ .../Extensions/DictionaryExtensionsTests.cs | 19 ------------------- .../Helpers/InstrumentationHelperTests.cs | 2 +- test/coverlet.core.tests/Samples/Samples.cs | 6 ++---- 10 files changed, 47 insertions(+), 42 deletions(-) rename src/{coverlet.core => coverlet.tracker}/CoverageTracker.cs (87%) rename src/{coverlet.core => coverlet.tracker}/Extensions/DictionaryExtensions.cs (75%) create mode 100644 src/coverlet.tracker/coverlet.tracker.csproj delete mode 100644 test/coverlet.core.tests/Extensions/DictionaryExtensionsTests.cs diff --git a/coverlet.sln b/coverlet.sln index f616006d5..a0efe4e6a 100644 --- a/coverlet.sln +++ b/coverlet.sln @@ -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 @@ -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 @@ -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 @@ -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} diff --git a/src/coverlet.core/Helpers/InstrumentationHelper.cs b/src/coverlet.core/Helpers/InstrumentationHelper.cs index f870ef042..3fc909080 100644 --- a/src/coverlet.core/Helpers/InstrumentationHelper.cs +++ b/src/coverlet.core/Helpers/InstrumentationHelper.cs @@ -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) diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index c94a92d32..e1f833d61 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -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; diff --git a/src/coverlet.core/coverlet.core.csproj b/src/coverlet.core/coverlet.core.csproj index 9459a519c..58f628ab0 100644 --- a/src/coverlet.core/coverlet.core.csproj +++ b/src/coverlet.core/coverlet.core.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/src/coverlet.core/CoverageTracker.cs b/src/coverlet.tracker/CoverageTracker.cs similarity index 87% rename from src/coverlet.core/CoverageTracker.cs rename to src/coverlet.tracker/CoverageTracker.cs index 09836a46e..50f7f11cd 100644 --- a/src/coverlet.core/CoverageTracker.cs +++ b/src/coverlet.tracker/CoverageTracker.cs @@ -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> _markers; private static Dictionary _markerFileCount; - [ExcludeFromCoverage] + [ExcludeFromCodeCoverage] static CoverageTracker() { _markers = new Dictionary>(); @@ -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) @@ -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); } @@ -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) @@ -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); } diff --git a/src/coverlet.core/Extensions/DictionaryExtensions.cs b/src/coverlet.tracker/Extensions/DictionaryExtensions.cs similarity index 75% rename from src/coverlet.core/Extensions/DictionaryExtensions.cs rename to src/coverlet.tracker/Extensions/DictionaryExtensions.cs index be1bee0df..2b7164025 100644 --- a/src/coverlet.core/Extensions/DictionaryExtensions.cs +++ b/src/coverlet.tracker/Extensions/DictionaryExtensions.cs @@ -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(this Dictionary dictionary, T key, U value) { if (dictionary.ContainsKey(key)) diff --git a/src/coverlet.tracker/coverlet.tracker.csproj b/src/coverlet.tracker/coverlet.tracker.csproj new file mode 100644 index 000000000..9f5c4f4ab --- /dev/null +++ b/src/coverlet.tracker/coverlet.tracker.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/test/coverlet.core.tests/Extensions/DictionaryExtensionsTests.cs b/test/coverlet.core.tests/Extensions/DictionaryExtensionsTests.cs deleted file mode 100644 index 9f22fbb18..000000000 --- a/test/coverlet.core.tests/Extensions/DictionaryExtensionsTests.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; - -using Coverlet.Core.Extensions; -using Xunit; - -namespace Coverlet.Core.Tests.Extensions -{ - public class DictionaryExtensionsTests - { - [Fact] - public void TestTryAdd() - { - var dictionary = new Dictionary(); - Assert.True(DictionaryExtensions.TryAdd(dictionary, "a", "b")); - Assert.Equal("b", dictionary["a"]); - Assert.False(DictionaryExtensions.TryAdd(dictionary, "a", "c")); - } - } -} \ No newline at end of file diff --git a/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs b/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs index a41c4646c..f49175ad0 100644 --- a/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs +++ b/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs @@ -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); } diff --git a/test/coverlet.core.tests/Samples/Samples.cs b/test/coverlet.core.tests/Samples/Samples.cs index 31917b11c..4cf007c6d 100644 --- a/test/coverlet.core.tests/Samples/Samples.cs +++ b/test/coverlet.core.tests/Samples/Samples.cs @@ -175,8 +175,8 @@ public string Method(string input) return input; } - } - + } + [ExcludeFromCodeCoverage] public class ClassExcludedByCodeAnalysisCodeCoverageAttr { @@ -189,6 +189,4 @@ public string Method(string input) return input; } } - - } \ No newline at end of file