add dotnet clean unit tests
This commit is contained in:
parent
b85a2ec6f2
commit
eddca32b2f
3 changed files with 96 additions and 44 deletions
|
@ -5,12 +5,21 @@ using System.Collections.Generic;
|
|||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Clean
|
||||
{
|
||||
public class CleanCommand
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
private MSBuildForwardingApp _forwardingApp;
|
||||
|
||||
public CleanCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||
{
|
||||
_forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
||||
}
|
||||
|
||||
public static CleanCommand FromArgs(string[] args, string msbuildPath = null)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
|
@ -42,9 +51,10 @@ namespace Microsoft.DotNet.Tools.Clean
|
|||
CommandOptionType.SingleValue);
|
||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
||||
|
||||
List<string> msbuildArgs = null;
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
List<string> msbuildArgs = new List<string>();
|
||||
msbuildArgs = new List<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(projectArgument.Value))
|
||||
{
|
||||
|
@ -75,10 +85,43 @@ namespace Microsoft.DotNet.Tools.Clean
|
|||
|
||||
msbuildArgs.AddRange(app.RemainingArguments);
|
||||
|
||||
return new MSBuildForwardingApp(msbuildArgs).Execute();
|
||||
return 0;
|
||||
});
|
||||
|
||||
return app.Execute(args);
|
||||
int exitCode = app.Execute(args);
|
||||
if (msbuildArgs == null)
|
||||
{
|
||||
throw new CommandCreationException(exitCode);
|
||||
}
|
||||
|
||||
return new CleanCommand(msbuildArgs, msbuildPath);
|
||||
}
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
CleanCommand cmd;
|
||||
try
|
||||
{
|
||||
cmd = FromArgs(args);
|
||||
}
|
||||
catch (CommandCreationException e)
|
||||
{
|
||||
return e.ExitCode;
|
||||
}
|
||||
|
||||
return cmd.Execute();
|
||||
}
|
||||
|
||||
public ProcessStartInfo GetProcessStartInfo()
|
||||
{
|
||||
return _forwardingApp.GetProcessStartInfo();
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
{
|
||||
return GetProcessStartInfo().Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,28 +6,33 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|||
{
|
||||
public class GivenDotnetBuildInvocation
|
||||
{
|
||||
const string ExpectedPrefix = "exec <msbuildpath> /m /v:m";
|
||||
const string ExpectedSuffix = "/clp:Summary";
|
||||
|
||||
[Theory]
|
||||
[InlineData(new string[] { }, @"exec <msbuildpath> /m /v:m /t:Build /clp:Summary")]
|
||||
[InlineData(new string[] { "-o", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
||||
[InlineData(new string[] { "--output", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
||||
[InlineData(new string[] { "-o", "foo1 foo2" }, @"exec <msbuildpath> /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-incremental" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /clp:Summary")]
|
||||
[InlineData(new string[] { "-f", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
||||
[InlineData(new string[] { "--framework", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
||||
[InlineData(new string[] { "-r", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
||||
[InlineData(new string[] { "--runtime", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
||||
[InlineData(new string[] { "-c", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
||||
[InlineData(new string[] { "--configuration", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
||||
[InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec <msbuildpath> /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-dependencies" }, @"exec <msbuildpath> /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")]
|
||||
[InlineData(new string[] { "-v", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--verbosity", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")]
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
||||
[InlineData(new string[] { }, "/t:Build")]
|
||||
[InlineData(new string[] { "-o", "foo" }, "/t:Build /p:OutputPath=foo")]
|
||||
[InlineData(new string[] { "--output", "foo" }, "/t:Build /p:OutputPath=foo")]
|
||||
[InlineData(new string[] { "-o", "foo1 foo2" }, "/t:Build \"/p:OutputPath=foo1 foo2\"")]
|
||||
[InlineData(new string[] { "--no-incremental" }, "/t:Rebuild")]
|
||||
[InlineData(new string[] { "-f", "framework" }, "/t:Build /p:TargetFramework=framework")]
|
||||
[InlineData(new string[] { "--framework", "framework" }, "/t:Build /p:TargetFramework=framework")]
|
||||
[InlineData(new string[] { "-r", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")]
|
||||
[InlineData(new string[] { "--runtime", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")]
|
||||
[InlineData(new string[] { "-c", "configuration" }, "/t:Build /p:Configuration=configuration")]
|
||||
[InlineData(new string[] { "--configuration", "configuration" }, "/t:Build /p:Configuration=configuration")]
|
||||
[InlineData(new string[] { "--version-suffix", "mysuffix" }, "/t:Build /p:VersionSuffix=mysuffix")]
|
||||
[InlineData(new string[] { "--no-dependencies" }, "/t:Build /p:BuildProjectReferences=false")]
|
||||
[InlineData(new string[] { "-v", "verbosity" }, "/t:Build /verbosity:verbosity")]
|
||||
[InlineData(new string[] { "--verbosity", "verbosity" }, "/t:Build /verbosity:verbosity")]
|
||||
[InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, "/t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag")]
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
|
||||
{
|
||||
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
|
||||
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
||||
.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs} {ExpectedSuffix}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Microsoft.DotNet.Tools.Build;
|
||||
using Microsoft.DotNet.Tools.Clean;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using System;
|
||||
|
@ -7,29 +7,33 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|||
{
|
||||
public class GivenDotnetCleanInvocation
|
||||
{
|
||||
[Theory(Skip = "finish me")]
|
||||
[InlineData(new string[] { }, @"exec <msbuildpath> /m /v:m /t:Build /clp:Summary")]
|
||||
[InlineData(new string[] { "-o", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
||||
[InlineData(new string[] { "--output", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
||||
[InlineData(new string[] { "-o", "foo1 foo2" }, @"exec <msbuildpath> /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-incremental" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /clp:Summary")]
|
||||
[InlineData(new string[] { "-f", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
||||
[InlineData(new string[] { "--framework", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
||||
[InlineData(new string[] { "-r", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
||||
[InlineData(new string[] { "--runtime", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
||||
[InlineData(new string[] { "-c", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
||||
[InlineData(new string[] { "--configuration", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
||||
[InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec <msbuildpath> /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-dependencies" }, @"exec <msbuildpath> /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")]
|
||||
[InlineData(new string[] { "-v", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--verbosity", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")]
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
||||
const string ExpectedPrefix = "exec <msbuildpath> /m /v:m /t:Clean";
|
||||
|
||||
[Fact]
|
||||
public void ItAddsProjectToMsbuildInvocation()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
||||
throw new NotImplementedException();
|
||||
CleanCommand.FromArgs(new string[] { "<project>" }, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be("exec <msbuildpath> /m /v:m <project> /t:Clean");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new string[] { }, "")]
|
||||
[InlineData(new string[] { "-o", "<output>" }, "/p:OutputPath=<output>")]
|
||||
[InlineData(new string[] { "--output", "<output>" }, "/p:OutputPath=<output>")]
|
||||
[InlineData(new string[] { "-f", "<framework>" }, "/p:TargetFramework=<framework>")]
|
||||
[InlineData(new string[] { "--framework", "<framework>" }, "/p:TargetFramework=<framework>")]
|
||||
[InlineData(new string[] { "-c", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||
[InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||
[InlineData(new string[] { "-v", "<verbosity>" }, "/verbosity:<verbosity>")]
|
||||
[InlineData(new string[] { "--verbosity", "<verbosity>" }, "/verbosity:<verbosity>")]
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
|
||||
{
|
||||
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
|
||||
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
CleanCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue