Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void Should_Append_LogFile()
// Given
var fixture = new DotCoverAnalyserFixture();
fixture.Settings.LogFile = "./logfile.log";
fixture.Settings.UseLegacySyntax = true;

// When
var result = fixture.Run();
Expand Down
269 changes: 244 additions & 25 deletions src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.cs

Large diffs are not rendered by default.

113 changes: 102 additions & 11 deletions src/Cake.Common.Tests/Unit/Tools/DotCover/Merge/DotCoverMergerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Cake.Common.Tools.DotCover;
using Cake.Core.IO;
using Xunit;

namespace Cake.Common.Tests.Unit.Tools.DotCover.Merge
{
public sealed class DotCoverMergerTests
Expand Down Expand Up @@ -43,31 +42,83 @@ public void Should_Throw_If_Source_Files_Is_Empty()
}

[Fact]
public void Should_Throw_If_Output_File_Is_Null()
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.OutputFile = null;
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
AssertEx.IsArgumentNullException(result, "outputFile");
AssertEx.IsArgumentNullException(result, "settings");
}

#region New Parameter Syntax

[Fact]
public void Should_Throw_If_Settings_Are_Null()
public void Should_Ignore_Output_If_Not_Set()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.Settings = null;
fixture.SourceFiles = new List<FilePath> { new ("/Working/result1.dcvr"), new ("/Working/result2.dcvr") };
fixture.OutputFile = null;
// When
var result = fixture.Run();

// Then
Assert.Equal("merge " +
"--snapshot-source \"/Working/result1.dcvr,/Working/result2.dcvr\"", result.Args);
}

[Fact]
public void Should_Set_Correct_Arguments()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.SourceFiles = new List<FilePath> { new ("/Working/result1.dcvr"), new ("/Working/result2.dcvr") };
fixture.OutputFile = new FilePath("/Working/output.dcvr");
// When
var result = fixture.Run();

// Then
Assert.Equal("merge " +
"--snapshot-source \"/Working/result1.dcvr,/Working/result2.dcvr\" " +
"--snapshot-output \"/Working/output.dcvr\"", result.Args);
}

[Fact]
public void Should_Append_TemporaryDirectory()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.Settings.TemporaryDirectory = new DirectoryPath("/Working/temp");

// When
var result = Record.Exception(() => fixture.Run());
var result = fixture.Run();

// Then
AssertEx.IsArgumentNullException(result, "settings");
Assert.Equal("merge " +
"--snapshot-source \"/Working/result1.dcvr,/Working/result2.dcvr\" " +
"--snapshot-output \"/Working/result.dcvr\" " +
"--temporary-directory \"/Working/temp\"", result.Args);
}

[Fact]
public void Should_Not_Append_Null_TemporaryDirectory()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.Settings.TemporaryDirectory = null;

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

// Then
Assert.Equal("merge " +
"--snapshot-source \"/Working/result1.dcvr,/Working/result2.dcvr\" " +
"--snapshot-output \"/Working/result.dcvr\"", result.Args);
}

[Fact]
Expand All @@ -81,27 +132,67 @@ public void Should_Append_LogFile()
var result = fixture.Run();

// Then
Assert.Equal("Merge " +
Assert.Equal("merge " +
"--snapshot-source \"/Working/result1.dcvr,/Working/result2.dcvr\" " +
"--snapshot-output \"/Working/result.dcvr\" " +
"--log-file \"/Working/logfile.log\"", result.Args);
}

#endregion

#region Legacy Parameter Syntax

[Fact]
public void Should_Append_LogFile_LegacySyntax()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.Settings.LogFile = "./logfile.log";
fixture.Settings.UseLegacySyntax = true;

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

// Then
Assert.Equal("merge " +
"/Source=\"/Working/result1.dcvr;/Working/result2.dcvr\" " +
"/Output=\"/Working/result.dcvr\" " +
"/LogFile=\"/Working/logfile.log\"", result.Args);
}

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

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

// Then
Assert.Equal("Merge \"/Working/config.xml\" " +
Assert.Equal("merge \"/Working/config.xml\" " +
"/Source=\"/Working/result1.dcvr;/Working/result2.dcvr\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}

[Fact]
public void Should_Throw_If_Output_File_Is_Null_LegacySyntax()
{
// Given
var fixture = new DotCoverMergerFixture();
fixture.OutputFile = null;
fixture.Settings.UseLegacySyntax = true;

// When
var result = Record.Exception(() => fixture.Run());

// Then
AssertEx.IsArgumentNullException(result, "outputFile");
}

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,135 @@ public void Should_Throw_If_Source_File_Is_Null()
}

[Fact]
public void Should_Throw_If_Output_File_Is_Null()
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
AssertEx.IsArgumentNullException(result, "outputFile");
AssertEx.IsArgumentNullException(result, "settings");
}

#region New Parameter Syntax

[Fact]
public void Should_Throw_If_Settings_Are_Null()
public void Should_Ignore_Output_File_If_Null()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.Settings = null;
fixture.OutputFile = null;

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

// Then
Assert.Equal("report " +
"--snapshot-source \"/Working/result.dcvr\"", result.Args);
}

[Fact]
public void Should_Append_JsonReportOutput()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings.JsonReportOutput = new FilePath("/Working/coverage.json");

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

// Then
Assert.Equal("report " +
"--snapshot-source \"/Working/result.dcvr\" " +
"--json-report-output \"/Working/coverage.json\"", result.Args);
}

[Theory]
[InlineData(DotCoverReportScope.None, "none")]
[InlineData(DotCoverReportScope.Assembly, "assembly")]
[InlineData(DotCoverReportScope.Type, "type")]
[InlineData(DotCoverReportScope.Method, "method")]
[InlineData(DotCoverReportScope.Statement, "statement")]
public void Should_Append_JsonReportScope(DotCoverReportScope reportScope, string reportScopeString)
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings.JsonReportOutput = new FilePath("/Working/coverage.json");
fixture.Settings.JsonReportCoveringTestsScope = reportScope;

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

// Then
Assert.Equal("report " +
"--snapshot-source \"/Working/result.dcvr\" " +
"--json-report-output \"/Working/coverage.json\" " +
"--json-report-covering-tests-scope \"" + reportScopeString + "\"", result.Args);
}

[Fact]
public void Should_Append_XmlReportOutput()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings.XmlReportOutput = new FilePath("/Working/coverage.json");

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

// Then
Assert.Equal("report " +
"--snapshot-source \"/Working/result.dcvr\" " +
"--xml-report-output \"/Working/coverage.json\"", result.Args);
}

[Theory]
[InlineData(DotCoverReportScope.None, "none")]
[InlineData(DotCoverReportScope.Assembly, "assembly")]
[InlineData(DotCoverReportScope.Type, "type")]
[InlineData(DotCoverReportScope.Method, "method")]
[InlineData(DotCoverReportScope.Statement, "statement")]
public void Should_Append_XmlReportScope(DotCoverReportScope reportScope, string reportScopeString)
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings.XmlReportOutput = new FilePath("/Working/coverage.json");
fixture.Settings.XmlReportCoveringTestsScope = reportScope;

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

// Then
Assert.Equal("report " +
"--snapshot-source \"/Working/result.dcvr\" " +
"--xml-report-output \"/Working/coverage.json\" " +
"--xml-report-covering-tests-scope \"" + reportScopeString + "\"", result.Args);
}

#endregion

#region Legacy Parameter Syntax

[Fact]
public void Should_Throw_If_Output_File_Is_Null()
{
// Given
var fixture = new DotCoverReporterFixture();
fixture.OutputFile = null;
fixture.Settings.UseLegacySyntax = true;

// When
var result = Record.Exception(() => fixture.Run());

// Then
AssertEx.IsArgumentNullException(result, "settings");
AssertEx.IsArgumentNullException(result, "outputFile");
}

[Theory]
Expand All @@ -65,12 +169,13 @@ public void Should_Append_ReportType(DotCoverReportType reportType, string repor
// Given
var fixture = new DotCoverReporterFixture();
fixture.Settings.ReportType = reportType;
fixture.Settings.UseLegacySyntax = true;

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

// Then
Assert.Equal("Report " +
Assert.Equal("report " +
"/Source=\"/Working/result.dcvr\" " +
"/Output=\"/Working/result.xml\" " +
"/ReportType=" + reportTypeString, result.Args);
Expand All @@ -82,12 +187,13 @@ public void Should_Append_LogFile()
// Given
var fixture = new DotCoverReporterFixture();
fixture.Settings.LogFile = "./logfile.log";
fixture.Settings.UseLegacySyntax = true;

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

// Then
Assert.Equal("Report " +
Assert.Equal("report " +
"/Source=\"/Working/result.dcvr\" " +
"/Output=\"/Working/result.xml\" " +
"/LogFile=\"/Working/logfile.log\"", result.Args);
Expand All @@ -99,15 +205,18 @@ public void Should_Append_ConfigurationFile()
// Given
var fixture = new DotCoverReporterFixture();
fixture.Settings.WithConfigFile(new FilePath("./config.xml"));
fixture.Settings.UseLegacySyntax = true;

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

// Then
Assert.Equal("Report \"/Working/config.xml\" " +
Assert.Equal("report \"/Working/config.xml\" " +
"/Source=\"/Working/result.dcvr\" " +
"/Output=\"/Working/result.xml\"", result.Args);
}

#endregion
}
}
}
8 changes: 0 additions & 8 deletions src/Cake.Common/Tools/DotCover/Cover/DotCoverCoverSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,5 @@ public sealed class DotCoverCoverSettings : DotCoverCoverageSettings
/// This represents the <c>--no-ngen</c> option.
/// </summary>
public bool NoNGen { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to use the legacy command syntax.
/// When true, uses old format like '/TargetExecutable="/path"'.
/// When false, uses new format like '--target-executable "/path"'.
/// Default is false (new format).
/// </summary>
public bool UseLegacySyntax { get; set; }
}
}
Loading
Loading