Fix for issue #774. Actually running dev/core/test now from ant build.xml

Review by: jat


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@584 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/common.ant.xml b/common.ant.xml
index 71b3e1c..5c56c39 100755
--- a/common.ant.xml
+++ b/common.ant.xml
@@ -125,6 +125,7 @@
 	</presetdef>
 
 	<macrodef name="gwt.junit">
+		<!-- TODO: make this more generic / refactor so it can be used from dev/core -->
 		<attribute name="test.args" default="" />
 		<attribute name="test.out" default="" />
 		<attribute name="test.reports" default="@{test.out}/reports" />
diff --git a/dev/core/build.xml b/dev/core/build.xml
index 3c2cc93..d0ce9ac 100755
--- a/dev/core/build.xml
+++ b/dev/core/build.xml
@@ -5,6 +5,21 @@
 
 	<property name="alldeps.jar" location="${project.build}/alldeps.jar" />
 
+	<fileset id="default.tests" dir="${javac.junit.out}">
+		<include name="**/*Test.class" />
+	</fileset>
+
+	<target name="compile.tests" depends="build" description="Compiles the test code for this project">
+		<mkdir dir="${javac.junit.out}" />
+		<gwt.javac srcdir="test" destdir="${javac.junit.out}">
+			<classpath>
+				<pathelement location="${javac.out}" />
+				<pathelement location="${alldeps.jar}" />
+				<pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" />
+			</classpath>
+		</gwt.javac>
+	</target>
+
 	<target name="build.alldeps.jar" description="Merges all dependency jars into a single jar">
 		<mkdir dir="${project.build}" />
 		<gwt.jar destfile="${alldeps.jar}">
@@ -107,6 +122,36 @@
 		</gwt.checkstyle>
 	</target>
 
+	<target name="test" depends="build, compile.tests" description="Run unit tests for this project.">
+		<!-- TODO: refactor gwt.junit so it can be reused here -->
+		<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
+			<classpath>
+				<pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" />
+				<pathelement location="${gwt.tools.antlib}/ant-junit-1.6.5.jar" />
+			</classpath>
+		</taskdef>
+	
+		<echo message="Writing test results to @{test.reports} for @{test.cases}" />
+		<mkdir dir="${junit.out}/reports" />
+	
+		<echo message="${javac.out} ${javac.junit.out}" />
+		<junit dir="${junit.out}" fork="yes" printsummary="yes" haltonfailure="true">
+			<classpath>
+				<pathelement location="${javac.junit.out}" />
+				<pathelement location="${javac.out}" />
+				<pathelement location="${alldeps.jar}" />
+				<pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" />
+			</classpath>
+	
+			<formatter type="plain" />
+			<formatter type="xml" />
+	
+			<batchtest todir="${junit.out}/reports">
+				<fileset refid="default.tests" />
+			</batchtest>
+		</junit>
+	</target>
+
 	<target name="clean" description="Cleans this project's intermediate and output files">
 		<delete dir="${project.build}" />
 		<delete file="${project.lib}" />
diff --git a/dev/core/test/com/google/gwt/dev/typeinfo/test/InteractiveTypeOracle.java b/dev/core/test/com/google/gwt/dev/typeinfo/test/InteractiveTypeOracle.java
index bda64cb..0e639e7 100644
--- a/dev/core/test/com/google/gwt/dev/typeinfo/test/InteractiveTypeOracle.java
+++ b/dev/core/test/com/google/gwt/dev/typeinfo/test/InteractiveTypeOracle.java
@@ -50,11 +50,12 @@
     // See if we should create a gui logger.
     //
     for (int i = 0; i < args.length; i++) {
-      if ("-gui".equals(args[i])) {
-        logger = TreeLoggerWidget.getAsDetachedWindow(
-          "Interactive Type Oracle Log", 700, 600, true);
-        break;
-      }
+      // TODO: this was removed to avoid making an SWT dependency from test code
+      // if ("-gui".equals(args[i])) {
+      // logger = TreeLoggerWidget.getAsDetachedWindow(
+      // "Interactive Type Oracle Log", 700, 600, true);
+      // break;
+      // }
     }
 
     if (logger == null) {
@@ -132,7 +133,7 @@
 
     if (currType == null && handler.requiresCurrentType()) {
       logger.log(TreeLogger.WARN,
-        "This command requires a current type to be selected", null);
+          "This command requires a current type to be selected", null);
       return false;
     }
 
@@ -198,8 +199,7 @@
       for (int i = 0; i < cmdTokens.length; i++) {
         String cmdToken = cmdTokens[i];
         if (sublogger == null) {
-          sublogger = logger
-            .branch(TreeLogger.INFO, "Available commands", null);
+          sublogger = logger.branch(TreeLogger.INFO, "Available commands", null);
         }
         sublogger.log(TreeLogger.INFO, cmdToken, null);
       }
@@ -233,7 +233,7 @@
 
       currType = type;
       logger.log(TreeLogger.INFO, "Current type is now "
-        + type.getQualifiedSourceName(), null);
+          + type.getQualifiedSourceName(), null);
       return true;
     }
 
@@ -253,7 +253,7 @@
         logger.log(TreeLogger.WARN, "No arguments expected", null);
         logger.log(TreeLogger.INFO, "Usage: subtypes", null);
         logger.log(TreeLogger.INFO, "Prints all subtypes of the current type",
-          null);
+            null);
         return false;
       }
 
@@ -265,10 +265,10 @@
       for (int i = 0; i < subtypes.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Subtypes of " + typename,
-            null);
+              null);
         }
         sublogger.log(TreeLogger.INFO, subtypes[i].getQualifiedSourceName(),
-          null);
+            null);
       }
 
       return true;
@@ -290,7 +290,7 @@
         logger.log(TreeLogger.WARN, "No arguments expected", null);
         logger.log(TreeLogger.INFO, "Usage: fields", null);
         logger.log(TreeLogger.INFO, "Prints the fields of the current type",
-          null);
+            null);
         return false;
       }
 
@@ -301,7 +301,7 @@
       for (int i = 0; i < fields.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Fields of " + typename,
-            null);
+              null);
         }
         sublogger.log(TreeLogger.INFO, fields[i].toString(), null);
       }
@@ -325,7 +325,7 @@
         logger.log(TreeLogger.WARN, "No arguments expected", null);
         logger.log(TreeLogger.INFO, "Usage: methods", null);
         logger.log(TreeLogger.INFO, "Prints the methods of the current type",
-          null);
+            null);
         return false;
       }
 
@@ -336,7 +336,7 @@
       for (int i = 0; i < methods.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Methods of " + typename,
-            null);
+              null);
         }
         sublogger.log(TreeLogger.INFO, methods[i].toString(), null);
       }
@@ -360,7 +360,7 @@
         logger.log(TreeLogger.WARN, "No arguments expected", null);
         logger.log(TreeLogger.INFO, "Usage: nested", null);
         logger.log(TreeLogger.INFO,
-          "Prints the nested types of the current type", null);
+            "Prints the nested types of the current type", null);
         return false;
       }
 
@@ -371,7 +371,7 @@
       for (int i = 0; i < nestedTypes.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Types nested inside "
-            + typename, null);
+              + typename, null);
         }
         sublogger.log(TreeLogger.INFO, nestedTypes[i].toString(), null);
       }
@@ -414,7 +414,7 @@
         logger.log(TreeLogger.WARN, "Bad arguments " + mushed, e);
       } catch (TypeOracleException e) {
         logger.log(TreeLogger.WARN,
-          "Some other type oracle exception while parsing " + mushed, e);
+            "Some other type oracle exception while parsing " + mushed, e);
       }
 
       return true;
@@ -436,14 +436,14 @@
         logger.log(TreeLogger.WARN, "No arguments", null);
         logger.log(TreeLogger.INFO, "Usage: enclosing", null);
         logger.log(TreeLogger.INFO,
-          "Prints the enclosing type of the current type", null);
+            "Prints the enclosing type of the current type", null);
         return false;
       }
 
       JClassType enclosingType = currType.getEnclosingType();
       if (enclosingType != null) {
         logger.log(TreeLogger.INFO, enclosingType.getQualifiedSourceName(),
-          null);
+            null);
       }
 
       return true;
@@ -465,7 +465,7 @@
         logger.log(TreeLogger.WARN, "No arguments", null);
         logger.log(TreeLogger.INFO, "Usage: ctors", null);
         logger.log(TreeLogger.INFO,
-          "Prints the constructors of the current type", null);
+            "Prints the constructors of the current type", null);
         return false;
       }
 
@@ -476,7 +476,7 @@
       for (int i = 0; i < ctors.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Constructors of "
-            + typename, null);
+              + typename, null);
         }
         sublogger.log(TreeLogger.INFO, ctors[i].toString(), null);
       }
@@ -500,8 +500,8 @@
         logger.log(TreeLogger.WARN, "One argument is expected", null);
         logger.log(TreeLogger.INFO, "Usage: overloads <method-name>", null);
         logger.log(TreeLogger.INFO,
-          "Prints the overloads of a particular method in the current type",
-          null);
+            "Prints the overloads of a particular method in the current type",
+            null);
         return false;
       }
 
@@ -512,7 +512,7 @@
       for (int i = 0; i < overloads.length; i++) {
         if (sublogger == null) {
           sublogger = logger.branch(TreeLogger.INFO, "Overloads in " + typename
-            + " of " + args[0], null);
+              + " of " + args[0], null);
         }
         sublogger.log(TreeLogger.INFO, overloads[i].toString(), null);
       }
@@ -535,13 +535,12 @@
         logger.log(TreeLogger.WARN, "No arguments", null);
         logger.log(TreeLogger.INFO, "Usage: supertypes", null);
         logger.log(TreeLogger.INFO,
-          "Prints the hierarchy of supertypes of the current type", null);
+            "Prints the hierarchy of supertypes of the current type", null);
         return false;
       }
 
       String typename = currType.getQualifiedSourceName();
-      logger = logger
-        .branch(TreeLogger.INFO, "Supertypes of " + typename, null);
+      logger = logger.branch(TreeLogger.INFO, "Supertypes of " + typename, null);
       printSupertypesImpl(logger, currType);
       return true;
     }