Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/coverlet.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int Main(string[] args)
if (!target.HasValue())
throw new CommandParsingException(app, "Target must be specified.");

Coverage coverage = new Coverage(module.Value, includeFilters.Values.ToArray(), includeDirectories.Values.ToArray(), excludeFilters.Values.ToArray(), excludedSourceFiles.Values.ToArray(), excludeAttributes.Values.ToArray(), singleHit.HasValue(), mergeWith.Value(), useSourceLink.HasValue(), logger);
Coverage coverage = new Coverage(module.Value, includeFilters.Values.ToArray(), includeDirectories.Values.ToArray(), excludeFilters.Values.ToArray(), excludedSourceFiles.Values.ToArray(), excludeAttributes.Values.ToArray(), singleHit.HasValue(), mergeWith.Value(), useSourceLink.HasValue(), logger, Guid.NewGuid().ToString());
coverage.PrepareModules();

Process process = new Process();
Expand Down
5 changes: 3 additions & 2 deletions src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public Coverage(string module,
bool singleHit,
string mergeWith,
bool useSourceLink,
ILogger logger)
ILogger logger,
string identifier)
{
_module = module;
_includeFilters = includeFilters;
Expand All @@ -53,8 +54,8 @@ public Coverage(string module,
_mergeWith = mergeWith;
_useSourceLink = useSourceLink;
_logger = logger;
_identifier = identifier;

_identifier = Guid.NewGuid().ToString();
_results = new List<InstrumenterResult>();
}

Expand Down
10 changes: 9 additions & 1 deletion src/coverlet.msbuild.tasks/CoverageResultTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ namespace Coverlet.MSbuild.Tasks
{
public class CoverageResultTask : Task
{
private string _identifier;
private string _output;
private string _format;
private double _threshold;
private string _thresholdType;
private string _thresholdStat;
private MSBuildLogger _logger;

[Required]
public string Identifier
{
get { return _identifier; }
set { _identifier = value; }
}

[Required]
public string Output
{
Expand Down Expand Up @@ -66,7 +74,7 @@ public override bool Execute()
{
Console.WriteLine("\nCalculating coverage result...");

var coverage = InstrumentationTask.Coverage;
var coverage = InstrumentationTask.Coverage[Identifier];
var result = coverage.GetCoverageResult();

var directory = Path.GetDirectoryName(_output);
Expand Down
18 changes: 14 additions & 4 deletions src/coverlet.msbuild.tasks/InstrumentationTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Immutable;
using Coverlet.Core;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand All @@ -7,7 +8,7 @@ namespace Coverlet.MSbuild.Tasks
{
public class InstrumentationTask : Task
{
private static Coverage _coverage;
private static ImmutableDictionary<string, Coverage> _coverage;
private string _path;
private string _include;
private string _includeDirectory;
Expand All @@ -19,7 +20,7 @@ public class InstrumentationTask : Task
private bool _useSourceLink;
private readonly MSBuildLogger _logger;

internal static Coverage Coverage
internal static ImmutableDictionary<string, Coverage> Coverage
{
get { return _coverage; }
}
Expand All @@ -31,6 +32,13 @@ public string Path
set { _path = value; }
}

[Required]
public string Identifier
{
get;
set;
}

public string Include
{
get { return _include; }
Expand Down Expand Up @@ -94,8 +102,10 @@ public override bool Execute()
var excludedSourceFiles = _excludeByFile?.Split(',');
var excludeAttributes = _excludeByAttribute?.Split(',');

_coverage = new Coverage(_path, includeFilters, includeDirectories, excludeFilters, excludedSourceFiles, excludeAttributes, _singleHit, _mergeWith, _useSourceLink, _logger);
_coverage.PrepareModules();
var coverage = new Coverage(_path, includeFilters, includeDirectories, excludeFilters, excludedSourceFiles, excludeAttributes, _singleHit, _mergeWith, _useSourceLink, _logger, Identifier);
coverage.PrepareModules();

ImmutableInterlocked.AddOrUpdate(ref _coverage, Identifier, coverage, (_1, _2) => coverage);
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/coverlet.msbuild.tasks/coverlet.msbuild.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CollectCoverage Condition="$(CollectCoverage) == ''">false</CollectCoverage>
<CoverletIdentifier>$([System.Guid]::NewGuid())</CoverletIdentifier>
<Include Condition="$(Include) == ''"></Include>
<IncludeDirectory Condition="$(IncludeDirectory) == ''"></IncludeDirectory>
<Exclude Condition="$(Exclude) == ''"></Exclude>
Expand Down
3 changes: 3 additions & 0 deletions src/coverlet.msbuild.tasks/coverlet.msbuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Coverlet.MSbuild.Tasks.InstrumentationTask
Condition="'$(VSTestNoBuild)' == 'true' and $(CollectCoverage) == 'true'"
Path="$(TargetPath)"
Identifier="$(CoverletIdentifier)"
Include="$(Include)"
IncludeDirectory="$(IncludeDirectory)"
Exclude="$(Exclude)"
Expand All @@ -21,6 +22,7 @@
<Coverlet.MSbuild.Tasks.InstrumentationTask
Condition="'$(VSTestNoBuild)' != 'true' and $(CollectCoverage) == 'true'"
Path="$(TargetPath)"
Identifier="$(CoverletIdentifier)"
Include="$(Include)"
IncludeDirectory="$(IncludeDirectory)"
Exclude="$(Exclude)"
Expand All @@ -34,6 +36,7 @@
<Target Name="GenerateCoverageResult" AfterTargets="VSTest">
<Coverlet.MSbuild.Tasks.CoverageResultTask
Condition="$(CollectCoverage) == 'true'"
Identifier="$(CoverletIdentifier)"
Output="$(CoverletOutput)"
OutputFormat="$(CoverletOutputFormat)"
Threshold="$(Threshold)"
Expand Down
2 changes: 1 addition & 1 deletion test/coverlet.core.tests/CoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void TestCoverage()

// TODO: Find a way to mimick hits

var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, string.Empty, false, new Mock<ILogger>().Object);
var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, string.Empty, false, new Mock<ILogger>().Object, Guid.NewGuid().ToString());
coverage.PrepareModules();

var result = coverage.GetCoverageResult();
Expand Down