skytreader / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

StdOut and StdErr from launched processes are not printed properly + patch #415

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I was using (which includes js-test-driver and which turned to contain the bug):

  <groupId>com.googlecode.jstd-maven-plugin</groupId>
  <artifactId>jstd-maven-plugin</artifactId>
  <version>1.3.2.5</version>

and there were some problems launching browser on my Hudson server. We were 
getting errors below (please note "[B@6a1e01" string):

----
Failure 1: java.lang.RuntimeException: Could not start browser 
CommandLineBrowserRunner [
browserPath=/usr/bin/firefox,
process=java.lang.UNIXProcess@2cba0a,
 process log={
error:
[B@6a1e01
input:

}] in 30

---

This is very likely because stringBuilder.append(byteArray) does not put the 
bytes into the array. Here is a fix that works for ASCII characters:

src/js-test-driver$ git diff
diff --git 
a/JsTestDriver/src/com/google/jstestdriver/browser/CommandLineBrowserRunner.java

b/JsTestDriver/src/com/google/jstestdriver/browser/CommandLineBrowserRunner.java
index d0aa65d..c182a09 100644
--- 
a/JsTestDriver/src/com/google/jstestdriver/browser/CommandLineBrowserRunner.java
+++ 
b/JsTestDriver/src/com/google/jstestdriver/browser/CommandLineBrowserRunner.java
@@ -212,12 +212,16 @@ public class CommandLineBrowserRunner implements 
BrowserRunner {
       try {
         while (stream.get()) {
           while (errorStream.available() > 0) {
-            errorStream.read(errBuffer);
-            errLog.append(errBuffer);
+            int len = errorStream.read(errBuffer);
+            for (int i = 0; i < len; i++) {
+                errLog.append((char)errBuffer[i]);
+            }
           }
           while (inputStream.available() > 0) {
-            inputStream.read(stdOutBuffer);
-            outLog.append(errBuffer);
+            int len = inputStream.read(stdOutBuffer);
+            for (int i = 0; i < len; i++) {
+                outLog.append((char)stdOutBuffer[i]);
+            }
           }
         }
       } catch (IOException e) {

Original issue reported on code.google.com by jaroslav...@gmail.com on 12 Dec 2012 at 4:36