import org.junit.Test;
public class RunExternalScriptTest {
+ private static final String LF = "\n";
+
private ByteArrayOutputStream out;
private ByteArrayOutputStream err;
- private String sep = System.getProperty("line.separator");
-
@Before
public void setUp() throws Exception {
out = new ByteArrayOutputStream();
String inputStr = "a\nb\rc\r\nd";
File script = writeTempFile("cat -");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath()), out, err,
+ new ProcessBuilder("sh", script.getPath()), out, err,
new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(0, rc);
assertEquals(inputStr, new String(out.toByteArray()));
public void testCopyNullStdIn() throws IOException, InterruptedException {
File script = writeTempFile("cat -");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath()), out, err,
+ new ProcessBuilder("sh", script.getPath()), out, err,
(InputStream) null);
assertEquals(0, rc);
assertEquals("", new String(out.toByteArray()));
@Test
public void testArguments() throws IOException, InterruptedException {
File script = writeTempFile("echo $#,$1,$2,$3,$4,$5,$6");
- int rc = FS.DETECTED.runProcess(new ProcessBuilder("/bin/bash",
+ int rc = FS.DETECTED.runProcess(
+ new ProcessBuilder("sh",
script.getPath(), "a", "b", "c"), out, err, (InputStream) null);
assertEquals(0, rc);
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray()));
public void testRc() throws IOException, InterruptedException {
File script = writeTempFile("exit 3");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+ new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
out, err, (InputStream) null);
assertEquals(3, rc);
assertEquals("", new String(out.toByteArray()));
public void testNullStdout() throws IOException, InterruptedException {
File script = writeTempFile("echo hi");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath()), null, err,
+ new ProcessBuilder("sh", script.getPath()), null, err,
(InputStream) null);
assertEquals(0, rc);
assertEquals("", new String(out.toByteArray()));
public void testStdErr() throws IOException, InterruptedException {
File script = writeTempFile("echo hi >&2");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath()), null, err,
+ new ProcessBuilder("sh", script.getPath()), null, err,
(InputStream) null);
assertEquals(0, rc);
assertEquals("", new String(out.toByteArray()));
- assertEquals("hi" + sep, new String(err.toByteArray()));
+ assertEquals("hi" + LF, new String(err.toByteArray()));
}
@Test
String inputStr = "a\nb\rc\r\nd";
File script = writeTempFile("echo $#,$1,$2,$3,$4,$5,$6 >&2 ; cat -; exit 5");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+ new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
out, err, new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(5, rc);
assertEquals(inputStr, new String(out.toByteArray()));
- assertEquals("3,a,b,c,,," + sep, new String(err.toByteArray()));
+ assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray()));
}
@Test(expected = IOException.class)
public void testWrongScript() throws IOException, InterruptedException {
File script = writeTempFile("cat-foo -");
int rc = FS.DETECTED.runProcess(
- new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+ new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
out, err, (InputStream) null);
assertEquals(127, rc);
}
throws IOException, InterruptedException {
String inputStr = "a\nb\rc\r\nd";
File script = writeTempFile("cat -");
- ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+ ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
ExecutionResult res = FS.DETECTED.execute(pb,
new ByteArrayInputStream(inputStr.getBytes()));
assertEquals(0, res.getRc());
@Test
public void testStdErrExecute() throws IOException, InterruptedException {
File script = writeTempFile("echo hi >&2");
- ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+ ProcessBuilder pb = new ProcessBuilder("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()));
+ assertEquals("hi" + LF, new String(res.getStderr().toByteArray()));
}
@Test
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",
+ ProcessBuilder pb = new ProcessBuilder("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,
+ assertEquals("3,a,b,c,,," + LF,
new String(res.getStderr().toByteArray()));
}