public void TestNormalExecution() { var processFactory = new Mock <IProcessFactory>(); var mockProcess = new Mock <ProcessWrapper>(); mockProcess.Setup(x => x.ExitCode).Returns(0); var startInfo = new ProcessStartInfo(); mockProcess.Setup(x => x.StartInfo).Returns(startInfo); processFactory.Setup(x => x.GetProcess()).Returns(mockProcess.Object); var service = new BashRunner(processFactory.Object); var processResult = service.RunCommand("test-command blah -k \"zz\"", "/working/path", true, 33, 10); Assert.Equal("/bin/bash", startInfo.FileName); Assert.Equal("/working/path", startInfo.WorkingDirectory); Assert.Equal("-c \"test-command blah -k \\\"zz\\\"\"", startInfo.Arguments); Assert.True(startInfo.RedirectStandardError); Assert.True(startInfo.RedirectStandardOutput); Assert.True(startInfo.CreateNoWindow); Assert.False(startInfo.RedirectStandardInput); Assert.False(startInfo.UseShellExecute); mockProcess.Verify(x => x.Start(), Times.Once); mockProcess.Verify(x => x.WaitForExit(33), Times.Once); }
static void InnerGetText(string tempFileName) { if (isWsl) { BashRunner.Run($"powershell.exe Get-Clipboard > {tempFileName}"); } else { BashRunner.Run($"xsel -o --clipboard > {tempFileName}"); } }
public void Delete() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { CmdRunner.DeleteDirectoryWithUnlimitedRetries(this.RootPath); } else { // TODO(Mac): See if we can use BashRunner.DeleteDirectoryWithRetry on Windows as well BashRunner.DeleteDirectoryWithUnlimitedRetries(this.RootPath); } }
public static void DeleteTestDirectory(string repoPath) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Use cmd.exe to delete the enlistment as it properly handles tombstones and reparse points CmdRunner.DeleteDirectoryWithUnlimitedRetries(repoPath); } else { BashRunner.DeleteDirectoryWithUnlimitedRetries(repoPath); } }
private void DeleteDirectoryWithUnlimitedRetries(string path) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { CmdRunner.DeleteDirectoryWithUnlimitedRetries(path); } else { // TODO(Mac): See if we can use BashRunner.DeleteDirectoryWithRetry on Windows as well BashRunner.DeleteDirectoryWithUnlimitedRetries(path); } }
public static async Task <string?> GetTextAsync(CancellationToken cancellation) { var tempFileName = Path.GetTempFileName(); try { BashRunner.Run($"xsel -o --clipboard > {tempFileName}"); return(await File.ReadAllTextAsync(tempFileName, cancellation)); } finally { File.Delete(tempFileName); } }
public static string GetText() { var tempFileName = Path.GetTempFileName(); try { BashRunner.Run($"xclip -o -selection clipboard > {tempFileName}"); return(File.ReadAllText(tempFileName)); } finally { File.Delete(tempFileName); } }
public static void SetText(string text) { var tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, text); try { BashRunner.Run($"cat {tempFileName} | xclip -i -selection clipboard"); } finally { File.Delete(tempFileName); } }
public void PasteFile(MapType mapTypeToLoad) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { return; } const string filePrefix = "file:///"; string pathToFile; var pathToTextFile = Path.GetTempFileName(); BashRunner.Run($"xclip -selection clipboard -t TARGETS -o > {pathToTextFile}"); var bashOut = File.ReadAllText(pathToTextFile); Debug.Log($"Out : {bashOut}"); File.Delete(pathToTextFile); if (bashOut.Contains("image/png")) { pathToFile = Path.GetTempFileName() + ".png"; BashRunner.Run($"xclip -selection clipboard -t image/png -o > {pathToFile}"); } else { BashRunner.Run($"xclip -selection clipboard -o > {pathToTextFile}"); bashOut = File.ReadAllText(pathToTextFile); if (!bashOut.Contains(filePrefix)) { return; } var supported = MainGui.LoadFormats.Any(format => bashOut.Contains(format)); if (!supported) { return; } var firstIndex = bashOut.IndexOf("file:///", StringComparison.Ordinal); var lastIndex = bashOut.IndexOf("\n", firstIndex, StringComparison.Ordinal); var length = lastIndex - firstIndex; pathToFile = bashOut.Substring(firstIndex, length); pathToFile = pathToFile.Replace("file:///", "/"); Debug.Log("Path " + pathToFile); } File.Delete(pathToTextFile); StartCoroutine(LoadTexture(mapTypeToLoad, pathToFile)); }
public static Task SetText(string text, CancellationToken cancellation) { var tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, text); try { BashRunner.Run($"cat {tempFileName} | xclip -i -selection clipboard"); } finally { File.Delete(tempFileName); } return(Task.CompletedTask); }
public static Task <string?> GetText(CancellationToken cancellation) { var tempFileName = Path.GetTempFileName(); try { BashRunner.Run($"xclip -o -selection clipboard > {tempFileName}"); var readAllText = File.ReadAllText(tempFileName); // ReSharper disable once RedundantTypeArgumentsOfMethod return(Task.FromResult <string?>(readAllText)); } finally { File.Delete(tempFileName); } }
public static string?GetText() { var tempFileName = Path.GetTempFileName(); try { BashRunner.Run($"xclip -o -selection clipboard > {tempFileName}"); var readAllText = File.ReadAllText(tempFileName); // ReSharper disable once RedundantTypeArgumentsOfMethod return(readAllText); } finally { File.Delete(tempFileName); } }
protected void CreateHardLink(string newLinkFileName, string existingFileName) { string virtualExistingFile = Path.Combine(this.Enlistment.RepoRoot, existingFileName); string controlExistingFile = Path.Combine(this.ControlGitRepo.RootPath, existingFileName); string virtualNewLinkFile = Path.Combine(this.Enlistment.RepoRoot, newLinkFileName); string controlNewLinkFile = Path.Combine(this.ControlGitRepo.RootPath, newLinkFileName); // GitRepoTests are only run with SystemIORunner (which does not support hardlink // creation) so use a BashRunner instead. this.FileSystem.SupportsHardlinkCreation.ShouldBeFalse( "If this.FileSystem.SupportsHardlinkCreation is true, CreateHardLink no longer needs to create a BashRunner"); FileSystemRunner runner = new BashRunner(); runner.CreateHardLink(virtualNewLinkFile, virtualExistingFile); runner.CreateHardLink(controlNewLinkFile, controlExistingFile); }
static void InnerSetText(string tempFileName) { try { if (isWsl) { BashRunner.Run($"cat {tempFileName} | clip.exe "); } else { BashRunner.Run($"cat {tempFileName} | xsel -i --clipboard "); } } finally { File.Delete(tempFileName); } }
public static async Task SetTextAsync(string text, CancellationToken cancellation) { var tempFileName = Path.GetTempFileName(); await File.WriteAllTextAsync(tempFileName, text, cancellation); try { if (cancellation.IsCancellationRequested) { return; } BashRunner.Run($"cat {tempFileName} | xsel -i --clipboard "); } finally { File.Delete(tempFileName); } }
public void AppendFileUsingBash() { // Bash will perform the append using '>>' which will cause KAUTH_VNODE_APPEND_DATA to be sent without hydration // Other Runners may cause hydration before append BashRunner bash = new BashRunner(); string filePath = Path.Combine("Test_EPF_UpdatePlaceholderTests", "LockToPreventUpdate", "test.txt"); string content = "Apended Data"; string virtualFile = Path.Combine(this.Enlistment.RepoRoot, filePath); string controlFile = Path.Combine(this.ControlGitRepo.RootPath, filePath); bash.AppendAllText(virtualFile, content); bash.AppendAllText(controlFile, content); this.ValidateGitCommand("status"); // We check the contents after status, to ensure this check didn't cause the hydration string appendedContent = string.Concat("Commit2LockToPreventUpdate \r\n", content); virtualFile.ShouldBeAFile(this.FileSystem).WithContents(appendedContent); controlFile.ShouldBeAFile(this.FileSystem).WithContents(appendedContent); }
public static void SetText(string text) { var tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, text); try { if (isWsl) { BashRunner.Run($"cat {tempFileName} | clip.exe "); } else { BashRunner.Run($"cat {tempFileName} | xsel -i --clipboard "); } } finally { File.Delete(tempFileName); } }
public static string GetText() { var tempFileName = Path.GetTempFileName(); try { if (isWsl) { BashRunner.Run($"powershell.exe Get-Clipboard > {tempFileName}"); } else { BashRunner.Run($"xsel -o --clipboard > {tempFileName}"); } return(File.ReadAllText(tempFileName)); } finally { File.Delete(tempFileName); } }
public void TearDown() { string backupFolder = Path.Combine(this.Enlistment.EnlistmentRoot, "dehydrate_backup"); if (this.fileSystem.DirectoryExists(backupFolder)) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // Mac gets permission denied when using the System.IO DeleteDirectory BashRunner runner = new BashRunner(); runner.DeleteDirectory(backupFolder); } else { this.fileSystem.DeleteDirectory(backupFolder); } } if (!this.Enlistment.IsMounted()) { this.Enlistment.MountGVFS(); } }
public void PasteFile(MapType mapTypeToLoad) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string tempImagePath = Application.dataPath + "/temp.png"; //string tempImagePath = Application.persistentDataPath + "/temp.png"; UnityEngine.Debug.Log(tempImagePath); try { Process myProcess = new Process(); myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; myProcess.StartInfo.CreateNoWindow = true; myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace("/", "\\") + "\\c2i.exe"; myProcess.StartInfo.Arguments = tempImagePath.Replace("/", "\\"); myProcess.EnableRaisingEvents = true; myProcess.Start(); myProcess.WaitForExit(); StartCoroutine(LoadTexture(mapTypeToLoad, tempImagePath)); } catch (Exception e) { UnityEngine.Debug.Log(e); } } else { const string filePrefix = "file:///"; string pathToFile; var pathToTextFile = Path.GetTempFileName(); BashRunner.Run($"xclip -selection clipboard -t TARGETS -o > {pathToTextFile}"); var bashOut = File.ReadAllText(pathToTextFile); Debug.Log($"Out : {bashOut}"); File.Delete(pathToTextFile); if (bashOut.Contains("image/png")) { pathToFile = Path.GetTempFileName() + ".png"; BashRunner.Run($"xclip -selection clipboard -t image/png -o > {pathToFile}"); } else { BashRunner.Run($"xclip -selection clipboard -o > {pathToTextFile}"); bashOut = File.ReadAllText(pathToTextFile); if (!bashOut.Contains(filePrefix)) { return; } var supported = MainGui.LoadFormats.Any(format => bashOut.Contains(format)); if (!supported) { return; } var firstIndex = bashOut.IndexOf("file:///", StringComparison.Ordinal); var lastIndex = bashOut.IndexOf("\n", firstIndex, StringComparison.Ordinal); var length = lastIndex - firstIndex; pathToFile = bashOut.Substring(firstIndex, length); pathToFile = pathToFile.Replace("file:///", "/"); Debug.Log("Path " + pathToFile); } File.Delete(pathToTextFile); StartCoroutine(LoadTexture(mapTypeToLoad, pathToFile)); } }
public SymbolicLinkTests() { this.bashRunner = new BashRunner(); }