Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/coverlet.collector/DataCollection/CoverageWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Coverlet.Collector.Utilities.Interfaces;
using Coverlet.Core;
using Coverlet.Core.Abstracts;
using coverlet.core.Extensions;
using Coverlet.Core.Logging;

namespace Coverlet.Collector.DataCollection
Expand Down Expand Up @@ -30,8 +31,8 @@ public Coverage CreateCoverage(CoverletSettings settings, ILogger coverletLogger
settings.MergeWith,
settings.UseSourceLink,
coverletLogger,
(IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)),
(IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem)));
DependencyInjection.Current.GetService<IInstrumentationHelper>(),
DependencyInjection.Current.GetService<IFileSystem>());
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/coverlet.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Coverlet.Core;
using Coverlet.Core.Abstracts;
using Coverlet.Core.Enums;
using coverlet.core.Extensions;
using Coverlet.Core.Reporters;
using McMaster.Extensions.CommandLineUtils;

Expand Down Expand Up @@ -59,7 +60,7 @@ static int Main(string[] args)
// Adjust log level based on user input.
logger.Level = verbosity.ParsedValue;
}
var fileSystem = (IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem));
var fileSystem = DependencyInjection.Current.GetService<IFileSystem>();
Coverage coverage = new Coverage(module.Value,
includeFilters.Values.ToArray(),
includeDirectories.Values.ToArray(),
Expand All @@ -71,7 +72,7 @@ static int Main(string[] args)
mergeWith.Value(),
useSourceLink.HasValue(),
logger,
(IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)),
DependencyInjection.Current.GetService<IInstrumentationHelper>(),
fileSystem);
coverage.PrepareModules();

Expand Down
14 changes: 14 additions & 0 deletions src/coverlet.core/Extensions/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Coverlet.Core.Attributes;

namespace coverlet.core.Extensions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: namespace casing Coverlet.Core.Extensions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

{
public static class DependencyInjectionExtensions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we'll merge #566 we'll hide as internals...for now it's ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, for now it will stay public.

{
[ExcludeFromCoverage]
public static T GetService<T>(this IServiceProvider serviceProvider)
{
return (T)serviceProvider.GetService(typeof(T));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why [ExcludeFromCoverage]? core lib won't be instrumented so we don't need to exclude, you can remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I added it as it was on HelperExtensions. Maybe if core lib won't be instrumented I should remove [ExcludeFromCoverage] from ``HelperExtensions` too?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok...understood...I think it was placed to remove from "autocoverage" that we do on build.

}
}
}
5 changes: 3 additions & 2 deletions src/coverlet.msbuild.tasks/CoverageResultTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Coverlet.Core;
using Coverlet.Core.Abstracts;
using Coverlet.Core.Enums;
using coverlet.core.Extensions;
using Coverlet.Core.Reporters;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -75,7 +76,7 @@ public override bool Execute()
{
Console.WriteLine("\nCalculating coverage result...");

IFileSystem fileSystem = (IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem));
IFileSystem fileSystem = DependencyInjection.Current.GetService<IFileSystem>();
if (InstrumenterState is null || !fileSystem.Exists(InstrumenterState.ItemSpec))
{
_logger.LogError("Result of instrumentation task not found");
Expand All @@ -85,7 +86,7 @@ public override bool Execute()
Coverage coverage = null;
using (Stream instrumenterStateStream = fileSystem.NewFileStream(InstrumenterState.ItemSpec, FileMode.Open))
{
coverage = new Coverage(CoveragePrepareResult.Deserialize(instrumenterStateStream), this._logger, (IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)), fileSystem);
coverage = new Coverage(CoveragePrepareResult.Deserialize(instrumenterStateStream), this._logger, DependencyInjection.Current.GetService<IInstrumentationHelper>(), fileSystem);
}

CoverageResult result = coverage.GetCoverageResult();
Expand Down
5 changes: 3 additions & 2 deletions src/coverlet.msbuild.tasks/InstrumentationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Coverlet.Core;
using Coverlet.Core.Abstracts;
using coverlet.core.Extensions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -105,7 +106,7 @@ public override bool Execute()
var excludeFilters = _exclude?.Split(',');
var excludedSourceFiles = _excludeByFile?.Split(',');
var excludeAttributes = _excludeByAttribute?.Split(',');
var fileSystem = (IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem));
var fileSystem = DependencyInjection.Current.GetService<IFileSystem>();

Coverage coverage = new Coverage(_path,
includeFilters,
Expand All @@ -118,7 +119,7 @@ public override bool Execute()
_mergeWith,
_useSourceLink,
_logger,
(IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)),
DependencyInjection.Current.GetService<IInstrumentationHelper>(),
fileSystem);

CoveragePrepareResult prepareResult = coverage.PrepareModules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Coverlet.Collector.DataCollection;
using Coverlet.Core.Reporters;
using Coverlet.Core.Abstracts;
using coverlet.core.Extensions;

namespace Coverlet.Collector.Tests
{
Expand Down Expand Up @@ -74,7 +75,10 @@ public void OnSessionStartShouldPrepareModulesForCoverage()
null,
_context);
IDictionary<string, object> sessionStartProperties = new Dictionary<string, object>();
Coverage coverage = new Coverage("abc.dll", null, null, null, null, null, true, true, "abc.json", true, It.IsAny<ILogger>(), (IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)), (IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem)));
Coverage coverage = new Coverage("abc.dll", null, null, null, null, null, true, true, "abc.json", true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep declaration in one line...it's not so long at the moment, I prefer all in one line or all stacked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right consistency is better, fixed.

It.IsAny<ILogger>(),
DependencyInjection.Current.GetService<IInstrumentationHelper>(),
DependencyInjection.Current.GetService<IFileSystem>());

sessionStartProperties.Add("TestSources", new List<string> { "abc.dll" });
_mockCoverageWrapper.Setup(x => x.CreateCoverage(It.IsAny<CoverletSettings>(), It.IsAny<ILogger>())).Returns(coverage);
Expand Down