Author: sgoeschl
Date: Tue Jan 13 14:56:37 2009
New Revision: 734269
URL: http://svn.apache.org/viewvc?rev=734269&view=rev
Log:
[EXEC-33] Adding tests to properly analyse the problem
Added:
commons/proper/exec/trunk/src/test/scripts/redirect.sh (with props)
Modified:
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
Modified:
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java?rev=734269&r1=734268&r2=734269&view=diff
==============================================================================
---
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
(original)
+++
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
Tue Jan 13 14:56:37 2009
@@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
+import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +36,7 @@
private File errorTestScript = TestUtil.resolveScriptForOS(testDir +
"/error");
private File foreverTestScript = TestUtil.resolveScriptForOS(testDir +
"/forever");
private File nonExistingTestScript = TestUtil.resolveScriptForOS(testDir +
"/grmpffffff");
+ private File redirectScript = TestUtil.resolveScriptForOS(testDir +
"/redirect");
// Get suitable exit codes for the OS
private static final int SUCCESS_STATUS; // test script successful exit
code
@@ -343,5 +345,39 @@
int exitValue = exec.execute(cl);
assertTrue(baos.toString().trim().indexOf("test $;`(0)[1]{2}") > 0);
assertFalse(exec.isFailure(exitValue));
- }
+ }
+
+ /**
+ * Start a process with redirected streams - stdin of the newly
+ * created process is connected to a FileInputStream whereas
+ * the "redirect" script reads all lines from stdin and prints
+ * them on stdout. Furthermore the script prints a status
+ * message on stderr.
+ */
+ public void testExecuteWithRedirectedStreams() throws Exception
+ {
+ FileInputStream fis = new FileInputStream("./NOTICE.txt");
+ CommandLine cl = new CommandLine(redirectScript);
+ PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
System.out, System.out, fis );
+ DefaultExecutor executor = new DefaultExecutor();
+ executor.setWorkingDirectory(new File("."));
+ executor.setStreamHandler( pumpStreamHandler );
+ int exitValue = executor.execute(cl);
+ fis.close();
+ assertFalse(exec.isFailure(exitValue));
+ }
+
+ /**
+ * Start a process and connect stdin, stdout and stderr. This
+ * test currenty hang ....
+ */
+ public void doNotTestExecuteWithStdin() throws Exception
+ {
+ CommandLine cl = new CommandLine(testScript);
+ PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
System.out, System.err, System.in );
+ DefaultExecutor executor = new DefaultExecutor();
+ executor.setStreamHandler( pumpStreamHandler );
+ int exitValue = executor.execute(cl);
+ assertFalse(exec.isFailure(exitValue));
+ }
}
Added: commons/proper/exec/trunk/src/test/scripts/redirect.sh
URL:
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/redirect.sh?rev=734269&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/redirect.sh (added)
+++ commons/proper/exec/trunk/src/test/scripts/redirect.sh Tue Jan 13 14:56:37
2009
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# print the given environment variable and command line parameter
+# since this is verified by the regression test
+
+while read myline
+do
+ echo "stdout: $myline"
+done
+
+echo 1>&2 "stderr: Finished reading from stdin"
+
+exit 0
+
Propchange: commons/proper/exec/trunk/src/test/scripts/redirect.sh
------------------------------------------------------------------------------
svn:executable = *