diff options
author | wisberg <wisberg> | 2002-12-16 21:46:19 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 21:46:19 +0000 |
commit | 31b7d84b2b4dc4ba29088947d8872027830e8fe4 (patch) | |
tree | ec64d701df1ee2d84272264b6688032f4a860f6d /testing-drivers/testsrc | |
parent | c67cb6056cbd89b1fa95ec6a1813793fa18edf16 (diff) | |
download | aspectj-31b7d84b2b4dc4ba29088947d8872027830e8fe4.tar.gz aspectj-31b7d84b2b4dc4ba29088947d8872027830e8fe4.zip |
initial versioninitial_CPL
Diffstat (limited to 'testing-drivers/testsrc')
4 files changed, 547 insertions, 0 deletions
diff --git a/testing-drivers/testsrc/TestingDriversModuleTests.java b/testing-drivers/testsrc/TestingDriversModuleTests.java new file mode 100644 index 000000000..55254beb2 --- /dev/null +++ b/testing-drivers/testsrc/TestingDriversModuleTests.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * 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 + * ******************************************************************/ + + +// default package + +import org.aspectj.testing.drivers.DriversTests; + +import junit.framework.*; +import junit.framework.Test; + +public class TestingDriversModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TestingDriversModuleTests.class.getName()); + suite.addTest(DriversTests.suite()); + return suite; + } + + public TestingDriversModuleTests(String name) { super(name); } + +} diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/DriversTests.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/DriversTests.java new file mode 100644 index 000000000..5182b3175 --- /dev/null +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/DriversTests.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * 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 junit.framework.*; + +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 + //$JUnit-BEGIN$ + suite.addTestSuite(HarnessSelectionTest.class); + //$JUnit-END$ + return suite; + } + + public DriversTests(String name) { super(name); } + +} diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java new file mode 100644 index 000000000..a167f7d87 --- /dev/null +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java @@ -0,0 +1,286 @@ +/* ******************************************************************* + * 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.IMessage; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.MessageUtil; +import org.aspectj.testing.drivers.Harness.RunResult; +import org.aspectj.testing.harness.bridge.AbstractRunSpec; +import org.aspectj.testing.harness.bridge.AjcTest; +import org.aspectj.testing.harness.bridge.AjcTest.Spec; +import org.aspectj.testing.run.IRunStatus; +import org.aspectj.testing.run.RunValidator; +import org.aspectj.testing.util.BridgeUtil; +import org.aspectj.testing.util.RunUtils; +import org.aspectj.testing.xml.AjcSpecXmlReader; +import org.aspectj.util.LangUtil; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.List; + +import junit.framework.TestCase; + +/** + * + */ +public class HarnessSelectionTest extends TestCase { + private static final String SELECT + = "testdata/incremental/harness/selectionTest.xml"; + + /** @see testIncrementalSuite() */ + private static final String INCREMENTAL + = "testdata/incremental/harness/suite.xml"; + + private static Hashtable SPECS = new Hashtable(); + + private static AjcTest.Suite.Spec getSpec(String suiteFile) { + AjcTest.Suite.Spec result = (AjcTest.Suite.Spec) SPECS.get(suiteFile); + if (null == result) { + try { + result = AjcSpecXmlReader.getReader().readAjcSuite(new File(suiteFile)); + SPECS.put(suiteFile, result); + } catch (IOException e) { + e.printStackTrace(System.err); + } + } + return result; + } + + private boolean verbose; + + public HarnessSelectionTest(String name) { + super(name); + } + + public void testIncrementalSuite() { + if (!eclipseAvailable()) { + System.err.println("skipping test - eclipse classes not available"); + return; + } + String[] options = new String[] + { "!verbose", "!eclipse", + }; + Exp exp = new Exp(8, 8, 0, 8, 0, 0, 0); + checkSelection(INCREMENTAL, options, "INFIX IGNORED", exp); + } + + public void testKeywordSelectionBoth() { + if (!eclipseAvailable()) { + System.err.println("skipping test - eclipse classes not available"); + return; + } + String[] options = new String[] + { "-ajctestRequireKeywords=requireKeyword", + "-ajctestSkipKeywords=skipKeyword", + "!verbose", + "-eclipse", + }; + Exp exp = new Exp(17, 1, 16, 1, 0, 0, 1); + checkSelection(SELECT, options, "keyword skipKeyword was found", exp); + } + + public void testKeywordSelectionRequire() { + if (!eclipseAvailable()) { + System.err.println("skipping test - eclipse classes not available"); + return; + } + String[] options = new String[] + { "-ajctestRequireKeywords=skipKeyword", + "!verbose", + "-eclipse", + }; + Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16); + checkSelection(SELECT, options, "keyword skipKeyword was not found", exp); + } + + public void testKeywordSelectionSkip() { + if (!eclipseAvailable()) { + System.err.println("skipping test - eclipse classes not available"); + return; + } + String[] options = new String[] + { "-ajctestSkipKeywords=requireKeyword", + "!verbose", + "-eclipse", + }; + Exp exp = new Exp(17, 0, 17, 0, 0, 0, 17); + checkSelection(SELECT, options, "keyword requireKeyword was found", exp); + } + + public void testNoOptions() { + if (!ajcAvailable()) { + System.err.println("skipping test - ajc classes not available"); + return; + } + String[] options = new String[] + { "!ajc" + }; + Exp exp = new Exp(17, 3, 14, 3, 0, 0, 4); + checkSelection(SELECT, options, "normally-valid", exp); + } + + public void testEclipseOptionsSkip() { + String[] options = new String[] + { "-eclipse", + "-ajctestRequireKeywords=eclipseOptionSkip" + }; + Exp exp = new Exp(17, 0, 17, 0, 0, 0, 6); + checkSelection(SELECT, options, "no support in eclipse-based compiler", exp); + } + + public void testAjcEclipseConflict() { + if (!ajcAvailable()) { + System.err.println("skipping test - ajc classes not available"); + return; + } + String[] options = new String[] + { "!ajc" + }; + Exp exp = new Exp(17, 3, 14, 3, 0, 0, 6); + checkSelection(SELECT, options, "conflict between !eclipse and !ajc", exp); + } + + public void testEclipseConflict() { + String[] options = new String[] + { "^eclipse" + }; + Exp exp = new Exp(17, 3, 14, 3, 0, 0, 6); + checkSelection(SELECT, options, "conflict between arg=!eclipse and global=^eclipse", exp); + } + + public void testSinglePR() { + String[] options = new String[] + { "-eclipse", "-ajctestPR=100" + }; + Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16); + checkSelection(SELECT, options, "bugId required", exp); + } + + public void testTwoPR() { + String[] options = new String[] + { "-eclipse", "-ajctestPR=100,101" + }; + Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15); + checkSelection(SELECT, options, "bugId required", exp); + } + + /** + * Run the static test suite with the given options. + * @param setupHolder the IMessageHolder for any setup messages + * @return null if setup failed or Harness.RunResult if suite completed. + */ + private Harness.RunResult runSuite(String suiteFile, String[] options, MessageHandler setupHolder) { + AbstractRunSpec.RT runtime = new AbstractRunSpec.RT(); + runtime.setOptions(options); + AjcTest.Suite.Spec spec = getSpec(suiteFile); + assertNotNull(spec); + ArrayList kids = spec.getChildren(); + assertNotNull(kids); + if ((suiteFile == SELECT) && (17 != kids.size())) { + assertTrue("expected 17 kids, got " + kids.size(), false); + } + if (!spec.adoptParentValues(runtime, setupHolder)) { + return null; + } else { + class TestHarness extends Harness { + public RunResult run(AjcTest.Suite.Spec spec) { + return super.run(spec); + } + } + TestHarness h = new TestHarness(); + return h.run(spec); + } + } + + class Exp { + public final int tests; + public final int testsRun; + public final int skipped; + public final int passed; + public final int failed; + public final int incomplete; + public final int infix; + Exp(int tests, int testsRun, int skipped, int passed, int failed, int incomplete, int infix) { + this.tests = tests; + this.testsRun = testsRun; + this.skipped = skipped; + this.passed = passed; + this.failed = failed; + this.incomplete = incomplete; + this.infix = infix; + } + } + + public void checkSelection(String suiteFile, String[] options, String infoInfix, Exp exp) { + MessageHandler holder = new MessageHandler(); + Harness.RunResult result = runSuite(suiteFile, options, holder); + if (verbose) { + MessageUtil.print(System.out, holder, " setup - "); + } + assertNotNull("Harness.RunResult", result); + // XXX sync hack snooping of message text with skip messages, harness + final List skipList = MessageUtil.getMessages(holder, IMessage.INFO, false, "skip"); + final int numSkipped = skipList.size(); + IRunStatus status = result.status; + assertNotNull(status); + if (verbose) { + RunUtils.print(System.out, "result - ", status); + System.out.println(BridgeUtil.childString(status, numSkipped, result.numIncomplete)); + } + assertEquals("skips", exp.skipped, numSkipped); + IRunStatus[] children = status.getChildren(); + assertNotNull(children); + assertTrue(children.length + "!= expRun=" + exp.testsRun, + exp.testsRun == children.length); + int actPass = 0; + for (int i = 0; i < children.length; i++) { + if (RunValidator.NORMAL.runPassed(children[i])) { + actPass++; + } + } + if (exp.passed != actPass) { + assertTrue("exp.passed=" + exp.passed + " != actPass=" + actPass, false); + } + if (!LangUtil.isEmpty(infoInfix)) { + int actInfix = MessageUtil.getMessages(holder, IMessage.INFO, false, infoInfix).size(); + if (actInfix != exp.infix) { + String s = "for infix \"" + infoInfix + + "\" actInfix=" + actInfix + " != expInfix=" + exp.infix; + assertTrue(s, false); + } + } + } + + private boolean ajcAvailable() { // XXX util + try { + return (null != Class.forName("org.aspectj.compiler.base.JavaCompiler")); + } catch (ClassNotFoundException e) { + return false; + } + } + + + private boolean eclipseAvailable() { // XXX util + try { + return (null != Class.forName("org.aspectj.ajdt.ajc.AjdtCommand")); + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java new file mode 100644 index 000000000..3f9ff1b26 --- /dev/null +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java @@ -0,0 +1,197 @@ +/* ******************************************************************* + * 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[] + { "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(); + } + + } +} |