private static CommandResult ExecuteMiniCover(string minicoverDirectory, string command, string parameter) { StreamForwarder stdOut = new StreamForwarder(); StreamForwarder stdError = new StreamForwarder(); ProcessStartInfo processStartInfo = new ProcessStartInfo("dotnet", $"minicover {command} {parameter}") { WorkingDirectory = minicoverDirectory, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }; stdOut.Capture(); stdError.Capture(); var process = new Process { StartInfo = processStartInfo }; process.Start(); var threadOut = stdOut.BeginRead(process.StandardOutput); var threadErr = stdError.BeginRead(process.StandardError); process.WaitForExit(); threadOut.Wait(); threadErr.Wait(); process.HasExited.ShouldBe(true); return(new CommandResult(processStartInfo, process.ExitCode, stdOut.CapturedOutput, stdError.CapturedOutput)); }
public virtual CommandResult ExecuteWithCapturedOutput(string args = "") { Console.WriteLine($"Executing (Captured Output) - {_command} {args}"); var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ?? Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", ""); var stdOut = new StreamForwarder(); var stdErr = new StreamForwarder(); stdOut.Capture(); stdErr.Capture(); return(RunProcess(commandPath, args, stdOut, stdErr)); }
public virtual CommandResult ExecuteWithCapturedOutput(params string[] args) { var command = _command; ResolveCommand(ref command); var commandPath = Env.GetCommandPath(command, ".exe", ".cmd", string.Empty) ?? Env.GetCommandPathFromRootPath(AppContext.BaseDirectory, command, ".exe", ".cmd", string.Empty); var stdOut = new StreamForwarder(); var stdErr = new StreamForwarder(); stdOut.Capture(); stdErr.Capture(); return(RunProcess(commandPath, args, stdOut, stdErr)); }
public virtual CommandResult ExecuteWithCapturedOutput(string args = "") { var command = _command; ResolveCommand(ref command, ref args); var commandPath = Env.GetCommandPath(command, ".exe", ".cmd", "") ?? Env.GetCommandPathFromRootPath(_baseDirectory, command, ".exe", ".cmd", ""); Console.WriteLine($"Executing (Captured Output) - {commandPath} {args}"); var stdOut = new StreamForwarder(); var stdErr = new StreamForwarder(); stdOut.Capture(); stdErr.Capture(); return(RunProcess(commandPath, args, stdOut, stdErr)); }
private static void Forward(int bufferSize, ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites) { var forwarder = new StreamForwarder(bufferSize); var writes = new List <string>(); if ((options & ForwardOptions.WriteLine) != 0) { forwarder.ForwardTo( write: (options & ForwardOptions.Write) == 0 ? (Action <string>)null : writes.Add, writeLine: s => writes.Add(s + "\n")); } if ((options & ForwardOptions.Capture) != 0) { forwarder.Capture(); } forwarder.Read(new StringReader(str)); Assert.Equal(expectedWrites, writes); var captured = forwarder.GetCapturedOutput(); Assert.Equal(expectedCaptured, captured); }
private void TestCapturingAndForwardingHelper(ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites) { var forwarder = new StreamForwarder(); var writes = new List <string>(); if ((options & ForwardOptions.WriteLine) != 0) { forwarder.ForwardTo(writeLine: s => writes.Add(s + Environment.NewLine)); } if ((options & ForwardOptions.Capture) != 0) { forwarder.Capture(); } forwarder.Read(new StringReader(str)); Assert.Equal(expectedWrites, writes); var captured = forwarder.CapturedOutput; Assert.Equal(expectedCaptured, captured); }