aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2015-10-28 13:24:28 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2015-11-18 00:28:45 +0100
commit69cd6f586418291c980831cd92508c549c84ce94 (patch)
treeaa54d0ed4bae5f7c1c3c23211d458e5378099c44 /org.eclipse.jgit.test
parent6389948a814412267f46de375563f9d009d76ccb (diff)
downloadjgit-69cd6f586418291c980831cd92508c549c84ce94.tar.gz
jgit-69cd6f586418291c980831cd92508c549c84ce94.zip
Introduce FS.execute() to execute a command defined by a ProcessBuilder
Change-Id: I2ad2c71ad30b969455bdea89637b8e996b1dad8c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java
index 82beab2dc8..b6a2519c59 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java
@@ -52,6 +52,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.util.FS.ExecutionResult;
import org.junit.Before;
import org.junit.Test;
@@ -163,6 +164,45 @@ public class RunExternalScriptTest {
assertEquals(127, rc);
}
+ @Test
+ public void testCopyStdInExecute()
+ throws IOException, InterruptedException {
+ String inputStr = "a\nb\rc\r\nd";
+ File script = writeTempFile("cat -");
+ ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+ ExecutionResult res = FS.DETECTED.execute(pb,
+ new ByteArrayInputStream(inputStr.getBytes()));
+ assertEquals(0, res.getRc());
+ assertEquals(inputStr, new String(res.getStdout().toByteArray()));
+ assertEquals("", new String(res.getStderr().toByteArray()));
+ }
+
+ @Test
+ public void testStdErrExecute() throws IOException, InterruptedException {
+ File script = writeTempFile("echo hi >&2");
+ ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+ ExecutionResult res = FS.DETECTED.execute(pb, null);
+ assertEquals(0, res.getRc());
+ assertEquals("", new String(res.getStdout().toByteArray()));
+ assertEquals("hi" + sep, new String(res.getStderr().toByteArray()));
+ }
+
+ @Test
+ public void testAllTogetherBinExecute()
+ throws IOException, InterruptedException {
+ String inputStr = "a\nb\rc\r\nd";
+ File script = writeTempFile(
+ "echo $#,$1,$2,$3,$4,$5,$6 >&2 ; cat -; exit 5");
+ ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath(), "a",
+ "b", "c");
+ ExecutionResult res = FS.DETECTED.execute(pb,
+ new ByteArrayInputStream(inputStr.getBytes()));
+ assertEquals(5, res.getRc());
+ assertEquals(inputStr, new String(res.getStdout().toByteArray()));
+ assertEquals("3,a,b,c,,," + sep,
+ new String(res.getStderr().toByteArray()));
+ }
+
private File writeTempFile(String body) throws IOException {
File f = File.createTempFile("RunProcessTestScript_", "");
JGitTestUtil.write(f, body);