[jboss-cvs] JBossAS SVN: r94210 - in projects/jboss-osgi/projects/aQute/trunk/aQute.runtime: src/main/java/aQute/junit/runtime and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 1 06:02:28 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-01 06:02:28 -0400 (Thu, 01 Oct 2009)
New Revision: 94210

Modified:
   projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/scripts/assembly-ant-junit.xml
   projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/src/main/java/aQute/junit/runtime/Target.java
Log:
Remove the notion of flattened test suite.

Modified: projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/scripts/assembly-ant-junit.xml
===================================================================
--- projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/scripts/assembly-ant-junit.xml	2009-10-01 09:58:16 UTC (rev 94209)
+++ projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/scripts/assembly-ant-junit.xml	2009-10-01 10:02:28 UTC (rev 94210)
@@ -29,10 +29,12 @@
           <include>org/apache/tools/ant/taskdefs/optional/junit/BaseTest.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitResultFormatter.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror.class</include>
-          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror$JUnitResultFormatterMirror.class</include>
-          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl$VmExitErrorTest.class</include>
+          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror$*.class</include>
+          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.class</include>
+          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl$*.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class</include>
+          <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner$*.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.class</include>
           <include>org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.class</include>

Modified: projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/src/main/java/aQute/junit/runtime/Target.java
===================================================================
--- projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/src/main/java/aQute/junit/runtime/Target.java	2009-10-01 09:58:16 UTC (rev 94209)
+++ projects/jboss-osgi/projects/aQute/trunk/aQute.runtime/src/main/java/aQute/junit/runtime/Target.java	2009-10-01 10:02:28 UTC (rev 94210)
@@ -11,6 +11,7 @@
 import java.util.Properties;
 
 import junit.framework.Test;
+import junit.framework.TestCase;
 import junit.framework.TestResult;
 import junit.framework.TestSuite;
 
@@ -129,106 +130,105 @@
     /**
      * Main test routine.
      * 
-     * @param tl
+     * @param testSuiteReport
      * @param framework
      * @param targetBundle
      * @param testNames
      * @return
      * @throws Throwable
      */
-    private int doTesting(TestReporter tl) throws Throwable {
-        if (framework.activate()) {
-            boolean report = properties.containsKey("report");
-            if (report)
-                framework.report(System.out);
+    private int doTesting(TestReporter testSuiteReport) throws Throwable {
+        if (framework.activate() == false)
+            throw new IllegalStateException("Framework does not activate");
+        	
+        boolean report = properties.containsKey("report");
+        if (report)
+            framework.report(System.out);
 
-            Bundle targetBundle = framework.getBundle(target);
-            if (targetBundle == null)
-                throw new IllegalArgumentException("No target specified");
+        Bundle targetBundle = framework.getBundle(target);
+        if (targetBundle == null)
+            throw new IllegalArgumentException("No target specified");
 
-            // Verify if we have any test names set
-            if (testNames.size() == 0)
-                checkTestCases(targetBundle);
+        // Verify if we have any test names set
+        if (testNames.size() == 0)
+            checkTestCases(targetBundle);
 
-            if (testNames.size() == 0) {
-                System.out
-                        .println("No test cases to run, waiting for the framework to quit");
-                framework.waitForStop(0);
-                System.out.println("And the framework is gone!");
-                return 0;
-            }
+        if (testNames.size() == 0) {
+            System.out
+                    .println("No test cases to run, waiting for the framework to quit");
+            framework.waitForStop(0);
+            System.out.println("And the framework is gone!");
+            return 0;
+        }
 
-            BasicTestReport otl = new BasicTestReport();
-            TestResult result = new TestResult();
-            try {
-                TestSuite suite = createSuite(targetBundle, testNames);
-                List flattened = new ArrayList();
-                int realcount = flatten(flattened, suite);
-                tl.begin(framework, targetBundle, flattened, realcount);
-                otl.begin(framework, targetBundle, flattened, realcount);
-                result.addListener(tl);
-                result.addListener(otl);
+        int allErrors = 0;
+        
+        TestSuite suite = createSuite(targetBundle, testNames);
+        testSuiteReport.begin(framework, targetBundle, null, suite.countTestCases());
+        
+        try {
+            Enumeration tests = suite.tests();
+            while (tests.hasMoreElements())
+            {
+            	Test test = (Test) tests.nextElement();
+            	
+                TestResult result = new TestResult();
                 
+                // Note, this also sets the BundleContext
+                BasicTestReport basicReport = new BasicTestReport();
+                result.addListener(basicReport);
+                result.addListener(testSuiteReport);
+                
+                // Get the test name
+            	String testName = null;
+            	if (test instanceof TestSuite)
+            		testName = ((TestSuite)test).getName();
+            	else if (test instanceof TestCase)
+            		testName = ((TestCase)test).getName();
+                
                 // Add the standard plain and xml formatters 
-                String testSuiteName = getTestSuiteName();
                 String reportDir = new File(reportName).getParentFile() + "/test-reports";
                 List<JUnitResultFormatter> formatters = new ArrayList<JUnitResultFormatter>();
-                formatters.add(new XMLResultFormatter(reportDir, testSuiteName));
-                formatters.add(new PlainResultFormatter(reportDir, testSuiteName));
+                formatters.add(new XMLResultFormatter(reportDir, testName));
+                formatters.add(new PlainResultFormatter(reportDir, testName));
                 for (JUnitResultFormatter formatter : formatters) 
                     result.addListener(formatter);
                 
-				JUnitTest junitTest = new JUnitTest(testSuiteName);
+				JUnitTest junitTest = new JUnitTest(testName);
                 junitTest.setProperties(System.getProperties());
                 
+                // Start the report formatters
                 long startTime = System.currentTimeMillis();
                 fireStartTestSuite(formatters, junitTest);
+                basicReport.begin(framework, targetBundle, null, test.countTestCases());
+                
                 try {
-					suite.run(result);
+                	
+                	// Run the test
+					test.run(result);
+					
 				} finally {
-	                junitTest.setCounts(realcount, result.failureCount(), result.errorCount());
+					
+	                // End the report formatters
+	                junitTest.setCounts(test.countTestCases(), result.failureCount(), result.errorCount());
 	                junitTest.setRunTime(System.currentTimeMillis() - startTime);
 	                fireEndTestSuite(formatters, junitTest);
+	                basicReport.end();
 				}
-				
-                if (result.wasSuccessful())
-                    return 0;
-                else
-                    return result.errorCount();
-            } catch (Throwable t) {
-                result.addError(null, t);
-                throw t;
-            } finally {
-                tl.end();
-                otl.end();
-                if (properties.containsKey("wait")) {
-                    framework.waitForStop(10000000);
-                }
-                framework.deactivate();
+            	
+            	allErrors += result.errorCount();
             }
-        } else
-            throw new IllegalStateException("Framework does not activate");
-    }
-
-    private String getTestSuiteName() {
-		String name = new File(target).getName();
-		int dashIndex = name.indexOf("-");
-		if (dashIndex > 0)
-			name = name.substring(0, dashIndex);
-		return name;
-	}
-
-	private int flatten(List list, TestSuite suite) {
-        int realCount = 0;
-        for (Enumeration e = suite.tests(); e.hasMoreElements();) {
-            Test test = (Test) e.nextElement();
-            list.add(test);
-            if (test instanceof TestSuite)
-                realCount += flatten(list, (TestSuite) test);
-            else
-                realCount++;
+			
+            return allErrors;
+            
+        } finally {
+            testSuiteReport.end();
+            
+            if (properties.containsKey("wait")) {
+                framework.waitForStop(10000000);
+            }
+            framework.deactivate();
         }
-        return realCount;
     }
 
     private void fireStartTestSuite(List<JUnitResultFormatter> formatters, JUnitTest junitTest) {




More information about the jboss-cvs-commits mailing list