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

Coverlet Intergration with VSTest #410

Merged
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
7 changes: 0 additions & 7 deletions coverlet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.core.performancete
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.collector", "src\coverlet.collector\coverlet.collector.csproj", "{F5B2C45B-274B-43D6-9565-8B50659CFE56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "coverlet.inproccollector", "src\coverlet.inproccollector\coverlet.inproccollector.csproj", "{C53F1496-65AE-415D-A46B-4BA1BC45709B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "coverlet.collector.tests", "test\coverlet.collector.tests\coverlet.collector.tests.csproj", "{5ED4FA81-8F8C-4211-BA88-7573BD63262E}"
EndProject
Global
Expand Down Expand Up @@ -59,10 +57,6 @@ Global
{F5B2C45B-274B-43D6-9565-8B50659CFE56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5B2C45B-274B-43D6-9565-8B50659CFE56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5B2C45B-274B-43D6-9565-8B50659CFE56}.Release|Any CPU.Build.0 = Release|Any CPU
{C53F1496-65AE-415D-A46B-4BA1BC45709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53F1496-65AE-415D-A46B-4BA1BC45709B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53F1496-65AE-415D-A46B-4BA1BC45709B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53F1496-65AE-415D-A46B-4BA1BC45709B}.Release|Any CPU.Build.0 = Release|Any CPU
{5ED4FA81-8F8C-4211-BA88-7573BD63262E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ED4FA81-8F8C-4211-BA88-7573BD63262E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ED4FA81-8F8C-4211-BA88-7573BD63262E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -79,7 +73,6 @@ Global
{AE117FAA-C21D-4F23-917E-0C8050614750} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{C68CF6DE-F86C-4BCF-BAB9-7A60C320E1F9} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{F5B2C45B-274B-43D6-9565-8B50659CFE56} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
{C53F1496-65AE-415D-A46B-4BA1BC45709B} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
{5ED4FA81-8F8C-4211-BA88-7573BD63262E} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
using Coverlet.Collector.Utilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;

namespace Coverlet.Collector.DataCollector
namespace Coverlet.Collector.DataCollection
{
/// <summary>
/// Manages coverage report attachments
/// </summary>
internal class AttachmentManager : IDisposable
{
private readonly DataCollectionSink dataSink;
private readonly TestPlatformEqtTrace eqtTrace;
private readonly TestPlatformLogger logger;
private readonly DataCollectionContext dataCollectionContext;
private readonly IFileHelper fileHelper;
private readonly IDirectoryHelper directoryHelper;
private readonly string reportFileName;
private readonly string reportDirectory;
private readonly DataCollectionSink _dataSink;
private readonly TestPlatformEqtTrace _eqtTrace;
private readonly TestPlatformLogger _logger;
private readonly DataCollectionContext _dataCollectionContext;
private readonly IFileHelper _fileHelper;
private readonly IDirectoryHelper _directoryHelper;
private readonly string _reportFileName;
private readonly string _reportDirectory;

public AttachmentManager(DataCollectionSink dataSink, DataCollectionContext dataCollectionContext, TestPlatformLogger logger, TestPlatformEqtTrace eqtTrace, string reportFileName)
: this(dataSink,
Expand All @@ -36,20 +36,20 @@ public AttachmentManager(DataCollectionSink dataSink, DataCollectionContext data

public AttachmentManager(DataCollectionSink dataSink, DataCollectionContext dataCollectionContext, TestPlatformLogger logger, TestPlatformEqtTrace eqtTrace, string reportFileName, string reportDirectoryName, IFileHelper fileHelper, IDirectoryHelper directoryHelper)
{
// Store input vars
this.dataSink = dataSink;
this.dataCollectionContext = dataCollectionContext;
this.logger = logger;
this.eqtTrace = eqtTrace;
this.reportFileName = reportFileName;
this.fileHelper = fileHelper;
this.directoryHelper = directoryHelper;
// Store input variabless
_dataSink = dataSink;
_dataCollectionContext = dataCollectionContext;
_logger = logger;
_eqtTrace = eqtTrace;
_reportFileName = reportFileName;
_fileHelper = fileHelper;
_directoryHelper = directoryHelper;

// Report directory to store the coverage reports.
this.reportDirectory = Path.Combine(Path.GetTempPath(), reportDirectoryName);
_reportDirectory = Path.Combine(Path.GetTempPath(), reportDirectoryName);

// Register events
this.dataSink.SendFileCompleted += this.OnSendFileCompleted;
_dataSink.SendFileCompleted += this.OnSendFileCompleted;
}

/// <summary>
Expand All @@ -59,7 +59,7 @@ public AttachmentManager(DataCollectionSink dataSink, DataCollectionContext data
public void SendCoverageReport(string coverageReport)
{
// Save coverage report to file
var coverageReportPath = this.SaveCoverageReport(coverageReport);
string coverageReportPath = this.SaveCoverageReport(coverageReport);

// Send coverage attachment to test platform.
this.SendAttachment(coverageReportPath);
Expand All @@ -71,9 +71,17 @@ public void SendCoverageReport(string coverageReport)
public void Dispose()
{
// Unregister events
if (this.dataSink != null)
try
{
this.dataSink.SendFileCompleted -= this.OnSendFileCompleted;
if (_dataSink != null)
{
_dataSink.SendFileCompleted -= this.OnSendFileCompleted;
}
this.CleanupReportDirectory();
}
catch (Exception ex)
{
_logger.LogWarning(ex.ToString());
}
}

Expand All @@ -86,16 +94,16 @@ private string SaveCoverageReport(string report)
{
try
{
this.directoryHelper.CreateDirectory(this.reportDirectory);
var filePath = Path.Combine(this.reportDirectory, this.reportFileName);
this.fileHelper.WriteAllText(filePath, report);
this.eqtTrace.Info("{0}: Saved coverage report to path: '{1}'", CoverletConstants.DataCollectorName, filePath);
_directoryHelper.CreateDirectory(_reportDirectory);
string filePath = Path.Combine(_reportDirectory, _reportFileName);
_fileHelper.WriteAllText(filePath, report);
_eqtTrace.Info("{0}: Saved coverage report to path: '{1}'", CoverletConstants.DataCollectorName, filePath);

return filePath;
}
catch (Exception ex)
{
var errorMessage = string.Format(Resources.FailedToSaveCoverageReport, CoverletConstants.DataCollectorName, this.reportFileName, this.reportDirectory);
string errorMessage = string.Format(Resources.FailedToSaveCoverageReport, CoverletConstants.DataCollectorName, _reportFileName, _reportDirectory);
throw new CoverletDataCollectorException(errorMessage, ex);
}
}
Expand All @@ -109,12 +117,12 @@ public void OnSendFileCompleted(object sender, AsyncCompletedEventArgs e)
{
try
{
this.eqtTrace.Verbose("{0}: SendFileCompleted received", CoverletConstants.DataCollectorName);
_eqtTrace.Verbose("{0}: SendFileCompleted received", CoverletConstants.DataCollectorName);
this.CleanupReportDirectory();
}
catch (Exception ex)
{
this.logger.LogWarning(ex.ToString());
_logger.LogWarning(ex.ToString());
this.Dispose();
}
}
Expand All @@ -125,11 +133,15 @@ public void OnSendFileCompleted(object sender, AsyncCompletedEventArgs e)
/// <param name="attachmentPath">Attachment file path</param>
private void SendAttachment(string attachmentPath)
{
if (this.fileHelper.Exists(attachmentPath))
if (_fileHelper.Exists(attachmentPath))
{
// Send coverage attachment to test platform.
this.eqtTrace.Verbose("{0}: Sending attachment to test platform", CoverletConstants.DataCollectorName);
this.dataSink.SendFileAsync(this.dataCollectionContext, attachmentPath, false);
_eqtTrace.Verbose("{0}: Sending attachment to test platform", CoverletConstants.DataCollectorName);
_dataSink.SendFileAsync(_dataCollectionContext, attachmentPath, false);
}
else
{
_eqtTrace.Warning("{0}: Attachment file does not exist", CoverletConstants.DataCollectorName);
}
}

Expand All @@ -140,15 +152,15 @@ private void CleanupReportDirectory()
{
try
{
if (this.directoryHelper.Exists(this.reportDirectory))
if (_directoryHelper.Exists(_reportDirectory))
{
this.directoryHelper.Delete(this.reportDirectory, true);
this.eqtTrace.Verbose("{0}: Deleted report directory: '{1}'", CoverletConstants.DataCollectorName, this.reportDirectory);
_directoryHelper.Delete(_reportDirectory, true);
_eqtTrace.Verbose("{0}: Deleted report directory: '{1}'", CoverletConstants.DataCollectorName, _reportDirectory);
}
}
catch (Exception ex)
{
var errorMessage = string.Format(Resources.FailedToCleanupReportDirectory, CoverletConstants.DataCollectorName, this.reportDirectory);
string errorMessage = string.Format(Resources.FailedToCleanupReportDirectory, CoverletConstants.DataCollectorName, _reportDirectory);
throw new CoverletDataCollectorException(errorMessage, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
using Coverlet.Core.Logging;
using Coverlet.Core.Reporters;

namespace Coverlet.Collector.DataCollector
namespace Coverlet.Collector.DataCollection
{
/// <summary>
/// Manages coverlet coverage
/// </summary>
internal class CoverageManager
{
private readonly Coverage coverage;
private readonly Coverage _coverage;

private ICoverageWrapper coverageWrapper;
private ICoverageWrapper _coverageWrapper;

public IReporter Reporter { get; }
public IReporter _reporter { get; }
tonerdo marked this conversation as resolved.
Show resolved Hide resolved

public CoverageManager(CoverletSettings settings, TestPlatformEqtTrace eqtTrace, TestPlatformLogger logger, ICoverageWrapper coverageWrapper)
: this(settings,
Expand All @@ -30,11 +30,11 @@ public CoverageManager(CoverletSettings settings, TestPlatformEqtTrace eqtTrace,
public CoverageManager(CoverletSettings settings, IReporter reporter, ILogger logger, ICoverageWrapper coverageWrapper)
{
// Store input vars
this.Reporter = reporter;
this.coverageWrapper = coverageWrapper;
_reporter = reporter;
_coverageWrapper = coverageWrapper;

// Coverage object
this.coverage = this.coverageWrapper.CreateCoverage(settings, logger);
_coverage = _coverageWrapper.CreateCoverage(settings, logger);
}

/// <summary>
Expand All @@ -45,11 +45,11 @@ public void InstrumentModules()
try
{
// Instrument modules
this.coverageWrapper.PrepareModules(this.coverage);
_coverageWrapper.PrepareModules(_coverage);
}
catch (Exception ex)
{
var errorMessage = string.Format(Resources.InstrumentationException, CoverletConstants.DataCollectorName);
string errorMessage = string.Format(Resources.InstrumentationException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
}
}
Expand All @@ -61,10 +61,10 @@ public void InstrumentModules()
public string GetCoverageReport()
{
// Get coverage result
var coverageResult = this.GetCoverageResult();
CoverageResult coverageResult = this.GetCoverageResult();

// Get coverage report in default format
var coverageReport = this.GetCoverageReport(coverageResult);
string coverageReport = this.GetCoverageReport(coverageResult);
return coverageReport;
}

Expand All @@ -76,11 +76,11 @@ private CoverageResult GetCoverageResult()
{
try
{
return this.coverageWrapper.GetCoverageResult(this.coverage);
return _coverageWrapper.GetCoverageResult(_coverage);
}
catch (Exception ex)
{
var errorMessage = string.Format(Resources.CoverageResultException, CoverletConstants.DataCollectorName);
string errorMessage = string.Format(Resources.CoverageResultException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
}
}
Expand All @@ -94,11 +94,11 @@ private string GetCoverageReport(CoverageResult coverageResult)
{
try
{
return this.Reporter.Report(coverageResult);
return _reporter.Report(coverageResult);
}
catch (Exception ex)
{
var errorMessage = string.Format(Resources.CoverageReportException, CoverletConstants.DataCollectorName);
string errorMessage = string.Format(Resources.CoverageReportException, CoverletConstants.DataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Coverlet.Collector.DataCollector;
using Coverlet.Collector.Utilities.Interfaces;
using Coverlet.Collector.Utilities.Interfaces;
using Coverlet.Core;
using Coverlet.Core.Logging;

namespace coverlet.collector.DataCollector
namespace Coverlet.Collector.DataCollection
{
/// <summary>
/// Implementation for wrapping over Coverage class in coverlet.core
Expand Down
Loading