ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r420337 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit: Constants.java JUnitTask.java JUnitTestRunner.java
Date Sun, 09 Jul 2006 19:47:26 GMT
Author: jkf
Date: Sun Jul  9 12:47:26 2006
New Revision: 420337

URL: http://svn.apache.org/viewvc?rev=420337&view=rev
Log:
Fixed length mismatch.

Made use of shared constants in junit package.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java
Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

Added: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java?rev=420337&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java Sun
Jul  9 12:47:26 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright  2000-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+/**
+ * Constants, like filenames shared between various classes in this package.
+ */
+public class Constants {
+
+    static final String HALT_ON_ERROR = "haltOnError=";
+    static final String HALT_ON_FAILURE = "haltOnFailure=";
+    static final String FILTERTRACE = "filtertrace=";
+    static final String CRASHFILE = "crashfile=";
+    static final String BEFORE_FIRST_TEST = "BeforeFirstTest";
+    static final String PROPSFILE = "propsfile=";
+    static final String SHOWOUTPUT = "showoutput=";
+    static final String FORMATTER = "formatter=";
+    static final String LOGTESTLISTENEREVENTS = "logtestlistenerevents=";
+    static final String TESTSFILE = "testsfile=";
+    static final String TERMINATED_SUCCESSFULLY = "terminated successfully";
+}

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?rev=420337&r1=420336&r2=420337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Sun
Jul  9 12:47:26 2006
@@ -125,6 +125,7 @@
  */
 public class JUnitTask extends Task {
 
+    private static final String CLASSPATH = "CLASSPATH=";
     private CommandlineJava commandline;
     private Vector tests = new Vector();
     private Vector batchTests = new Vector();
@@ -883,22 +884,22 @@
             cmd.createArgument().setValue(test.getName());
         } else {
             log("Running multiple tests in the same VM", Project.MSG_VERBOSE);
-            cmd.createArgument().setValue("testsfile=" + casesFile);
+            cmd.createArgument().setValue(Constants.TESTSFILE + casesFile);
         }
 
-        cmd.createArgument().setValue("filtertrace=" + test.getFiltertrace());
-        cmd.createArgument().setValue("haltOnError=" + test.getHaltonerror());
-        cmd.createArgument().setValue("haltOnFailure="
+        cmd.createArgument().setValue(Constants.FILTERTRACE + test.getFiltertrace());
+        cmd.createArgument().setValue(Constants.HALT_ON_ERROR + test.getHaltonerror());
+        cmd.createArgument().setValue(Constants.HALT_ON_FAILURE
                                       + test.getHaltonfailure());
         if (includeAntRuntime) {
             Vector v = Execute.getProcEnvironment();
             Enumeration e = v.elements();
             while (e.hasMoreElements()) {
                 String s = (String) e.nextElement();
-                if (s.startsWith("CLASSPATH=")) {
+                if (s.startsWith(CLASSPATH)) {
                     cmd.createClasspath(getProject()).createPath()
                         .append(new Path(getProject(),
-                                         s.substring(10 // "CLASSPATH=".length()
+                                         s.substring(CLASSPATH.length()
                                                      )));
                 }
             }
@@ -914,21 +915,21 @@
                 prefix = "OutErr";
             }
             cmd.createArgument()
-                .setValue("formatter"
-                          + "=org.apache.tools.ant.taskdefs.optional.junit."
+                .setValue(Constants.FORMATTER
+                          + "org.apache.tools.ant.taskdefs.optional.junit."
                           + prefix + "SummaryJUnitResultFormatter");
         }
 
-        cmd.createArgument().setValue("showoutput="
+        cmd.createArgument().setValue(Constants.SHOWOUTPUT
                                       + String.valueOf(showOutput));
-        cmd.createArgument().setValue("logtestlistenerevents=true"); // #31885
+        cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS+"true"); // #31885
 
         StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
         final FormatterElement[] feArray = mergeFormatters(test);
         for (int i = 0; i < feArray.length; i++) {
             FormatterElement fe = feArray[i];
             if (fe.shouldUse(this)) {
-                formatterArg.append("formatter=");
+                formatterArg.append(Constants.FORMATTER);
                 formatterArg.append(fe.getClassname());
                 File outFile = getOutput(fe, test);
                 if (outFile != null) {
@@ -941,10 +942,10 @@
         }
 
         File vmWatcher = createTempPropertiesFile("junitvmwatcher");
-        cmd.createArgument().setValue("crashfile="
+        cmd.createArgument().setValue(Constants.CRASHFILE
                                       + vmWatcher.getAbsolutePath());
         File propsFile = createTempPropertiesFile("junit");
-        cmd.createArgument().setValue("propsfile="
+        cmd.createArgument().setValue(Constants.PROPSFILE
                                       + propsFile.getAbsolutePath());
         Hashtable p = getProject().getProperties();
         Properties props = new Properties();
@@ -1000,7 +1001,7 @@
             if (watchdog != null && watchdog.killedProcess()) {
                 result.timedOut = true;
                 logTimeout(feArray, test, vmCrashString);
-            } else if (!"terminated successfully".equals(vmCrashString)) {
+            } else if (!Constants.TERMINATED_SUCCESSFULLY.equals(vmCrashString)) {
                 result.crashed = true;
                 logVmCrash(feArray, test, vmCrashString);
             }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?rev=420337&r1=420336&r2=420337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
Sun Jul  9 12:47:26 2006
@@ -21,7 +21,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -146,7 +145,7 @@
 
     /** ClassLoader passed in in non-forked mode. */
     private ClassLoader loader;
-    
+
     /** Do we print TestListener events? */
     private boolean logTestListenerEvents = false;
 
@@ -158,7 +157,7 @@
      * File will be empty in case the build did not crash.
      */
     private static String crashFile = null;
-    
+
     /**
      * Constructor for fork=true or when the user hasn't specified a
      * classpath.
@@ -227,7 +226,7 @@
     }
 
     private PrintStream savedOut = null;
-    
+
     public void run() {
         res = new TestResult();
         res.addListener(wrapListener(this));
@@ -426,7 +425,7 @@
         String testName = JUnitVersionHelper.getTestCaseName(test);
         logTestListenerEvent("endTest(" + testName + ")");
     }
-    
+
     private void logTestListenerEvent(String msg) {
         PrintStream out = forked ? savedOut : System.out;
         if (logTestListenerEvents) {
@@ -481,9 +480,9 @@
     }
 
     public void handleOutput(String output) {
-        if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX))
-            ; // ignore
-        else if (systemOut != null) {
+        if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX))
{
+            // ignore
+        } else if (systemOut != null) {
             systemOut.print(output);
         }
     }
@@ -589,37 +588,37 @@
             System.exit(ERRORS);
         }
 
-        if (args[0].startsWith("testsfile=")) {
+        if (args[0].startsWith(Constants.TESTSFILE)) {
             multipleTests = true;
-            args[0] = args[0].substring(10 /* "testsfile=".length() */);
+            args[0] = args[0].substring(Constants.TESTSFILE.length());
         }
 
         for (int i = 1; i < args.length; i++) {
-            if (args[i].startsWith("haltOnError=")) {
-                haltError = Project.toBoolean(args[i].substring(12));
-            } else if (args[i].startsWith("haltOnFailure=")) {
-                haltFail = Project.toBoolean(args[i].substring(14));
-            } else if (args[i].startsWith("filtertrace=")) {
-                stackfilter = Project.toBoolean(args[i].substring(12));
-            } else if (args[i].startsWith("crashfile=")) {
-                crashFile = args[i].substring(12);
-                registerTestCase("BeforeFirstTest");
-            } else if (args[i].startsWith("formatter=")) {
+            if (args[i].startsWith(Constants.HALT_ON_ERROR)) {
+                haltError = Project.toBoolean(args[i].substring(Constants.HALT_ON_ERROR.length()));
+            } else if (args[i].startsWith(Constants.HALT_ON_FAILURE)) {
+                haltFail = Project.toBoolean(args[i].substring(Constants.HALT_ON_FAILURE.length()));
+            } else if (args[i].startsWith(Constants.FILTERTRACE)) {
+                stackfilter = Project.toBoolean(args[i].substring(Constants.FILTERTRACE.length()));
+            } else if (args[i].startsWith(Constants.CRASHFILE)) {
+                crashFile = args[i].substring(Constants.CRASHFILE.length());
+                registerTestCase(Constants.BEFORE_FIRST_TEST);
+            } else if (args[i].startsWith(Constants.FORMATTER)) {
                 try {
-                    createAndStoreFormatter(args[i].substring(10));
+                    createAndStoreFormatter(args[i].substring(Constants.FORMATTER.length()));
                 } catch (BuildException be) {
                     System.err.println(be.getMessage());
                     System.exit(ERRORS);
                 }
-            } else if (args[i].startsWith("propsfile=")) {
+            } else if (args[i].startsWith(Constants.PROPSFILE)) {
                 FileInputStream in = new FileInputStream(args[i]
-                                                         .substring(10));
+                                                         .substring(Constants.PROPSFILE.length()));
                 props.load(in);
                 in.close();
-            } else if (args[i].startsWith("showoutput=")) {
-                showOut = Project.toBoolean(args[i].substring(11));
-            } else if (args[i].startsWith("logtestlistenerevents=")) {
-                logTestListenerEvents = Project.toBoolean(args[i].substring(22));
+            } else if (args[i].startsWith(Constants.SHOWOUTPUT)) {
+                showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length()));
+            } else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) {
+                logTestListenerEvents = Project.toBoolean(args[i].substring(Constants.LOGTESTLISTENEREVENTS.length()));
             }
         }
 
@@ -669,7 +668,7 @@
             }
         } else {
             returnCode = launch(new JUnitTest(args[0]), haltError,
-                                stackfilter, haltFail, showOut, 
+                                stackfilter, haltFail, showOut,
                                 logTestListenerEvents, props);
         }
 
@@ -708,7 +707,6 @@
             }
 
             public void startTest(Test arg0) {
-                System.out.println(this.getClass().getName() + ":" + arg0);
                 registerTestCase(JUnitVersionHelper.getTestCaseName(arg0));
             }
         });
@@ -779,7 +777,7 @@
                     pw.println(line);
                 }
             }
-        } catch (Exception IOException) {
+        } catch (Exception e) {
             return stack; // return the stack unfiltered
         }
         return sw.toString();
@@ -821,7 +819,7 @@
             FileWriter out = null;
             try {
                 out = new FileWriter(crashFile);
-                out.write("terminated successfully\n");
+                out.write(Constants.TERMINATED_SUCCESSFULLY + "\n");
                 out.flush();
             } finally {
                 if (out != null) {
@@ -853,7 +851,7 @@
     /**
      * Modifies a TestListener when running JUnit 4: treats AssertionFailedError
      * as a failure not an error.
-     * 
+     *
      * @since Ant 1.7
      */
     private TestListener wrapListener(final TestListener testListener) {
@@ -870,8 +868,8 @@
                     // We would prefer to show "failure" for things that logically are.
                     try {
                         String msg = t.getMessage();
-                        AssertionFailedError failure = msg != null ?
-                            new AssertionFailedError(msg) : new AssertionFailedError();
+                        AssertionFailedError failure = msg != null 
+                            ? new AssertionFailedError(msg) : new AssertionFailedError();
                         // To compile on pre-JDK 4 (even though this should always succeed):
                         Method initCause = Throwable.class.getMethod("initCause", new Class[]
{Throwable.class});
                         initCause.invoke(failure, new Object[] {t});



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message