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

Added DotCover Cover command #713

Merged
merged 1 commit into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/Cake.Common.Tests/Cake.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="Fixtures\Tools\DNU\Pack\DNUPackerFixture.cs" />
<Compile Include="Fixtures\Tools\DNU\Restorer\DNURestorerFixture.cs" />
<Compile Include="Fixtures\Tools\DotCover\Analyse\DotCoverAnalyserFixture.cs" />
<Compile Include="Fixtures\Tools\DotCover\Cover\DotCoverCovererFixture.cs" />
<Compile Include="Fixtures\Tools\DotCover\DotCoverFixture.cs" />
<Compile Include="Fixtures\Tools\DupFinder\DupFinderRunnerConfigFixture.cs" />
<Compile Include="Fixtures\Tools\DupFinder\DupFinderRunnerFixture.cs" />
Expand Down Expand Up @@ -209,6 +210,7 @@
<Compile Include="Unit\Tools\DNU\Restore\DNURestorerTests.cs" />
<Compile Include="Unit\Tools\DotCover\Analyse\DotCoverAnalyserTests.cs" />
<Compile Include="Unit\Tools\DotCover\Analyse\DotCoverAnalyseSettingsTests.cs" />
<Compile Include="Unit\Tools\DotCover\Cover\DotCoverCovererTests.cs" />
<Compile Include="Unit\Tools\DupFinder\DupFinderRunnerTests.cs" />
<Compile Include="Unit\Tools\Fixie\FixieRunnerTests.cs" />
<Compile Include="Unit\Tools\GitLink\GitlinkRunnerTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cake.Common.Tools.DNU.Build;
using Cake.Common.Tools.DotCover.Analyse;
using Cake.Core;
using Cake.Core.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cake.Common.Tools.DotCover.Cover;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using NSubstitute;

namespace Cake.Common.Tests.Fixtures.Tools.DotCover.Cover
{
internal sealed class DotCoverCovererFixture : DotCoverFixture<DotCoverCoverSettings>
{
public ICakeContext Context { get; set; }
public Action<ICakeContext> Action { get; set; }
public FilePath OutputPath { get; set; }

public DotCoverCovererFixture()
{
// Set the output file.
OutputPath = new FilePath("./result.dcvr");

// Setup the Cake Context.
Context = Substitute.For<ICakeContext>();
Context.FileSystem.Returns(FileSystem);
Context.Arguments.Returns(Substitute.For<ICakeArguments>());
Context.Environment.Returns(Environment);
Context.Globber.Returns(Globber);
Context.Log.Returns(Substitute.For<ICakeLog>());
Context.Registry.Returns(Substitute.For<IRegistry>());
Context.ProcessRunner.Returns((IProcessRunner)null);

// Set up the default action that intercepts.
Action = context =>
{
context.ProcessRunner.Start(
new FilePath("/Working/tools/Test.exe"),
new ProcessSettings()
{
Arguments = "-argument"
});
};
}

protected override void RunTool()
{
var tool = new DotCoverCoverer(FileSystem, Environment, ProcessRunner, Globber);
tool.Cover(Context, Action, OutputPath, Settings);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cake.Common.Tests.Fixtures.Tools.DotCover;
using Cake.Common.Tests.Fixtures.Tools.DotCover.Cover;
using Cake.Common.Tools.DotCover;
using Cake.Common.Tools.DotCover.Cover;
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.Cover
{
public sealed class DotCoverCovererTests
{
public sealed class TheCoverMethod
{
[Fact]
public void Should_Throw_If_Context_Is_Null()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Context = null;

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

// Then
Assert.IsArgumentNullException(result, "context");
}

[Fact]
public void Should_Throw_If_Action_Is_Null()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Action = null;

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

// Then
Assert.IsArgumentNullException(result, "action");

}

[Fact]
public void Should_Throw_If_Output_File_Is_Null()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.OutputPath = null;

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

// Then
Assert.IsArgumentNullException(result, "outputPath");
}

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

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

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

[Fact]
public void Should_Throw_If_No_Tool_Was_Intercepted()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Action = context => { };

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

// Then
Assert.IsCakeException(result, "No tool was started.");
}

[Fact]
public void Should_Capture_Tool_And_Arguments_From_Action()
{
// Given
var fixture = new DotCoverCovererFixture();

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}

[Theory]
[InlineData("")]
[InlineData(null)]
public void Should_Not_Capture_Arguments_From_Action_If_Excluded(string arguments)
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Action = context =>
{
context.ProcessRunner.Start(
new FilePath("/Working/tools/Test.exe"),
new ProcessSettings()
{
Arguments = arguments
});
};

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}

[Fact]
public void Should_Append_TargetWorkingDir()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.TargetWorkingDir = new DirectoryPath("/Working");

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\" " +
"/TargetWorkingDir=\"/Working\"", result.Args);
}

[Fact]
public void Should_Append_Scope()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.WithScope("/Working/*.dll")
.WithScope("/Some/**/Other/*.dll");

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\" " +
"/Scope=\"/Working/*.dll;/Some/**/Other/*.dll\"", result.Args);
}

[Fact]
public void Should_Append_Filters()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.WithFilter("+:module=Test.*")
.WithFilter("-:myassembly");

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\" " +
"/Filters=\"+:module=Test.*;-:myassembly\"", result.Args);
}

[Fact]
public void Should_Append_AttributeFilters()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.WithAttributeFilter("filter1")
.WithAttributeFilter("filter2");

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\" " +
"/AttributeFilters=\"filter1;filter2\"", result.Args);
}

[Fact]
public void Should_Append_DisableDefaultFilters()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.Settings.DisableDefaultFilters = true;

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " +
"/TargetArguments=\"-argument\" " +
"/Output=\"/Working/result.dcvr\" " +
"/DisableDefaultFilters", result.Args);
}

[Fact]
public void Should_Capture_XUnit()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.FileSystem.CreateFile("/Working/tools/xunit.console.exe");
fixture.Action = context =>
{
context.XUnit2(
new FilePath[] { "./Test.dll" },
new XUnit2Settings { ShadowCopy = false });
};

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/xunit.console.exe\" " +
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}

[Fact]
public void Should_Capture_NUnit()
{
// Given
var fixture = new DotCoverCovererFixture();
fixture.FileSystem.CreateFile("/Working/tools/nunit-console.exe");
fixture.Action = context =>
{
context.NUnit(
new FilePath[] { "./Test.dll" },
new NUnitSettings { ShadowCopy = false });
};

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

// Then
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/nunit-console.exe\" " +
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " +
"/Output=\"/Working/result.dcvr\"", result.Args);
}
}
}
}
5 changes: 4 additions & 1 deletion src/Cake.Common/Cake.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,15 @@
<Compile Include="Tools\DNU\Restore\DNURestorer.cs" />
<Compile Include="Tools\DNU\Restore\DNURestoreSettings.cs" />
<Compile Include="Tools\DotCover\Analyse\DotCoverAnalyseSettings.cs" />
<Compile Include="Tools\DotCover\Analyse\DotCoverAnalyseSettingsExtensions.cs" />
<Compile Include="Tools\DotCover\Analyse\DotCoverAnalyser.cs" />
<Compile Include="Tools\DotCover\Cover\DotCoverCoverSettings.cs" />
<Compile Include="Tools\DotCover\Cover\DotCoverCoverer.cs" />
<Compile Include="Tools\DotCover\DotCoverReportType.cs" />
<Compile Include="Tools\DotCover\DotCoverContext.cs" />
<Compile Include="Tools\DotCover\DotCoverProcessRunner.cs" />
<Compile Include="Tools\DotCover\DotCoverAliases.cs" />
<Compile Include="Tools\DotCover\DotCoverSettings.cs" />
<Compile Include="Tools\DotCover\DotCoverSettingsExtensions.cs" />
<Compile Include="Tools\DotCover\DotCoverTool.cs" />
<Compile Include="Tools\DupFinder\DupFinderAliases.cs" />
<Compile Include="Tools\DupFinder\DupFinderRunner.cs" />
Expand Down
Loading