add dotnet-publish unit tests
This commit is contained in:
parent
584b4a93c0
commit
1514dd5e16
3 changed files with 74 additions and 32 deletions
|
@ -1,15 +1,17 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Publish
|
||||
{
|
||||
public partial class PublishCommand
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
public static PublishCommand FromArgs(string[] args, string msbuildPath = null)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
|
@ -50,10 +52,11 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
||||
|
||||
var publish = new PublishCommand(msbuildPath);
|
||||
bool commandExecuted = false;
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
var publish = new PublishCommand();
|
||||
|
||||
commandExecuted = true;
|
||||
publish.ProjectPath = projectArgument.Value;
|
||||
publish.Framework = frameworkOption.Value();
|
||||
publish.Runtime = runtimeOption.Value();
|
||||
|
@ -64,10 +67,43 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
publish.Verbosity = verbosityOption.Value();
|
||||
publish.ExtraMSBuildArguments = app.RemainingArguments;
|
||||
|
||||
return publish.Execute();
|
||||
return 0;
|
||||
});
|
||||
|
||||
return app.Execute(args);
|
||||
int exitCode = app.Execute(args);
|
||||
if (!commandExecuted)
|
||||
{
|
||||
throw new CommandCreationException(exitCode);
|
||||
}
|
||||
|
||||
return publish;
|
||||
}
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
PublishCommand cmd;
|
||||
try
|
||||
{
|
||||
cmd = FromArgs(args);
|
||||
}
|
||||
catch (CommandCreationException e)
|
||||
{
|
||||
return e.ExitCode;
|
||||
}
|
||||
|
||||
return cmd.Execute();
|
||||
}
|
||||
|
||||
public ProcessStartInfo GetProcessStartInfo()
|
||||
{
|
||||
return CreateForwardingApp(_msbuildPath).GetProcessStartInfo();
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
{
|
||||
return GetProcessStartInfo().Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
{
|
||||
public partial class PublishCommand
|
||||
{
|
||||
private string _msbuildPath;
|
||||
|
||||
public string ProjectPath { get; set; }
|
||||
public string Framework { get; set; }
|
||||
public string Runtime { get; set; }
|
||||
|
@ -22,21 +24,22 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
public List<string> ExtraMSBuildArguments { get; set; }
|
||||
|
||||
private PublishCommand()
|
||||
private PublishCommand(string msbuildPath = null)
|
||||
{
|
||||
_msbuildPath = msbuildPath;
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
private MSBuildForwardingApp CreateForwardingApp(string msbuildPath)
|
||||
{
|
||||
List<string> msbuildArgs = new List<string>();
|
||||
|
||||
msbuildArgs.Add("/t:Publish");
|
||||
|
||||
if (!string.IsNullOrEmpty(ProjectPath))
|
||||
{
|
||||
msbuildArgs.Add(ProjectPath);
|
||||
}
|
||||
|
||||
msbuildArgs.Add("/t:Publish");
|
||||
|
||||
if (!string.IsNullOrEmpty(Framework))
|
||||
{
|
||||
msbuildArgs.Add($"/p:TargetFramework={Framework}");
|
||||
|
@ -74,7 +77,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
msbuildArgs.AddRange(ExtraMSBuildArguments);
|
||||
|
||||
return new MSBuildForwardingApp(msbuildArgs).Execute();
|
||||
return new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,38 @@
|
|||
using Microsoft.DotNet.Tools.Build;
|
||||
using Microsoft.DotNet.Tools.Publish;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
||||
{
|
||||
public class GivenDotnetPublishInvocation
|
||||
{
|
||||
[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:Publish";
|
||||
|
||||
[Theory]
|
||||
[InlineData(new string[] { }, "")]
|
||||
[InlineData(new string[] { "-f", "<framework>" }, "/p:TargetFramework=<framework>")]
|
||||
[InlineData(new string[] { "--framework", "<framework>" }, "/p:TargetFramework=<framework>")]
|
||||
[InlineData(new string[] { "-r", "<runtime>" }, "/p:RuntimeIdentifier=<runtime>")]
|
||||
[InlineData(new string[] { "--runtime", "<runtime>" }, "/p:RuntimeIdentifier=<runtime>")]
|
||||
[InlineData(new string[] { "-o", "<output>" }, "/p:PublishDir=<output>")]
|
||||
[InlineData(new string[] { "--output", "<output>" }, "/p:PublishDir=<output>")]
|
||||
[InlineData(new string[] { "-c", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||
[InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||
[InlineData(new string[] { "--version-suffix", "<version-suffix>" }, "/p:VersionSuffix=<version-suffix>")]
|
||||
[InlineData(new string[] { "--filter", "<filter>" }, "/p:FilterProjFile=<filter>")]
|
||||
[InlineData(new string[] { "-v", "<verbosity>" }, "/verbosity:<verbosity>")]
|
||||
[InlineData(new string[] { "--verbosity", "<verbosity>" }, "/verbosity:<verbosity>")]
|
||||
[InlineData(new string[] { "<project>" }, "<project>")]
|
||||
[InlineData(new string[] { "<project>", "<extra-args>" }, "<project> <extra-args>")]
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
|
||||
{
|
||||
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
|
||||
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
||||
throw new NotImplementedException();
|
||||
PublishCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue