|
|
@ -43,6 +43,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.eclipse.jgit.util; |
|
|
|
package org.eclipse.jgit.util; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
@ -77,8 +78,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath()), out, err, |
|
|
|
new ProcessBuilder("sh", script.getPath()), out, err, |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(inputStr, new String(out.toByteArray())); |
|
|
|
assertEquals(inputStr, new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("", new String(err.toByteArray())); |
|
|
|
assertEquals("", new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -88,8 +89,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath()), out, err, |
|
|
|
new ProcessBuilder("sh", script.getPath()), out, err, |
|
|
|
(InputStream) null); |
|
|
|
(InputStream) null); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals("", new String(out.toByteArray())); |
|
|
|
assertEquals("", new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("", new String(err.toByteArray())); |
|
|
|
assertEquals("", new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -99,8 +100,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", |
|
|
|
new ProcessBuilder("sh", |
|
|
|
script.getPath(), "a", "b", "c"), out, err, (InputStream) null); |
|
|
|
script.getPath(), "a", "b", "c"), out, err, (InputStream) null); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray())); |
|
|
|
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("", new String(err.toByteArray())); |
|
|
|
assertEquals("", new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -110,8 +111,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), |
|
|
|
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), |
|
|
|
out, err, (InputStream) null); |
|
|
|
out, err, (InputStream) null); |
|
|
|
assertEquals(3, rc); |
|
|
|
assertEquals(3, rc); |
|
|
|
assertEquals("", new String(out.toByteArray())); |
|
|
|
assertEquals("", new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("", new String(err.toByteArray())); |
|
|
|
assertEquals("", new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -121,8 +122,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath()), null, err, |
|
|
|
new ProcessBuilder("sh", script.getPath()), null, err, |
|
|
|
(InputStream) null); |
|
|
|
(InputStream) null); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals("", new String(out.toByteArray())); |
|
|
|
assertEquals("", new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("", new String(err.toByteArray())); |
|
|
|
assertEquals("", new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -132,8 +133,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath()), null, err, |
|
|
|
new ProcessBuilder("sh", script.getPath()), null, err, |
|
|
|
(InputStream) null); |
|
|
|
(InputStream) null); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals(0, rc); |
|
|
|
assertEquals("", new String(out.toByteArray())); |
|
|
|
assertEquals("", new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("hi" + LF, new String(err.toByteArray())); |
|
|
|
assertEquals("hi" + LF, new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -144,8 +145,8 @@ public class RunExternalScriptTest { |
|
|
|
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), |
|
|
|
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), |
|
|
|
out, err, new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
out, err, new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
assertEquals(5, rc); |
|
|
|
assertEquals(5, rc); |
|
|
|
assertEquals(inputStr, new String(out.toByteArray())); |
|
|
|
assertEquals(inputStr, new String(out.toByteArray(), UTF_8)); |
|
|
|
assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray())); |
|
|
|
assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IOException.class) |
|
|
|
@Test(expected = IOException.class) |
|
|
@ -174,8 +175,9 @@ public class RunExternalScriptTest { |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
assertEquals(0, res.getRc()); |
|
|
|
assertEquals(0, res.getRc()); |
|
|
|
assertEquals(inputStr, new String(res.getStdout().toByteArray())); |
|
|
|
assertEquals(inputStr, |
|
|
|
assertEquals("", new String(res.getStderr().toByteArray())); |
|
|
|
new String(res.getStdout().toByteArray(), UTF_8)); |
|
|
|
|
|
|
|
assertEquals("", new String(res.getStderr().toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -184,8 +186,9 @@ public class RunExternalScriptTest { |
|
|
|
ProcessBuilder pb = new ProcessBuilder("sh", script.getPath()); |
|
|
|
ProcessBuilder pb = new ProcessBuilder("sh", script.getPath()); |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, null); |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, null); |
|
|
|
assertEquals(0, res.getRc()); |
|
|
|
assertEquals(0, res.getRc()); |
|
|
|
assertEquals("", new String(res.getStdout().toByteArray())); |
|
|
|
assertEquals("", new String(res.getStdout().toByteArray(), UTF_8)); |
|
|
|
assertEquals("hi" + LF, new String(res.getStderr().toByteArray())); |
|
|
|
assertEquals("hi" + LF, |
|
|
|
|
|
|
|
new String(res.getStderr().toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -199,9 +202,10 @@ public class RunExternalScriptTest { |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, |
|
|
|
ExecutionResult res = FS.DETECTED.execute(pb, |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
new ByteArrayInputStream(inputStr.getBytes())); |
|
|
|
assertEquals(5, res.getRc()); |
|
|
|
assertEquals(5, res.getRc()); |
|
|
|
assertEquals(inputStr, new String(res.getStdout().toByteArray())); |
|
|
|
assertEquals(inputStr, |
|
|
|
|
|
|
|
new String(res.getStdout().toByteArray(), UTF_8)); |
|
|
|
assertEquals("3,a,b,c,,," + LF, |
|
|
|
assertEquals("3,a,b,c,,," + LF, |
|
|
|
new String(res.getStderr().toByteArray())); |
|
|
|
new String(res.getStderr().toByteArray(), UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private File writeTempFile(String body) throws IOException { |
|
|
|
private File writeTempFile(String body) throws IOException { |
|
|
|