forked from cake-build/cake
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cake-buildGH-619) Added GitLink Support with Tests
- Loading branch information
Showing
7 changed files
with
561 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using Cake.Testing.Fixtures; | ||
using NSubstitute; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools | ||
{ | ||
using Cake.Common.Tools.GitLink; | ||
internal sealed class GitLinkFixture : ToolFixture<GitLinkSettings> | ||
{ | ||
private readonly ICakeLog Log; | ||
|
||
public DirectoryPath SolutionPath { get; set; } | ||
|
||
public GitLinkFixture() | ||
: base("gitlink.exe") | ||
{ | ||
SolutionPath = new DirectoryPath("c:/temp"); | ||
|
||
Log = Substitute.For<ICakeLog>(); | ||
} | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new GitLinkRunner(FileSystem, Environment, ProcessRunner, Globber, Log); | ||
tool.Run(SolutionPath, Settings); | ||
} | ||
} | ||
} |
241 changes: 241 additions & 0 deletions
241
src/Cake.Common.Tests/Unit/Tools/GitLink/GitlinkRunnerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
using Cake.Common.Tests.Fixtures.Tools; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.GitLink | ||
{ | ||
using System; | ||
|
||
public sealed class GitlinkRunnerTests | ||
{ | ||
public sealed class TheRunMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_SolutionPath_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.SolutionPath = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "solutionPath"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Find_GitLink_Runner() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("/Working/tools/gitlink.exe", result.Path.FullPath); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.GivenProcessCannotStart(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsType<CakeException>(result); | ||
Assert.Equal("GitLink: Process was not started.", result.Message); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Has_A_Non_Zero_Exit_Code() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.GivenProcessExitsWithCode(1); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsType<CakeException>(result); | ||
Assert.Equal("GitLink: Process returned an error.", result.Message); | ||
} | ||
|
||
[Fact] | ||
public void Should_Use_Provided_SolutionPath_In_Process_Arguments() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.SolutionPath = "source"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"/Working/source\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_RepositoryUrl() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.RepositoryUrl = new Uri("http://mydomain.com"); | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -u \"http://mydomain.com/\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_SolutionFileName() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.SolutionFileName = "solution.sln"; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -f \"solution.sln\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Configuration() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.Configuration = "Release"; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -c \"Release\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Platform() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.Platform = "AnyCPU"; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -p \"AnyCPU\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Branch() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.Branch = "master"; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -b \"master\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_LogFilePath() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.LogFilePath = @"/temp/log.txt"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -l \"/temp/log.txt\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_ShaHash() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.ShaHash = "abcdef"; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -s \"abcdef\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_PdbDirectory() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.PdbDirectoryPath = DirectoryPath.FromString("pdb/"); | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -d \"/Working/pdb\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_PowerShell_Switch() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.UsePowerShellCommand = true; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -powershell", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_SkipVerify_Switch() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.SkipVerify = true; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -skipverify", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Debug_Switch() | ||
{ | ||
// Given | ||
var fixture = new GitLinkFixture(); | ||
fixture.Settings.Debug = true; | ||
|
||
// Then | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("\"c:/temp\" -debug", result.Args); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Common.Tools.GitLink | ||
{ | ||
/// <summary> | ||
/// Contains functionality for working with GitLink. | ||
/// </summary> | ||
[CakeAliasCategory("GitTools")] | ||
public static class GitLinkAliases | ||
{ | ||
/// <summary> | ||
/// Update pdb files to link all sources. | ||
/// This will allow anyone to step through the source code while debugging without a symbol source server. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="solutionPath">The Solution File to analyze.</param> | ||
/// <example> | ||
/// <code> | ||
/// GitLink("C:/temp/solution"); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("GitLink")] | ||
public static void GitLink(this ICakeContext context, DirectoryPath solutionPath) | ||
{ | ||
GitLink(context, solutionPath, new GitLinkSettings()); | ||
} | ||
|
||
/// <summary> | ||
/// Update pdb files to link all sources, using specified settings. | ||
/// This will allow anyone to step through the source code while debugging without a symbol source server. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="solutionPath">The Solution File to analyze.</param> | ||
/// <param name="settings">The settings.</param> | ||
/// <example> | ||
/// <code> | ||
/// GitLink("C:/temp/solution", new GitLinkSettings { | ||
/// RepositoryUrl = new Uri("http://mydomain.com"), | ||
/// Branch = "master", | ||
/// ShaHash = "abcdef", | ||
/// }); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("GitLink")] | ||
public static void GitLink(this ICakeContext context, DirectoryPath solutionPath, GitLinkSettings settings) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException("context"); | ||
} | ||
|
||
var runner = new GitLinkRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Globber, context.Log); | ||
runner.Run(solutionPath, settings); | ||
} | ||
} | ||
} |
Oops, something went wrong.