unit tests for dotnet-cache invocation, some cleanup

This commit is contained in:
Krzysztof Wicher 2017-02-22 15:49:39 -08:00
parent 3415a79940
commit b85a2ec6f2
10 changed files with 89 additions and 241 deletions

View file

@ -5,12 +5,14 @@ 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.Cache
{
public partial class CacheCommand
{
public static int Run(string[] args)
public static CacheCommand FromArgs(string[] args, string msbuildPath = null)
{
DebugHelper.HandleDebugSwitch(ref args);
@ -56,10 +58,11 @@ namespace Microsoft.DotNet.Tools.Cache
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
var cache = new CacheCommand(msbuildPath);
bool commandExecuted = false;
app.OnExecute(() =>
{
var cache = new CacheCommand();
commandExecuted = true;
cache.Framework = frameworkOption.Value();
cache.Runtime = runtimeOption.Value();
cache.OutputPath = outputOption.Value();
@ -71,10 +74,43 @@ namespace Microsoft.DotNet.Tools.Cache
cache.ExtraMSBuildArguments = app.RemainingArguments;
cache.ProjectArgument = projectArgument.Value();
return cache.Execute();
return 0;
});
return app.Execute(args);
int exitCode = app.Execute(args);
if (!commandExecuted)
{
throw new CommandCreationException(exitCode);
}
return cache;
}
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
CacheCommand 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();
}
}
}