Skip to content

Commit

Permalink
Support for DotCover configuration file added - fixes cake-build#1401
Browse files Browse the repository at this point in the history
  • Loading branch information
AdaskoTheBeAsT committed Jul 19, 2018
1 parent ba349da commit caa7cc9
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 3 deletions.
Expand Up @@ -295,6 +295,22 @@ public void Should_Capture_NUnit()
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " +
"/Output=\"/Working/result.xml\"", result.Args);
}

[Fact]
public void Should_Append_ConfigurationFile()
{
// Given
var fixture = new DotCoverAnalyserFixture();
fixture.Settings.WithConfigFile(new FilePath("./config.xml"));

// When
var result = fixture.Run();

// Then
Assert.Equal("Analyse \"/Working/config.xml\" /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.xml\"", result.Args);
}
}
}
}
Expand Up @@ -275,6 +275,22 @@ public void Should_Capture_NUnit()
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}

[Fact]
public void Should_Append_ConfigurationFile()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.WithConfigFile(new FilePath("./config.xml"));

// When
var result = fixture.Run();

// Then
Assert.Equal("Cover \"/Working/config.xml\" /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}
}
}
}
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using Cake.Common.Tests.Fixtures.Tools.DotCover.Merge;
using Cake.Common.Tools.DotCover;
using Cake.Core.IO;
using Xunit;

Expand Down Expand Up @@ -85,6 +86,22 @@ public void Should_Append_LogFile()
"/Output=\"/Working/result.dcvr\" " +
"/LogFile=\"/Working/logfile.log\"", result.Args);
}

[Fact]
public void Should_Append_ConfigurationFile()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.Settings.WithConfigFile(new FilePath("./config.xml"));

// When
var result = fixture.Run();

// Then
Assert.Equal("Merge \"/Working/config.xml\" " +
"/Source=\"/Working/result1.dcvr;/Working/result2.dcvr\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}
}
}
}
Expand Up @@ -4,10 +4,7 @@

using Cake.Common.Tests.Fixtures.Tools.DotCover.Report;
using Cake.Common.Tools.DotCover;
using Cake.Common.Tools.NUnit;
using Cake.Common.Tools.XUnit;
using Cake.Core.IO;
using Cake.Testing;
using Xunit;

namespace Cake.Common.Tests.Unit.Tools.DotCover.Report
Expand Down Expand Up @@ -95,6 +92,22 @@ public void Should_Append_LogFile()
"/Output=\"/Working/result.xml\" " +
"/LogFile=\"/Working/logfile.log\"", result.Args);
}

[Fact]
public void Should_Append_ConfigurationFile()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.Settings.WithConfigFile(new FilePath("./config.xml"));

// When
var result = fixture.Run();

// Then
Assert.Equal("Report \"/Working/config.xml\" " +
"/Source=\"/Working/result.dcvr\" " +
"/Output=\"/Working/result.xml\"", result.Args);
}
}
}
}
3 changes: 3 additions & 0 deletions src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs
Expand Up @@ -75,6 +75,9 @@ public sealed class DotCoverAnalyser : DotCoverCoverageTool<DotCoverAnalyseSetti

builder.Append("Analyse");

// Set configuration file if exists.
GetConfigurationFileArgument(settings).CopyTo(builder);

// Get Target executable arguments
GetTargetArguments(context, action).CopyTo(builder);

Expand Down
3 changes: 3 additions & 0 deletions src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverer.cs
Expand Up @@ -75,6 +75,9 @@ public sealed class DotCoverCoverer : DotCoverCoverageTool<DotCoverCoverSettings

builder.Append("Cover");

// Set configuration file if exists.
GetConfigurationFileArgument(settings).CopyTo(builder);

// Get Target executable arguments
GetTargetArguments(context, action).CopyTo(builder);

Expand Down
7 changes: 7 additions & 0 deletions src/Cake.Common/Tools/DotCover/DotCoverSettings.cs
Expand Up @@ -17,5 +17,12 @@ public abstract class DotCoverSettings : ToolSettings
/// This represents the <c>/LogFile</c> option.
/// </summary>
public FilePath LogFile { get; set; }

/// <summary>
/// Gets or sets a value that enables DotCover configuration file.
/// A configuration file is a reasonable alternative
/// to specifying all parameters in-line or having them in a batch file.
/// </summary>
public FilePath ConfigFile { get; set; }
}
}
34 changes: 34 additions & 0 deletions src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Core.IO;

namespace Cake.Common.Tools.DotCover
{
/// <summary>
/// Contains extensions for <see cref="DotCoverSettings"/>.
/// </summary>
public static class DotCoverSettingsExtensions
{
/// <summary>
/// Adds the scope.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="configFile">The DotCover configuration file.</param>
/// <typeparam name="T">The settings type, derived from <see cref="DotCoverSettings"/></typeparam>
/// <returns>The same <see cref="DotCoverSettings"/> instance so that multiple calls can be chained.</returns>
public static T WithConfigFile<T>(this T settings, FilePath configFile)
where T : DotCoverSettings
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

settings.ConfigFile = configFile;
return settings;
}
}
}
17 changes: 17 additions & 0 deletions src/Cake.Common/Tools/DotCover/DotCoverTool.cs
Expand Up @@ -70,5 +70,22 @@ protected ProcessArgumentBuilder GetArguments(DotCoverSettings settings)

return builder;
}

/// <summary>
/// Get configuration full path from coverage settings
/// </summary>
/// <param name="settings">The settings</param>
/// <returns>The process arguments</returns>
protected ProcessArgumentBuilder GetConfigurationFileArgument(DotCoverSettings settings)
{
var builder = new ProcessArgumentBuilder();

if (settings.ConfigFile != null)
{
builder.AppendQuoted(settings.ConfigFile.MakeAbsolute(_environment).FullPath);
}

return builder;
}
}
}
3 changes: 3 additions & 0 deletions src/Cake.Common/Tools/DotCover/Merge/DotCoverMerger.cs
Expand Up @@ -71,6 +71,9 @@ public sealed class DotCoverMerger : DotCoverTool<DotCoverMergeSettings>

builder.Append("Merge");

// Set configuration file if exists.
GetConfigurationFileArgument(settings).CopyTo(builder);

// Set the Source files.
var source = string.Join(";", sourceFiles.Select(s => s.MakeAbsolute(_environment).FullPath));
builder.AppendSwitch("/Source", "=", source.Quote());
Expand Down
3 changes: 3 additions & 0 deletions src/Cake.Common/Tools/DotCover/Report/DotCoverReporter.cs
Expand Up @@ -69,6 +69,9 @@ public sealed class DotCoverReporter : DotCoverTool<DotCoverReportSettings>

builder.Append("Report");

// Set configuration file if exists.
GetConfigurationFileArgument(settings).CopyTo(builder);

// Set the Source file.
sourceFile = sourceFile.MakeAbsolute(_environment);
builder.AppendSwitch("/Source", "=", sourceFile.FullPath.Quote());
Expand Down

0 comments on commit caa7cc9

Please sign in to comment.