private void RunCommand(string command, string workingDirectory, Action<SystemProcess> onFailure) { log.Info("svn {0}", command); var processRunner = new ProcessRunner(workingDirectory); var process = processRunner.Exec("svn " + command, commandTimeout); if (!process.WasSuccessful) onFailure(process); }
public void ExecShouldKillEntireProcessTreeAfterTimeout() { SystemAssert.AssertProcessKilled("ping", () => { var runner = new ProcessRunner(); runner.Exec("cmd /c cmd /c ping 127.0.0.1 -n 20", TimeSpan.FromMilliseconds(100)); }); }
public static void GitRepo(Action<string> test) { var repoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var currentDirectory = Environment.CurrentDirectory; Using.Directory(repoPath, () => { var runner = new ProcessRunner(); var initProcess = runner.Exec("git init", TimeSpan.FromSeconds(30)); NUnit.Framework.Assert.That(initProcess.WasSuccessful, initProcess.ToString()); File.WriteAllText(Path.Combine(repoPath, "git-repo"), ""); var addProcess = runner.Exec("git add git-repo", TimeSpan.FromSeconds(30)); NUnit.Framework.Assert.That(addProcess.WasSuccessful, initProcess.ToString()); var commitProcess = runner.Exec("git commit -a -m 'init'", TimeSpan.FromSeconds(30)); NUnit.Framework.Assert.That(commitProcess.WasSuccessful, commitProcess.ToString()); Using.Directory(Path.Combine(currentDirectory, "git"), () => test(repoPath)); }); }
public void ShouldHandleMultilineOutput() { Using.Directory("processRunnerTest", () => { var lines = new StringBuilder().AppendLine("first line").Append("second line"); File.WriteAllText("multiline.txt", lines.ToString()); var runner = new ProcessRunner(); var process = runner.Exec("cmd /c type multiline.txt", TimeSpan.MaxValue); Assert.That(process.StandardOutput, Is.EqualTo(lines.ToString())); }); }
public static GitProvider Clone(string url, ILogger log, TimeSpan commandTimeout) { var localPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(localPath); var runner = new ProcessRunner(localPath); var process = runner.Exec(string.Format("git clone \"{0}\"", url), TimeSpan.FromMinutes(5)); if (!process.WasSuccessful) throw new ArgumentException(process.ToString()); return new GitProvider(log, localPath, commandTimeout); }
public void ExecShouldKillProcessAfterTimeout() { SystemAssert.AssertProcessKilled("ping", () => { var runner = new ProcessRunner(); var start = DateTime.Now; runner.Exec("ping 127.0.0.1 -n 20", TimeSpan.FromMilliseconds(100)); // Lots of buffer adding because of virtualization, etc // Should take 20 seconds or so without being killed Assert.That(DateTime.Now - start, Is.LessThan(TimeSpan.FromSeconds(8))); }); }
public void ShouldUseGivenWorkingDirectory() { var runner = new ProcessRunner(@"C:\"); var process = runner.Exec("cmd /c cd", TimeSpan.FromSeconds(10)); Assert.That(process.StandardOutput, Is.EqualTo(@"C:\")); }