Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create libraries #135

Merged
merged 6 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions MiniCover.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniCover", "src\MiniCover\MiniCover.csproj", "{CE06DCCF-32DB-44F2-B6D8-37DD0395C406}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover", "src\MiniCover\MiniCover.csproj", "{CE06DCCF-32DB-44F2-B6D8-37DD0395C406}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniCover.UnitTests", "tests\MiniCover.UnitTests\MiniCover.UnitTests.csproj", "{7373D72F-D0A7-4D74-BA48-39E4CA7679DE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.UnitTests", "tests\MiniCover.UnitTests\MiniCover.UnitTests.csproj", "{7373D72F-D0A7-4D74-BA48-39E4CA7679DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniCover.HitServices", "src\MiniCover.HitServices\MiniCover.HitServices.csproj", "{0A895434-3E4B-4BA7-BA90-C4894BECEECA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniCover.HitServices.UnitTests", "tests\MiniCover.HitServices.UnitTests\MiniCover.HitServices.UnitTests.csproj", "{AF2FD8B1-8CF7-46FB-B94D-6D892B5A33C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.Core", "src\MiniCover.Core\MiniCover.Core.csproj", "{F3CF9511-1A18-44E5-96D1-F7330C7A7C1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.Reports", "src\MiniCover.Reports\MiniCover.Reports.csproj", "{FEC52983-15CF-4420-8700-0E0B6E16B101}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.Core.UnitTests", "tests\MiniCover.Core.UnitTests\MiniCover.Core.UnitTests.csproj", "{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.Reports.UnitTests", "tests\MiniCover.Reports.UnitTests\MiniCover.Reports.UnitTests.csproj", "{2000A3C7-504B-4760-9DC1-167B96C04E77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniCover.TestHelpers", "tests\MiniCover.TestHelpers\MiniCover.TestHelpers.csproj", "{21EEDEA8-B073-4868-9E29-D0574547B884}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,13 +45,36 @@ Global
{AF2FD8B1-8CF7-46FB-B94D-6D892B5A33C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF2FD8B1-8CF7-46FB-B94D-6D892B5A33C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF2FD8B1-8CF7-46FB-B94D-6D892B5A33C9}.Release|Any CPU.Build.0 = Release|Any CPU
{F3CF9511-1A18-44E5-96D1-F7330C7A7C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3CF9511-1A18-44E5-96D1-F7330C7A7C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3CF9511-1A18-44E5-96D1-F7330C7A7C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3CF9511-1A18-44E5-96D1-F7330C7A7C1E}.Release|Any CPU.Build.0 = Release|Any CPU
{FEC52983-15CF-4420-8700-0E0B6E16B101}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEC52983-15CF-4420-8700-0E0B6E16B101}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEC52983-15CF-4420-8700-0E0B6E16B101}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEC52983-15CF-4420-8700-0E0B6E16B101}.Release|Any CPU.Build.0 = Release|Any CPU
{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB}.Release|Any CPU.Build.0 = Release|Any CPU
{2000A3C7-504B-4760-9DC1-167B96C04E77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2000A3C7-504B-4760-9DC1-167B96C04E77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2000A3C7-504B-4760-9DC1-167B96C04E77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2000A3C7-504B-4760-9DC1-167B96C04E77}.Release|Any CPU.Build.0 = Release|Any CPU
{21EEDEA8-B073-4868-9E29-D0574547B884}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21EEDEA8-B073-4868-9E29-D0574547B884}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21EEDEA8-B073-4868-9E29-D0574547B884}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21EEDEA8-B073-4868-9E29-D0574547B884}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7373D72F-D0A7-4D74-BA48-39E4CA7679DE} = {32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}
{AF2FD8B1-8CF7-46FB-B94D-6D892B5A33C9} = {32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}
{6610CDC4-7860-4D3D-BCE3-B8B6383A9CFB} = {32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}
{2000A3C7-504B-4760-9DC1-167B96C04E77} = {32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}
{21EEDEA8-B073-4868-9E29-D0574547B884} = {32DDAE15-CEC4-4D44-9561-AF82BE1C2DA9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C9809608-5E38-4E98-80B5-7CD7859FF4E8}
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,47 @@ coverage-html
coverage-hits
coverage.json
```

## Libraries

When using MiniCover libraries:

- use dependency injection to create instances
- use only the main interfaces listed on each package below

By doing that, you reduce the risk of being impacted by future MiniCover changes.

### MiniCover.Core

Main MiniCover operations.

Dependency injection configuration:
```C#
services.AddMiniCoverCore();
```

Main interfaces:
- IInstrumenter
- IUninstrumenter
- IHitsReader
- IHitsResetter

### MiniCover.Reports

MiniCover reports.

Dependency injection configuration:
```C#
services.AddMiniCoverCore();
services.AddMiniCoverReports();
```

Main interfaces:
- ICloverReport
- ICoberturaReport
- IConsoleReport
- ICoverallsReport
- IHtmlReport
- IHtmlSourceFileReport
- INCoverReport
- IOpenCoverReport
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ jobs:
useGlobalJson: true
- bash: |
export Version=${TagName:1}
dotnet pack -c Release
dotnet nuget push nupkg/*.nupkg -k $NUGET_KEY -s https://api.nuget.org/v3/index.json
dotnet pack -c Release -o nupkg
dotnet nuget push "nupkg/*.nupkg" -k $NUGET_KEY -s https://api.nuget.org/v3/index.json
env:
TagName: '$(Build.SourceBranchName)'
NUGET_KEY: '$(NUGET_KEY)'
Expand Down
14 changes: 7 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ echo "# Start Uninstrument"
./minicover.sh uninstrument
echo "# End Uninstrument"

echo "# Start CoberturaReport"
./minicover.sh coberturareport
echo "# End CoberturaReport"
echo "# Start Report"
./minicover.sh report --threshold 34
echo "# End Report"

echo "# Start HtmlReport"
./minicover.sh htmlreport --threshold 35
./minicover.sh htmlreport --threshold 34
echo "# End HtmlReport"

echo "# Start Report"
./minicover.sh report --threshold 35
echo "# End Report"
echo "# Start CoberturaReport"
./minicover.sh coberturareport
echo "# End CoberturaReport"

if [ -n "${BUILD_BUILDID}" ] && [ -n "${COVERALLS_REPO_TOKEN}" ]; then
echo "# Start Coveralls Report"
Expand Down
26 changes: 26 additions & 0 deletions sample/src/Sample/WorkerThread.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading;
using System.Threading.Tasks;

namespace Sample
{
public static class WorkerThread
{
public static Task RunWorkerThread()
{
var tcs = new TaskCompletionSource<bool>();
var thread = new Thread(() => DoWork(tcs));
thread.Start();
return tcs.Task;
}

private static void DoWork(TaskCompletionSource<bool> tcs)
{
for (int i = 0; i < 3; i++)
{
Thread.Sleep(100);
}

tcs.SetResult(true);
}
}
}
17 changes: 17 additions & 0 deletions sample/tests/Sample.UnitTests/WorkerThreadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Sample.TryFinally;
using Xunit;

namespace Sample.UnitTests
{
public class WorkerThreadTests
{
[Fact]
public async Task TestWorkerThread()
{
await WorkerThread.RunWorkerThread();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class AssemblyDefinitionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class CodeExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using Mono.Cecil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class CustomAttributeProviderExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Security.Cryptography;
using Mono.Cecil.Cil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class DocumentExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class EnumerableExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using MiniCover.Model;
using MiniCover.Core.Model;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class GraphNodeExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil.Cil;

namespace Mono.Cecil.Cil
namespace MiniCover.Core.Extensions
{
public static class ILProcessorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using MiniCover.Model;
using MiniCover.Core.Model;
using Mono.Cecil.Cil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class InstructionExtensions
{
Expand All @@ -16,8 +16,9 @@ public static GraphNode<Instruction> ToGraph(this Instruction rootInstruction)
var pending = new Queue<GraphNode<Instruction>>();
pending.Enqueue(rootNode);

while (pending.TryDequeue(out var node))
while (pending.Count > 0)
{
var node = pending.Dequeue();
foreach (var childInstruction in node.Value.GetChildren())
{
if (!cache.TryGetValue(childInstruction, out var childNode))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class MethodDefinitionExtensions
{
Expand All @@ -27,21 +27,24 @@ public static bool IsExcludedFromCodeCoverage(this MethodDefinition methodDefini
var sequencePointsQueue = new Queue<SequencePoint>(methodDefinition.DebugInformation.SequencePoints);
var instructionsQueue = new Queue<Instruction>(methodDefinition.Body.Instructions);

if (sequencePointsQueue.TryDequeue(out var sequencePoint))
if (sequencePointsQueue.Count > 0)
{
while (sequencePointsQueue.TryDequeue(out var nextSequencePoint))
var sequencePoint = sequencePointsQueue.Dequeue();
while (sequencePointsQueue.Count > 0)
{
while (instructionsQueue.TryPeek(out var instruction)
&& instruction.Offset < nextSequencePoint.Offset)
var nextSequencePoint = sequencePointsQueue.Dequeue();
while (instructionsQueue.Count > 0
&& instructionsQueue.Peek().Offset < nextSequencePoint.Offset)
{
yield return (sequencePoint, instructionsQueue.Dequeue());
}

sequencePoint = nextSequencePoint;
}

while (instructionsQueue.TryDequeue(out var remainingInstruction))
while (instructionsQueue.Count > 0)
{
var remainingInstruction = instructionsQueue.Dequeue();
yield return (sequencePoint, remainingInstruction);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Reflection;
using Mono.Cecil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class ModuleDefinitionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class ObjectExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace MiniCover.Extensions
namespace MiniCover.Core.Extensions
{
public static class TypeDefinitionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
using System.IO;
using System.IO;
using System.IO.Abstractions;
using Microsoft.Extensions.Caching.Memory;

namespace MiniCover.Infrastructure.FileSystem
namespace MiniCover.Core.FileSystem
{
public class CachedFileReader : IFileReader
{
private readonly IMemoryCache _memoryCache;
private readonly IFileSystem _fileSystem;

public CachedFileReader(IMemoryCache memoryCache)
public CachedFileReader(
IMemoryCache memoryCache,
IFileSystem fileSystem)
{
_memoryCache = memoryCache;
_fileSystem = fileSystem;
}

public string[] ReadAllLines(FileInfo file)
{
return _memoryCache.GetOrCreate<string[]>(file.FullName, entry =>
{
entry.Priority = CacheItemPriority.Low;
return File.ReadAllLines(file.FullName);
return _fileSystem.File.ReadAllLines(file.FullName);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;

namespace MiniCover.Infrastructure.FileSystem
namespace MiniCover.Core.FileSystem
{
public interface IFileReader
{
Expand Down
Loading