]> source.dussan.org Git - aspectj.git/commitdiff
Reimplemented JUnit harness adapter
authorwisberg <wisberg>
Sun, 17 Aug 2003 18:56:46 +0000 (18:56 +0000)
committerwisberg <wisberg>
Sun, 17 Aug 2003 18:56:46 +0000 (18:56 +0000)
testing-drivers/testsrc/org/aspectj/testing/drivers/AjcHarnessTestsUsingJUnit.java [new file with mode: 0644]
testing-drivers/testsrc/org/aspectj/testing/drivers/AjcTestsUsingJUnit.java [new file with mode: 0644]
testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java [new file with mode: 0644]
testing-drivers/testsrc/org/aspectj/testing/drivers/DriversTests.java
testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java [new file with mode: 0644]
testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java [deleted file]

diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/AjcHarnessTestsUsingJUnit.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/AjcHarnessTestsUsingJUnit.java
new file mode 100644 (file)
index 0000000..009f266
--- /dev/null
@@ -0,0 +1,47 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Wes Isberg     initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.drivers;
+
+import junit.framework.*;
+
+/*
+ * Run harness tests as JUnit test suites.
+ */
+public class AjcHarnessTestsUsingJUnit extends TestCase {
+
+    /**
+     * Create TestSuite with harness validation tests.
+     * @return Test with all TestSuites and TestCases
+     *         for the harness itself.
+     */
+    public static TestSuite suite() {
+        TestSuite result = HarnessJUnitUtil.suite(null, null, null);
+        result.addTest(
+            HarnessJUnitUtil.suite("harness", 
+                new String[] {"../tests/ajcHarnessTests.xml"},
+                new String[][] { 
+                    new String[] {"-ajctestSkipKeywords=expect-fail"}
+                    }
+                ));
+        result.addTest(
+            HarnessJUnitUtil.suite("harness selection tests", 
+                new String[] {"testdata/incremental/harness/selectionTest.xml"},
+                null
+                ));
+        return result;
+    }
+        
+       public AjcHarnessTestsUsingJUnit(String name) {
+               super(name);
+       }
+}
diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/AjcTestsUsingJUnit.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/AjcTestsUsingJUnit.java
new file mode 100644 (file)
index 0000000..06613bb
--- /dev/null
@@ -0,0 +1,48 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Wes Isberg     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.testing.drivers;
+
+import junit.framework.*;
+
+/**
+ * Run ajc tests as JUnit test suites.
+ * This class is named to avoid automatic inclusion in 
+ * most JUnit test runs.
+ */
+public class AjcTestsUsingJUnit extends TestCase {
+    private static final String[] SUITES = new String[]
+        { "../tests/ajcTestsFailing.xml",
+         "../tests/ajcTests.xml"
+        };
+
+    private static final String SKIPS = 
+        "-ajctestSkipKeywords=purejava,knownLimitation";
+    private static final String[][] OPTIONS = new String[][]
+        { new String[] { SKIPS },
+          new String[] { SKIPS, "-emacssym" }
+        };
+     
+    /**
+     * Create TestSuite with all SUITES running all OPTIONS.
+     * @return Test with all TestSuites and TestCases
+     *         specified in SUITES and OPTIONS.
+     */
+    public static Test suite() {
+        String name = AjcTestsUsingJUnit.class.getName();
+        return HarnessJUnitUtil.suite(name, SUITES, OPTIONS);
+    }
+        
+       public AjcTestsUsingJUnit(String name) {
+               super(name);
+       }
+}
diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java
new file mode 100644 (file)
index 0000000..da0c42f
--- /dev/null
@@ -0,0 +1,245 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Wes Isberg     initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.drivers;
+
+import java.io.*;
+import java.util.*;
+
+import junit.framework.*;
+
+import org.aspectj.bridge.*;
+import org.aspectj.testing.harness.bridge.*;
+import org.aspectj.testing.run.*;
+import org.aspectj.testing.util.RunUtils;
+import org.aspectj.testing.xml.AjcSpecXmlReader;
+
+/*
+ * Adapt Harness tests to JUnit driver.
+ * This renders suite files as TestSuite
+ * and AjcTest as TestCase.
+ * When run, aborts are reported as error
+ * and fails as failures, with all messages stuffed
+ * into the one JUnit exception message.
+ * Test options are supported, but no harness options.
+ * The TestSuite implementation prevents us
+ * from re-running tests.
+ * In the Eclipse JUnit test runner,
+ * the tests display hierarchically and with annotations 
+ * and with messages.  You can stop the tests, but not
+ * traverse to the source or re-run the test.
+ */
+public class AjctestsAdapter extends TestSuite {
+    public static final String VERBOSE_NAME =
+        AjctestsAdapter.class.getName() + ".VERBOSE";
+    
+    private static final boolean VERBOSE
+        = HarnessJUnitUtil.readBooleanSystemProperty(VERBOSE_NAME);
+        
+    /**
+     * Factory to make and populate suite without options.
+     * @param suitePath the String path to a harness suite file
+     * @return AjctestJUnitSuite populated with tests
+     */
+    public static AjctestsAdapter make(String suitePath) {
+        return make(suitePath, null);
+    }
+
+    /**
+     * Factory to make and populate suite
+     * @param suitePath the String path to a harness suite file
+     * @param options the String[] options to use when creating tests
+     * @return AjctestJUnitSuite populated with tests
+     */
+    public static AjctestsAdapter make(String suitePath, String[] options) {
+        AjctestsAdapter result = new AjctestsAdapter(suitePath, options);
+        AjcTest.Spec[] tests = AjcTest.Suite.getTests(result.getSpec());
+        if (VERBOSE) {
+            log("loading " + tests.length + " tests in " + suitePath);
+        }
+        for (int i = 0; i < tests.length; i++) {
+            AjcTest.Spec ajcTest = (AjcTest.Spec) tests[i];
+            result.addTest(new AjcTestSpecAsTest(ajcTest, result));
+        }
+        return result;
+    }
+    
+    private static void log(String message) {
+        System.err.println(message);
+        System.err.flush();
+    }
+
+    private final String suitePath;
+    private final String[] options;
+    private AjcTest.Suite.Spec spec;
+    private Runner runner;
+    private Validator validator;
+    private IMessageHolder holder;
+    private Sandbox sandbox;
+    private File suiteDir;
+    private String name;
+
+    private AjctestsAdapter(String suitePath, String[] options) { 
+        this.suitePath = suitePath;
+        String[] opts = new String[0];
+        if (!HarnessJUnitUtil.isEmpty(options)) {
+            opts = new String[options.length];
+            System.arraycopy(options, 0, opts, 0, opts.length);
+        }
+        this.options = opts;
+    }
+
+    public void addTest(Test test) {
+        if (! (test instanceof AjcTestSpecAsTest)) {
+            String m = "expecting AjcTestSpecAsTest, got "
+                + (null == test 
+                    ? "null test" 
+                    : test.getClass().getName() + ": " + test);
+            throw new IllegalArgumentException(m);
+        }
+        super.addTest(test);
+    }
+
+    public void addTestSuite(Class testClass) {
+        throw new Error("unimplemented");
+    }
+    
+    public String getName() {
+        if (null == name) {
+            name = HarnessJUnitUtil.cleanTestName(suitePath + Arrays.asList(options));
+        }
+        return name;
+    }
+                
+    /**
+     * Callback from test to run it using suite-wide holder, etc.
+     * The caller is responsible for calling 
+     * result.startTest(test) and result.endTest(test);
+     * @param test the AjcTestSpecAsTest to run
+     * @param result the TestResult for any result messages
+     */
+    protected void runTest(AjcTestSpecAsTest test, TestResult result) {
+        final Runner runner = getRunner();
+        final Sandbox sandbox = getSandbox();
+        final Validator validator = getValidator();
+        int numIncomplete = 0;
+        final RunStatus status = new RunStatus(new MessageHandler(), runner);
+        status.setIdentifier(test.toString());
+        try {
+            IMessageHolder holder = getHolder();
+            holder.clearMessages();
+            IRunIterator steps = test.spec.makeRunIterator(sandbox, validator);
+            if (0 < holder.numMessages(IMessage.ERROR, true)) {
+                MessageUtil.handleAll(status, holder, IMessage.INFO, true, false);
+            } else {
+                runner.runIterator(steps, status, null);
+            }
+            if (steps instanceof RunSpecIterator) {
+                numIncomplete = ((RunSpecIterator) steps).getNumIncomplete();
+            }
+        } finally {
+            HarnessJUnitUtil.reportResult(result, status, test, numIncomplete);
+            validator.deleteTempFiles(true);
+        }
+    }
+
+    private File getSuiteDir() {
+        if (null == suiteDir) {
+            File file = new File(suitePath);
+            file = file.getParentFile();
+            if (null == file) {
+                file = new File(".");
+            }
+            suiteDir = file;
+        }
+        return suiteDir;
+    }
+
+    private Validator getValidator() {
+        if (null == validator) {
+            validator = new Validator(getHolder());
+            // XXX lock if keepTemp?
+        }
+        return validator;
+    }
+
+    private Runner getRunner() {
+        if (null == runner) {
+            runner = new Runner();
+        }
+        return runner;
+    }
+
+    private IMessageHolder getHolder() {
+        if (null == holder) {
+            holder = new MessageHandler();
+        }
+        return holder;
+    }
+
+    private AjcTest.Suite.Spec getSpec() {
+        if (null == spec) {
+            IMessageHolder holder = getHolder();
+            spec = HarnessJUnitUtil.getSuiteSpec(suitePath, options, getHolder());
+            if (VERBOSE && holder.hasAnyMessage(null, true)) {
+                MessageUtil.print(System.err, holder, "skip ", 
+                    MessageUtil.MESSAGE_MOST);
+            }
+            holder.clearMessages();
+        }
+        return spec; 
+    }
+    
+    private Sandbox getSandbox() {
+        if (null == sandbox) {
+            sandbox = new Sandbox(spec.getSuiteDirFile(), getValidator());
+        }
+        return sandbox;
+    }
+
+    /** Wrap AjcTest.Spec as a TestCase. Run by delegation to suite */
+    private static class AjcTestSpecAsTest extends TestCase {
+        // this could implement Test, but Ant batchtest fails to pull name 
+        final String name;
+        final AjcTest.Spec spec;
+        AjctestsAdapter suite;
+        AjcTestSpecAsTest(AjcTest.Spec spec, AjctestsAdapter suite) {
+            super(HarnessJUnitUtil.cleanTestName(spec.getDescription()));
+            this.name = HarnessJUnitUtil.cleanTestName(spec.getDescription());
+            this.suite = suite;
+            this.spec = spec;
+            spec.setSuiteDir(suite.getSuiteDir());
+        }
+        public int countTestCases() {
+            return 1;
+        }
+        public void run(TestResult result) {
+            if (null == suite) {
+                throw new Error("need to re-init");
+            }
+            try {
+                result.startTest(this);
+                suite.runTest(this, result); 
+            } finally {
+                result.endTest(this);
+                suite = null;
+            }
+        }
+
+        public String getName() {
+            return name;
+        }
+        public String toString() {
+            return name;
+        }
+    }
+}
index 5182b3175a006f2c532471bddeae8547bf3f8b0e..e93429868bf08f7690c3e9e9f6c353e46ce59334 100644 (file)
@@ -1,6 +1,7 @@
 /* *******************************************************************
  * Copyright (c) 1999-2001 Xerox Corporation, 
- *               2002 Palo Alto Research Center, Incorporated (PARC).
+ *               2002 Palo Alto Research Center, Incorporated (PARC)
+ *               2003 Contributors.
  * All rights reserved. 
  * This program and the accompanying materials are made available 
  * under the terms of the Common Public License v1.0 
@@ -9,6 +10,7 @@
  *  
  * Contributors: 
  *     Xerox/PARC     initial implementation 
+ *     Wes Isberg     added JUnit harness adapters
  * ******************************************************************/
 
 
@@ -20,9 +22,10 @@ public class DriversTests extends TestCase {
 
     public static Test suite() { 
         TestSuite suite = new TestSuite(DriversTests.class.getName());
-        // for now, do not include SuiteTest because it would take 15 minutes
+        // AjcTestsUsingJUnit takes too long to include by default
         //$JUnit-BEGIN$
         suite.addTestSuite(HarnessSelectionTest.class); 
+        suite.addTest(AjcHarnessTestsUsingJUnit.suite()); 
         //$JUnit-END$
         return suite;
     }
diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java
new file mode 100644 (file)
index 0000000..17eef7c
--- /dev/null
@@ -0,0 +1,267 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Wes Isberg     initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.drivers;
+
+import java.io.*;
+import java.util.*;
+
+import junit.framework.*;
+
+import org.aspectj.bridge.*;
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.testing.harness.bridge.*;
+import org.aspectj.testing.run.IRunStatus;
+import org.aspectj.testing.util.RunUtils;
+import org.aspectj.testing.util.RunUtils.IRunStatusPrinter;
+import org.aspectj.testing.xml.AjcSpecXmlReader;
+
+/**
+ * Utilities for adapting AjcTest.{Suite.}Spec to JUnit.
+ */
+public class HarnessJUnitUtil {
+    /** bug?: eclipse RemoteTestRunner hangs if n>1 */
+    public static final boolean ONE_ERROR_PER_TEST = true;
+    public static final boolean FLATTEN_RESULTS = true;
+    public static final boolean PRINT_OTHER_MESSAGES = false;
+
+    /**
+     * Create TestSuite with all suites running all options.
+     * @param suites the String[] of paths to harness test suite files
+     * @param options the String[][] of option sets to run (may be null)
+     * @return Test with all TestSuites and TestCases
+     *         specified in suites and options.
+     */
+    public static TestSuite suite(String name, String[] suites, String[][] options) {
+        if (null == name) {
+            name = AjcHarnessTestsUsingJUnit.class.getName();
+        }
+        TestSuite suite = new TestSuite(name);
+        if (!HarnessJUnitUtil.isEmpty(suites)) {
+            if (HarnessJUnitUtil.isEmpty(options)) {
+                options = new String[][] {new String[0]};
+            }
+            for (int i = 0; i < suites.length; i++) {
+                for (int j = 0; j < options.length; j++) {
+                    Test t = AjctestsAdapter.make(suites[i], options[j]);
+                    suite.addTest(t);
+                }
+            }
+        }
+        return suite;
+    }
+
+    public static boolean isEmpty(Object[] ra) {
+        return ((null == ra) || (0 == ra.length));
+    }
+    /**
+     * Render status using a given printer.
+     * @param status the IRunStatus to render to String
+     * @param printer the IRunStatusPrinter to use
+     *        (defaults to AJC_PRINTER if null)
+     * @return the String rendering of the status,
+     *         or "((IRunStatus) null)" if null
+     */
+    public static String render(IRunStatus status, IRunStatusPrinter printer) {
+        if (null == status) {
+            return "((IRunStatus) null)";
+        }
+        if (null == printer) {
+            printer = RunUtils.AJC_PRINTER;
+        }
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+        PrintStream out = new PrintStream(outStream);
+        printer.printRunStatus(out, status);
+        out.flush();
+          
+        return outStream.toString();
+    }
+    
+    /**
+     * Dump results for Test from status into TestResult.
+     * This defers to the status to determine if it failed,
+     * and treats ABORT as errors 
+     * and everything else as failures.
+     * @param result the TestResult sink
+     * @param status the IRunStatus source
+     * @param test the Test to associate with the results
+     * @param numIncomplete ignored
+     * @return 0 (ignored)
+     */
+    public static int reportResult(
+            TestResult result, 
+            IRunStatus status,
+            Test test,
+            int numIncomplete) {
+      if (!status.runResult()) {
+          String m = render(status, null);
+          AssertionFailedError failure = new AssertionFailedError(m);
+          if (status.hasAnyMessage(IMessage.ABORT, true)) {
+              result.addError(test, failure);
+          } else {
+              result.addFailure(test, failure);
+          }
+      }
+      return 0; // XXX not doing incomplete
+    }
+    
+//    public static int reportResultComplex(
+//        TestResult result, 
+//        IRunStatus status,
+//        Test test,
+//        int numIncomplete) {
+//        int errs = 0;
+//        if (FLATTEN_RESULTS) {
+//            IRunStatus[] kids = status.getChildren();
+//            for (int i = 0; i < kids.length; i++) {
+//                errs += reportResult(result, kids[i], test, 0);
+//                if ((errs > 0) && ONE_ERROR_PER_TEST) {
+//                    return errs;
+//                }
+//            }
+//        }
+//            
+//        Throwable thrown = status.getThrown();
+//        if (null != thrown) { // always report this? XXX what if expected?
+//            result.addError(test, thrown);
+//            errs++;
+//        }
+//        boolean previewPass = status.runResult();
+//        IMessage[] errors = status.getMessages(null, true);
+//        for (int i = 0; ((errs == 0) || !ONE_ERROR_PER_TEST)
+//                        && i < errors.length; i++) {
+//            IMessage message = errors[i];
+//            if (message.isAbort()) {
+//                result.addError(test, new ErrorMessage(message));
+//                errs++;
+//            } else if (message.isFailed()) {
+//                result.addFailure(test, new ErrorMessage(message));
+//                errs++;
+//            } else if (PRINT_OTHER_MESSAGES || !previewPass) {
+//                System.out.println("#### message for " + test + ": ");
+//                System.out.println(message);
+//            }
+//        }
+//        if (((errs == 0) || !ONE_ERROR_PER_TEST)
+//            && ((errs == 0) != status.runResult())) {
+//            String s = "expected pass=" + (errs == 0);
+//            result.addFailure(test, new ErrorMessage(s));
+//            errs++;
+//        }
+//        if (((errs == 0) || !ONE_ERROR_PER_TEST)
+//            && !status.isCompleted()) {
+//            result.addFailure(test, new ErrorMessage("test incomplete? "));
+//            errs++;
+//        }
+//        if (((errs == 0) || !ONE_ERROR_PER_TEST)
+//            && (0 < numIncomplete)) {
+//            result.addFailure(test, new ErrorMessage("incomplete steps: " + numIncomplete));
+//            errs++;
+//        }
+//        return errs;
+//    }
+
+    /**
+     * Fix up test names for JUnit.
+     * (i.e., workaround eclipse JUnit bugs)
+     * @param name the String identifier for the test
+     * @return the String permitted by (Eclipse) JUnit support
+     */
+    public static String cleanTestName(String name) { 
+        name = name.replace(',', ' ');
+        name = name.replace('[', ' ');
+        name = name.replace(']', ' ');
+        name = name.replace('-', ' ');
+        return name;
+    }
+
+    public static boolean readBooleanSystemProperty(String name) {
+        boolean result = false;
+        try {
+            String value = System.getProperty(name);
+            if (null != value) {
+                // XXX convert using Boolean?
+                value = value.toLowerCase();
+                result = ("true".equals(value) || "on".equals(value));
+            }
+        } catch (Throwable t) {
+            // ignore
+        }
+        return result;
+    }
+    
+    /**
+     * Get the test suite specifications from the suite file,
+     * apply the options to all,
+     * and report any messages to the holder.
+     * @param suitePath the String path to the harness suite file
+     * @param options the String[] options for the tests - may be null
+     * @param holder the IMessageHolder for any messages - may be null
+     * @return AjcTest.Suite.Spec test descriptions
+     *   (non-null but empty if some error)
+     */
+    public static AjcTest.Suite.Spec getSuiteSpec(
+            String suitePath, 
+            String[] options,
+            IMessageHolder holder) {
+        if (null == suitePath) {
+            MessageUtil.fail(holder, "null suitePath");
+            return EmptySuite.ME;
+        }
+        File suiteFile = new File(suitePath);
+        if (!suiteFile.canRead() || !suiteFile.isFile()) {
+            MessageUtil.fail(holder, "unable to read file " + suitePath);
+            return EmptySuite.ME;
+        }
+        try {
+            AjcTest.Suite.Spec tempSpec;
+            AbstractRunSpec.RT runtime = new AbstractRunSpec.RT();
+            tempSpec = AjcSpecXmlReader.getReader().
+                        readAjcSuite(suiteFile);
+            tempSpec.setSuiteDirFile(suiteFile.getParentFile());
+            if (null == options) {
+                options = new String[0];
+            }
+            runtime.setOptions(options);
+            boolean skip = !tempSpec.adoptParentValues(runtime, holder);                
+            if (skip) {
+                tempSpec = EmptySuite.ME;
+            }
+            return tempSpec;
+        } catch (IOException e) {
+            MessageUtil.abort(holder, "IOException", e);
+            return EmptySuite.ME;
+        }
+    }
+    
+    private static class EmptySuite extends AjcTest.Suite.Spec {
+        static final EmptySuite ME = new EmptySuite();
+        final ArrayList children;
+        private EmptySuite(){
+            children = new ArrayList() {
+                // XXX incomplete...
+                public void add(int arg0, Object arg1) { fail();}
+                public boolean addAll(int arg0, Collection arg1) { return fail();}
+                public boolean addAll(Collection o) { return fail(); }
+                public boolean add(Object o) { return fail(); }
+                public boolean remove(Object o) { return fail(); }
+                private boolean fail() {
+                    throw new Error("unmodifiable");
+                }
+            };
+        }
+        public ArrayList getChildren() {
+            return children;
+        }
+    }
+}
+
diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java
deleted file mode 100644 (file)
index be12344..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation, 
- *               2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Common Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://www.eclipse.org/legal/cpl-v10.html 
- *  
- * Contributors: 
- *     Xerox/PARC     initial implementation 
- * ******************************************************************/
-
-package org.aspectj.testing.drivers;
-
-import org.aspectj.bridge.IMessageHolder;
-import org.aspectj.bridge.MessageHandler;
-import org.aspectj.bridge.MessageUtil;
-import org.aspectj.testing.harness.bridge.AbstractRunSpec;
-import org.aspectj.testing.harness.bridge.AjcTest;
-import org.aspectj.testing.harness.bridge.Sandbox;
-import org.aspectj.testing.harness.bridge.Validator;
-import org.aspectj.testing.run.IRun;
-import org.aspectj.testing.run.IRunIterator;
-import org.aspectj.testing.run.RunStatus;
-import org.aspectj.testing.run.Runner;
-import org.aspectj.testing.util.RunUtils;
-import org.aspectj.util.LangUtil;
-
-import java.io.File;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-
-/**
- * 
- */
-public class SuiteTest extends TestCase {
-    private static final String[] SUITES = new String[]
-        { "../tests/ajcHarnessTests.xml",
-         "testdata/incremental/harness/selectionTest.xml",
-          "../tests/ajcTests.xml"
-        };
-        
-    public static Test suite() {
-        TestSuite suite = new TestSuite();
-        for (int i = 0; i < SUITES.length; i++) {
-            suite.addTest(JUnitSuite.suite(SUITES[i]));                        
-               }
-        return suite;
-    }
-    
-       public SuiteTest(String name) {
-               super(name);
-       }
-}
-
-/** adapt ajc test suite to JUnit TestSuite */
-class JUnitSuite extends TestSuite {
-    public static final String DEFAULT_SUITE = "../tests/ajcTests.xml";
-    public static final String[] DEFAULT_OPTIONS = new String[] 
-        { "-eclipse", "-hideStreams", "-logMinFail" };
-
-    static TestSuite suite() {
-        return suite(DEFAULT_SUITE);
-    }
-
-    static TestSuite suite(String path, String[] options, boolean verbose) {
-        return new JUnitSuite(path, options, verbose);
-    }
-
-    static TestSuite suite(String path) {
-        return new JUnitSuite(path, DEFAULT_OPTIONS, true);
-    }
-
-    private final Runner runner;
-
-    private boolean loadedTestCases;
-    
-    private JUnitSuite(String suiteFile, String[] options, boolean verbose) {
-        super(suiteFile);
-        runner = new Runner();
-        loadTestCases(suiteFile, options, verbose);
-    }
-    
-    public void runTest(Test test, TestResult result) {
-        if (!(test instanceof JUnitRunAdapter)) {
-            test.run(result);
-            return;
-        }
-        RunStatus status = new RunStatus(new MessageHandler(), runner);
-        result.startTest(test);
-        IRun testRun = ((JUnitRunAdapter) test).run;
-        try {
-            runner.run(testRun, status, null);
-            if (!status.runResult()) { 
-                RunUtils.VERBOSE_PRINTER.printRunStatus(System.out, status);
-                AssertionFailedError failure = new AssertionFailedError(""+status);
-                result.addFailure(test, failure);
-            }
-        } finally {
-            result.endTest(test);
-            if (testRun instanceof AjcTest) {
-                AjcTest ajcTest = (AjcTest) testRun;
-            }
-        }
-    }
-    
-    private void loadTestCases(String suiteFile, String[] options, boolean verbose) {
-        if (loadedTestCases) { // guard that cleanup is last
-            throw new IllegalStateException("already loaded test cases");
-        }
-        loadedTestCases = true;
-        final SuiteReader reader = new SuiteReader();
-        final Validator validator = new Validator(new MessageHandler());
-        AjcTest.Suite.Spec spec = reader.readSuite(new File(suiteFile));
-        if (null == spec) {
-            return;
-        }
-        IMessageHolder holder = new MessageHandler();
-        final AbstractRunSpec.RT parentValues = new AbstractRunSpec.RT();
-        parentValues.setOptions(options);
-        parentValues.setVerbose(verbose);
-        spec.adoptParentValues(parentValues, holder);
-        if (0 < holder.numMessages(null, true)) {
-            System.err.println("init: messages adopting options ");
-            MessageUtil.print(System.err, holder, "init: ");
-            holder = new MessageHandler();
-        }        
-        final RunStatus status = new RunStatus(holder, runner);
-        status.setIdentifier(spec);
-        final Sandbox sandbox = new Sandbox(spec.getSuiteDirFile(), validator);
-        int i = 0;
-        System.out.println("-- loading tests");
-        for (IRunIterator tests = spec.makeRunIterator(sandbox, validator);
-            tests.hasNextRun();) {
-            final IRun run = tests.nextRun(holder, runner);
-            if (0 < holder.numMessages(null, true)) {
-                System.err.println(i + ": messages loading " + run);
-                MessageUtil.print(System.err, holder, i + ": ");
-                holder = new MessageHandler();
-            } else if (null == run) {
-                System.err.println(i + ": null run ");
-            } else {
-                addTest(new JUnitRunAdapter(run));
-            }
-            System.out.print(".");
-            i++;
-            if ((i % 50) == 0) {
-                System.out.println(" -- " + i);
-            }
-        }
-        System.out.println("-- done loading tests for this suite");
-        // add a cleanup test
-        addTest(new Test() {
-            public int countTestCases() { return 1;}
-            public void run(TestResult result) {
-                result.startTest(this);
-                validator.deleteTempFiles(false);
-                result.endTest(this);
-            }
-            public String toString() { return "validator cleanup"; }
-        });
-    }
-
-    /** just opens up access, protected to public */
-    static class SuiteReader extends Harness {
-        public AjcTest.Suite.Spec readSuite(File suiteFile) {
-            return super.readSuite(suiteFile);
-        }
-
-    }
-    
-    /** non-functional wrapper for the enclosed IRun */
-    public static class JUnitRunAdapter implements Test {
-        static final UnsupportedOperationException EX =
-            new UnsupportedOperationException("");
-        
-        public final IRun run;
-        public JUnitRunAdapter(IRun run) {
-            LangUtil.throwIaxIfNull(run, "run");
-            this.run = run;
-        }
-        public final void run(TestResult result) {
-          throw EX;
-        }
-        public final int countTestCases() {
-            return 1;
-        }
-        public String toString() {
-            return run.toString();
-        }
-
-    }
-}