Test Changes to work with new Argument Escaping and Command Infra

This commit is contained in:
Bryan 2016-01-22 14:05:02 -08:00 committed by Bryan Thornbury
parent 8d0fada156
commit 37445f053d
18 changed files with 93 additions and 45 deletions

View file

@ -3,6 +3,7 @@
using Microsoft.DotNet.Cli.Utils;
using System;
using System.Diagnostics;
namespace Microsoft.DotNet.Tools.Test.Utilities
@ -19,23 +20,69 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
public virtual CommandResult Execute(string args = "")
{
Console.WriteLine($"Executing - {_command} {args}");
var commandResult = Command.Create(_command, args)
.ForwardStdErr()
.ForwardStdOut()
.Execute();
return commandResult;
var commandPath = Env.GetCommandPath(_command) ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command);
var stdOut = new StreamForwarder();
var stdErr = new StreamForwarder();
stdOut.ForwardTo(write: Reporter.Output.Write, writeLine: Reporter.Output.WriteLine);
stdErr.ForwardTo(write: Reporter.Error.Write, writeLine: Reporter.Output.WriteLine);
return RunProcess(commandPath, args, stdOut, stdErr);
}
public virtual CommandResult ExecuteWithCapturedOutput(string args = "")
{
Console.WriteLine($"Executing (Captured Output) - {_command} {args}");
var commandResult = Command.Create(_command, args)
.CaptureStdErr()
.CaptureStdOut()
.Execute();
return commandResult;
var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
Console.Write("command");
Console.WriteLine(commandPath);
var stdOut = new StreamForwarder();
var stdErr = new StreamForwarder();
stdOut.Capture();
stdErr.Capture();
return RunProcess(commandPath, args, stdOut, stdErr);
}
private CommandResult RunProcess(string executable, string args, StreamForwarder stdOut, StreamForwarder stdErr)
{
var psi = new ProcessStartInfo
{
FileName = executable,
Arguments = args,
RedirectStandardError = true,
RedirectStandardOutput = true
};
var process = new Process
{
StartInfo = psi
};
process.EnableRaisingEvents = true;
process.Start();
var threadOut = stdOut.BeginRead(process.StandardOutput);
var threadErr = stdErr.BeginRead(process.StandardError);
process.WaitForExit();
threadOut.Join();
threadErr.Join();
var result = new CommandResult(
process.ExitCode,
stdOut.GetCapturedOutput(),
stdErr.GetCapturedOutput());
return result;
}
}
}