@ -57,12 +57,12 @@ import org.junit.Before;
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 ( ) ;
@ -74,7 +74,7 @@ public class RunExternalScriptTest {
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 ( ) ) ) ;
@ -85,7 +85,7 @@ public class RunExternalScriptTest {
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 ( ) ) ) ;
@ -95,7 +95,8 @@ public class RunExternalScriptTest {
@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 ( ) ) ) ;
@ -106,7 +107,7 @@ public class RunExternalScriptTest {
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 ( ) ) ) ;
@ -117,7 +118,7 @@ public class RunExternalScriptTest {
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 ( ) ) ) ;
@ -128,11 +129,11 @@ public class RunExternalScriptTest {
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
@ -140,11 +141,11 @@ public class RunExternalScriptTest {
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 )
@ -159,7 +160,7 @@ public class RunExternalScriptTest {
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 ) ;
}
@ -169,7 +170,7 @@ public class RunExternalScriptTest {
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 ( ) ) ;
@ -180,11 +181,11 @@ public class RunExternalScriptTest {
@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
@ -193,13 +194,13 @@ public class RunExternalScriptTest {
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 ( ) ) ) ;
}