Skip to content

Commit

Permalink
Add alias for dotnet sdk check command
Browse files Browse the repository at this point in the history
  • Loading branch information
Marusyk authored and devlead committed Jan 23, 2022
1 parent 6b3191d commit cc628dd
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 Cake.Common.Tools.DotNet.SDKCheck;

namespace Cake.Common.Tests.Fixtures.Tools.DotNet.SDKCheck
{
internal sealed class DotNetSDKCheckerFixture : DotNetFixture<DotNetSDKCheckSettings>
{
protected override void RunTool()
{
var tool = new DotNetSDKChecker(FileSystem, Environment, ProcessRunner, Tools);
tool.Check();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 Cake.Common.Tests.Fixtures.Tools.DotNet.SDKCheck;
using Cake.Testing;
using Xunit;

namespace Cake.Common.Tests.Unit.Tools.DotNet.SDKCheck
{
public sealed class DotNetSDKCheckTests
{
public sealed class TheSDKCheckMethod
{
[Fact]
public void Should_Throw_If_Process_Was_Not_Started()
{
// Given
var fixture = new DotNetSDKCheckerFixture();
fixture.GivenProcessCannotStart();

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

// Then
AssertEx.IsCakeException(result, ".NET CLI: Process was not started.");
}

[Fact]
public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code()
{
// Given
var fixture = new DotNetSDKCheckerFixture();
fixture.GivenProcessExitsWithCode(1);

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

// Then
AssertEx.IsCakeException(result, ".NET CLI: Process returned an error (exit code 1).");
}
}
}
}
24 changes: 24 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Cake.Common.Tools.DotNet.Publish;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
using Cake.Common.Tools.DotNet.SDKCheck;
using Cake.Common.Tools.DotNet.Test;
using Cake.Common.Tools.DotNet.Tool;
using Cake.Common.Tools.DotNet.VSTest;
Expand Down Expand Up @@ -1821,5 +1822,28 @@ public static void DotNetFormatAnalyzers(this ICakeContext context, string root,
var formatter = new DotNetFormatter(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
formatter.Format(root, "analyzers", settings);
}

/// <summary>
/// Lists the latest available version of the .NET SDK and .NET Runtime.
/// </summary>
/// <param name="context">The context.</param>
/// <example>
/// <code>
/// DotNetSDKCheck();
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("SDK")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.SDKCheck")]
public static void DotNetSDKCheck(this ICakeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

var checker = new DotNetSDKChecker(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
checker.Check();
}
}
}
13 changes: 13 additions & 0 deletions src/Cake.Common/Tools/DotNet/SDKCheck/DotNetSDKCheckSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace Cake.Common.Tools.DotNet.SDKCheck
{
/// <summary>
/// Contains settings used by <see cref="DotNetSDKChecker" />.
/// </summary>
public sealed class DotNetSDKCheckSettings : DotNetSettings
{
}
}
52 changes: 52 additions & 0 deletions src/Cake.Common/Tools/DotNet/SDKCheck/DotNetSDKChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 Cake.Core;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.Common.Tools.DotNet.SDKCheck
{
/// <summary>
/// .NET SDK checker.
/// </summary>
public sealed class DotNetSDKChecker : DotNetTool<DotNetSDKCheckSettings>
{
private readonly ICakeEnvironment _environment;

/// <summary>
/// Initializes a new instance of the <see cref="DotNetSDKChecker" /> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="environment">The environment.</param>
/// <param name="processRunner">The process runner.</param>
/// <param name="tools">The tool locator.</param>
public DotNetSDKChecker(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools) : base(fileSystem, environment, processRunner, tools)
{
_environment = environment;
}

/// <summary>
/// Lists the latest available version of the .NET SDK and .NET Runtime, for each feature band.
/// </summary>
public void Check()
{
var settings = new DotNetSDKCheckSettings();
RunCommand(settings, GetArguments(settings));
}

private ProcessArgumentBuilder GetArguments(DotNetSDKCheckSettings settings)
{
var builder = CreateArgumentBuilder(settings);

builder.Append("sdk check");

return builder;
}
}
}
9 changes: 9 additions & 0 deletions tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetFormat")
DotNetFormat(project.FullPath);
});

Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetSDKCheck")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.Setup")
.Does(() =>
{
// When
DotNetSDKCheck();
});

Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuildServerShutdown")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetRestore")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuild")
Expand All @@ -270,6 +278,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuildServerShutdown")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetMSBuild")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetTest.Fail")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetFormat")
.IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetSDKCheck")
.Does(() =>
{
// When
Expand Down

0 comments on commit cc628dd

Please sign in to comment.