add dotnet pack unit tests
This commit is contained in:
parent
06ceb66089
commit
584b4a93c0
2 changed files with 71 additions and 26 deletions
|
@ -5,12 +5,21 @@ using System.Collections.Generic;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.MSBuild;
|
using Microsoft.DotNet.Tools.MSBuild;
|
||||||
|
using Microsoft.DotNet.Cli;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Pack
|
namespace Microsoft.DotNet.Tools.Pack
|
||||||
{
|
{
|
||||||
public class PackCommand
|
public class PackCommand
|
||||||
{
|
{
|
||||||
public static int Run(string[] args)
|
private MSBuildForwardingApp _forwardingApp;
|
||||||
|
|
||||||
|
public PackCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
||||||
|
{
|
||||||
|
_forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PackCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
|
@ -59,9 +68,10 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
multipleValues:true);
|
multipleValues:true);
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
||||||
|
|
||||||
|
List<string> msbuildArgs = null;
|
||||||
cmd.OnExecute(() =>
|
cmd.OnExecute(() =>
|
||||||
{
|
{
|
||||||
var msbuildArgs = new List<string>()
|
msbuildArgs = new List<string>()
|
||||||
{
|
{
|
||||||
"/t:pack"
|
"/t:pack"
|
||||||
};
|
};
|
||||||
|
@ -109,10 +119,43 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
msbuildArgs.AddRange(argRoot.Values);
|
msbuildArgs.AddRange(argRoot.Values);
|
||||||
|
|
||||||
msbuildArgs.AddRange(cmd.RemainingArguments);
|
msbuildArgs.AddRange(cmd.RemainingArguments);
|
||||||
return new MSBuildForwardingApp(msbuildArgs).Execute();
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
return cmd.Execute(args);
|
int exitCode = cmd.Execute(args);
|
||||||
|
if (msbuildArgs == null)
|
||||||
|
{
|
||||||
|
throw new CommandCreationException(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PackCommand(msbuildArgs, msbuildPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Run(string[] args)
|
||||||
|
{
|
||||||
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
|
PackCommand 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,37 @@
|
||||||
using Microsoft.DotNet.Tools.Build;
|
using Microsoft.DotNet.Tools.Pack;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
||||||
{
|
{
|
||||||
public class GivenDotnetPackInvocation
|
public class GivenDotnetPackInvocation
|
||||||
{
|
{
|
||||||
[Theory(Skip = "finish me")]
|
const string ExpectedPrefix = "exec <msbuildpath> /m /v:m /t:pack";
|
||||||
[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")]
|
[Theory]
|
||||||
[InlineData(new string[] { "--output", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
[InlineData(new string[] { }, "")]
|
||||||
[InlineData(new string[] { "-o", "foo1 foo2" }, @"exec <msbuildpath> /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")]
|
[InlineData(new string[] { "-o", "<output>" }, "/p:PackageOutputPath=<output>")]
|
||||||
[InlineData(new string[] { "--no-incremental" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /clp:Summary")]
|
[InlineData(new string[] { "--output", "<output>" }, "/p:PackageOutputPath=<output>")]
|
||||||
[InlineData(new string[] { "-f", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
[InlineData(new string[] { "--no-build" }, "/p:NoBuild=true")]
|
||||||
[InlineData(new string[] { "--framework", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
[InlineData(new string[] { "--include-symbols" }, "/p:IncludeSymbols=true")]
|
||||||
[InlineData(new string[] { "-r", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
[InlineData(new string[] { "--include-source" }, "/p:IncludeSource=true")]
|
||||||
[InlineData(new string[] { "--runtime", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
[InlineData(new string[] { "-c", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||||
[InlineData(new string[] { "-c", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
[InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")]
|
||||||
[InlineData(new string[] { "--configuration", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
[InlineData(new string[] { "--version-suffix", "<version-suffix>" }, "/p:VersionSuffix=<version-suffix>")]
|
||||||
[InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec <msbuildpath> /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")]
|
[InlineData(new string[] { "-s" }, "/p:Serviceable=true")]
|
||||||
[InlineData(new string[] { "--no-dependencies" }, @"exec <msbuildpath> /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")]
|
[InlineData(new string[] { "--serviceable" }, "/p:Serviceable=true")]
|
||||||
[InlineData(new string[] { "-v", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
[InlineData(new string[] { "-v", "<verbosity>" }, @"/verbosity:<verbosity>")]
|
||||||
[InlineData(new string[] { "--verbosity", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
[InlineData(new string[] { "--verbosity", "<verbosity>" }, @"/verbosity:<verbosity>")]
|
||||||
[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")]
|
[InlineData(new string[] { "<project>" }, "<project>")]
|
||||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
|
||||||
{
|
{
|
||||||
|
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
|
||||||
|
|
||||||
var msbuildPath = "<msbuildpath>";
|
var msbuildPath = "<msbuildpath>";
|
||||||
BuildCommand.FromArgs(args, msbuildPath)
|
PackCommand.FromArgs(args, msbuildPath)
|
||||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue