diff --git a/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs b/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs index 7a3b619ba8..5b6eabd0d7 100644 --- a/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs +++ b/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs @@ -235,6 +235,23 @@ public void Should_Append_DisableDefaultFilters() "/DisableDefaultFilters", result.Args); } + [Fact] + public void Should_Append_LogFile() + { + // Given + var fixture = new DotCoverAnalyserFixture(); + fixture.Settings.LogFile = "./logfile.log"; + + // When + var result = fixture.Run(); + + // Then + Assert.Equal("Analyse /TargetExecutable=\"/Working/tools/Test.exe\" " + + "/TargetArguments=\"-argument\" " + + "/Output=\"/Working/result.xml\" " + + "/LogFile=\"/Working/logfile.log\"", result.Args); + } + [Fact] public void Should_Capture_XUnit() { diff --git a/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs b/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs index 9d7281e88d..a3f0fead86 100644 --- a/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs +++ b/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs @@ -114,38 +114,8 @@ private ProcessArgumentBuilder GetArguments( builder.AppendSwitch("/ReportType", "=", settings.ReportType.ToString()); } - // TargetWorkingDir - if (settings.TargetWorkingDir != null) - { - builder.AppendSwitch("/TargetWorkingDir", "=", settings.TargetWorkingDir.MakeAbsolute(_environment).FullPath.Quote()); - } - - // Scope - if (settings.Scope.Count > 0) - { - var scope = string.Join(";", settings.Scope); - builder.AppendSwitch("/Scope", "=", scope.Quote()); - } - - // Filters - if (settings.Filters.Count > 0) - { - var filters = string.Join(";", settings.Filters); - builder.AppendSwitch("/Filters", "=", filters.Quote()); - } - - // Filters - if (settings.AttributeFilters.Count > 0) - { - var attributeFilters = string.Join(";", settings.AttributeFilters); - builder.AppendSwitch("/AttributeFilters", "=", attributeFilters.Quote()); - } - - // DisableDefaultFilters - if (settings.DisableDefaultFilters) - { - builder.Append("/DisableDefaultFilters"); - } + // Set common Coverage settings + settings.ToArguments(_environment).CopyTo(builder); return builder; } diff --git a/src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverer.cs b/src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverer.cs index e7c366dfab..e1e3f1d9d2 100644 --- a/src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverer.cs +++ b/src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverer.cs @@ -108,38 +108,8 @@ private ProcessArgumentBuilder GetArguments( outputPath = outputPath.MakeAbsolute(_environment); builder.AppendSwitch("/Output", "=", outputPath.FullPath.Quote()); - // TargetWorkingDir - if (settings.TargetWorkingDir != null) - { - builder.AppendSwitch("/TargetWorkingDir", "=", settings.TargetWorkingDir.MakeAbsolute(_environment).FullPath.Quote()); - } - - // Scope - if (settings.Scope.Count > 0) - { - var scope = string.Join(";", settings.Scope); - builder.AppendSwitch("/Scope", "=", scope.Quote()); - } - - // Filters - if (settings.Filters.Count > 0) - { - var filters = string.Join(";", settings.Filters); - builder.AppendSwitch("/Filters", "=", filters.Quote()); - } - - // Filters - if (settings.AttributeFilters.Count > 0) - { - var attributeFilters = string.Join(";", settings.AttributeFilters); - builder.AppendSwitch("/AttributeFilters", "=", attributeFilters.Quote()); - } - - // DisableDefaultFilters - if (settings.DisableDefaultFilters) - { - builder.Append("/DisableDefaultFilters"); - } + // Set common Coverage settings + settings.ToArguments(_environment).CopyTo(builder); return builder; } diff --git a/src/Cake.Common/Tools/DotCover/DotCoverSettings.cs b/src/Cake.Common/Tools/DotCover/DotCoverSettings.cs index 79b1ee2146..ecf68375be 100644 --- a/src/Cake.Common/Tools/DotCover/DotCoverSettings.cs +++ b/src/Cake.Common/Tools/DotCover/DotCoverSettings.cs @@ -52,6 +52,12 @@ public abstract class DotCoverSettings : ToolSettings /// public bool DisableDefaultFilters { get; set; } + /// + /// Gets or sets a value that enables logging and specifies log file name + /// This represents the /LogFile option. + /// + public FilePath LogFile { get; set; } + /// /// Initializes a new instance of the class. /// diff --git a/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs b/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs index eebffd74cf..0581a3553c 100644 --- a/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs +++ b/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System; +using Cake.Core; +using Cake.Core.IO; namespace Cake.Common.Tools.DotCover { @@ -61,5 +63,52 @@ public static T WithAttributeFilter(this T settings, string attributeFilter) settings.AttributeFilters.Add(attributeFilter); return settings; } + + internal static ProcessArgumentBuilder ToArguments(this DotCoverSettings settings, ICakeEnvironment environment) + { + var builder = new ProcessArgumentBuilder(); + + // TargetWorkingDir + if (settings.TargetWorkingDir != null) + { + builder.AppendSwitch("/TargetWorkingDir", "=", settings.TargetWorkingDir.MakeAbsolute(environment).FullPath.Quote()); + } + + // Scope + if (settings.Scope.Count > 0) + { + var scope = string.Join(";", settings.Scope); + builder.AppendSwitch("/Scope", "=", scope.Quote()); + } + + // Filters + if (settings.Filters.Count > 0) + { + var filters = string.Join(";", settings.Filters); + builder.AppendSwitch("/Filters", "=", filters.Quote()); + } + + // Filters + if (settings.AttributeFilters.Count > 0) + { + var attributeFilters = string.Join(";", settings.AttributeFilters); + builder.AppendSwitch("/AttributeFilters", "=", attributeFilters.Quote()); + } + + // DisableDefaultFilters + if (settings.DisableDefaultFilters) + { + builder.Append("/DisableDefaultFilters"); + } + + // LogFile + if (settings.LogFile != null) + { + var logFilePath = settings.LogFile.MakeAbsolute(environment); + builder.AppendSwitch("/LogFile", "=", logFilePath.FullPath.Quote()); + } + + return builder; + } } } \ No newline at end of file