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 10d84ee39a..d3a39025ac 100644 --- a/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs +++ b/src/Cake.Common.Tests/Unit/Tools/DotCover/Analyse/DotCoverAnalyserTests.cs @@ -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); + } } } } \ No newline at end of file diff --git a/src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.cs b/src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.cs index f0515809f8..bb74ba5f17 100644 --- a/src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.cs +++ b/src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.cs @@ -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); + } } } } \ No newline at end of file diff --git a/src/Cake.Common.Tests/Unit/Tools/DotCover/Merge/DotCoverMergerTests.cs b/src/Cake.Common.Tests/Unit/Tools/DotCover/Merge/DotCoverMergerTests.cs index ddb046dfe2..238584413e 100644 --- a/src/Cake.Common.Tests/Unit/Tools/DotCover/Merge/DotCoverMergerTests.cs +++ b/src/Cake.Common.Tests/Unit/Tools/DotCover/Merge/DotCoverMergerTests.cs @@ -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; @@ -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); + } } } } \ No newline at end of file diff --git a/src/Cake.Common.Tests/Unit/Tools/DotCover/Report/DotCoverReporterTests.cs b/src/Cake.Common.Tests/Unit/Tools/DotCover/Report/DotCoverReporterTests.cs index ed918024dd..468f0c17a5 100644 --- a/src/Cake.Common.Tests/Unit/Tools/DotCover/Report/DotCoverReporterTests.cs +++ b/src/Cake.Common.Tests/Unit/Tools/DotCover/Report/DotCoverReporterTests.cs @@ -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 @@ -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); + } } } } \ No newline at end of file diff --git a/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs b/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs index f29f43de96..c7c90b3b90 100644 --- a/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs +++ b/src/Cake.Common/Tools/DotCover/Analyse/DotCoverAnalyser.cs @@ -75,6 +75,9 @@ public sealed class DotCoverAnalyser : DotCoverCoverageTool/LogFile option. /// public FilePath LogFile { get; set; } + + /// + /// 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. + /// + public FilePath ConfigFile { get; set; } } } diff --git a/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs b/src/Cake.Common/Tools/DotCover/DotCoverSettingsExtensions.cs new file mode 100644 index 0000000000..211a3901fd --- /dev/null +++ b/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 +{ + /// + /// Contains extensions for . + /// + public static class DotCoverSettingsExtensions + { + /// + /// Adds the scope. + /// + /// The settings. + /// The DotCover configuration file. + /// The settings type, derived from + /// The same instance so that multiple calls can be chained. + public static T WithConfigFile(this T settings, FilePath configFile) + where T : DotCoverSettings + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + settings.ConfigFile = configFile; + return settings; + } + } +} diff --git a/src/Cake.Common/Tools/DotCover/DotCoverTool.cs b/src/Cake.Common/Tools/DotCover/DotCoverTool.cs index b1958800f3..3df28df359 100644 --- a/src/Cake.Common/Tools/DotCover/DotCoverTool.cs +++ b/src/Cake.Common/Tools/DotCover/DotCoverTool.cs @@ -70,5 +70,22 @@ protected ProcessArgumentBuilder GetArguments(DotCoverSettings settings) return builder; } + + /// + /// Get configuration full path from coverage settings + /// + /// The settings + /// The process arguments + protected ProcessArgumentBuilder GetConfigurationFileArgument(DotCoverSettings settings) + { + var builder = new ProcessArgumentBuilder(); + + if (settings.ConfigFile != null) + { + builder.AppendQuoted(settings.ConfigFile.MakeAbsolute(_environment).FullPath); + } + + return builder; + } } } \ No newline at end of file diff --git a/src/Cake.Common/Tools/DotCover/Merge/DotCoverMerger.cs b/src/Cake.Common/Tools/DotCover/Merge/DotCoverMerger.cs index 3e348a14bc..aa143b58cf 100644 --- a/src/Cake.Common/Tools/DotCover/Merge/DotCoverMerger.cs +++ b/src/Cake.Common/Tools/DotCover/Merge/DotCoverMerger.cs @@ -71,6 +71,9 @@ public sealed class DotCoverMerger : DotCoverTool 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()); diff --git a/src/Cake.Common/Tools/DotCover/Report/DotCoverReporter.cs b/src/Cake.Common/Tools/DotCover/Report/DotCoverReporter.cs index 63acfb7362..7bc8bde4e4 100644 --- a/src/Cake.Common/Tools/DotCover/Report/DotCoverReporter.cs +++ b/src/Cake.Common/Tools/DotCover/Report/DotCoverReporter.cs @@ -69,6 +69,9 @@ public sealed class DotCoverReporter : DotCoverTool 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());