summaryrefslogtreecommitdiffstats
path: root/testing/testsrc
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-10-31 04:01:18 +0000
committerwisberg <wisberg>2003-10-31 04:01:18 +0000
commit0871a66c915e4db43e3d736899c60779a63fd4b4 (patch)
tree16a5d0e63799700ef9ab5ea70928acbe244171c9 /testing/testsrc
parent03a6e118200e61b47c489fd89107b7d6cec1fbfd (diff)
downloadaspectj-0871a66c915e4db43e3d736899c60779a63fd4b4.tar.gz
aspectj-0871a66c915e4db43e3d736899c60779a63fd4b4.zip
basic tests for extdirs support
initial compiler stub for harness command-line munging tests
Diffstat (limited to 'testing/testsrc')
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java1
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java48
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunTest.java180
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java1
-rw-r--r--testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java6
5 files changed, 219 insertions, 17 deletions
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
index 6cacaf42a..f6009fc30 100644
--- a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
@@ -213,6 +213,7 @@ public class AjcSpecTest extends TestCase {
assertEquals(l.includeClassesDir, r.includeClassesDir);
assertEquals(l.reuseCompiler, r.reuseCompiler);
assertEquals(l.sourceroots, r.sourceroots);
+ assertEquals(l.extdirs, r.extdirs);
} else if (c == JavaRun.class) {
JavaRun.Spec l = ((JavaRun) lhs).spec;
JavaRun.Spec r = ((JavaRun) rhs).spec;
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
index 8d05160b4..d3de61686 100644
--- a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
@@ -50,6 +50,22 @@ public class CompilerRunSpecTest extends TestCase {
+ "=... in order to run all tests");
}
}
+
+ private static String[][] duplicate(String[][] input, String prefix) {
+ String[][] output = new String[input.length][];
+ final int prefixLength = (null == prefix ? 0 : prefix.length());
+ for (int i = 0; i < output.length; i++) {
+ int length = input[i].length;
+ output[i] = new String[length];
+ if ((length > 0) && (prefixLength > 0)) {
+ System.arraycopy(input[i], 0, output[i], 0, length);
+ output[i][0] =
+ prefix + output[i][0].substring(prefixLength);
+ }
+ }
+ return output;
+ }
+
private static boolean haveProperty(String key) {
try {
return (null != System.getProperty(key));
@@ -207,6 +223,12 @@ public class CompilerRunSpecTest extends TestCase {
}
}
+ /**
+ * Checck that setting arg as spec compiler and setting up args
+ * results in this compiler classname.
+ * @param arg
+ * @param className
+ */
void checkCompilerOption(String arg, String className) {
MessageHandler handler = new MessageHandler();
try {
@@ -294,21 +316,6 @@ public class CompilerRunSpecTest extends TestCase {
}
}
- String[][] duplicate(String[][] input, String prefix) {
- String[][] output = new String[input.length][];
- final int prefixLength = (null == prefix ? 0 : prefix.length());
- for (int i = 0; i < output.length; i++) {
- int length = input[i].length;
- output[i] = new String[length];
- if ((length > 0) && (prefixLength > 0)) {
- System.arraycopy(input[i], 0, output[i], 0, length);
- output[i][0] =
- prefix + output[i][0].substring(prefixLength);
- }
- }
- return output;
- }
-
public void checkSourceTargetOverride(String name, int from, int to) {
final String specOptions = "-" + name + ", 1." + from;
String[] globalOptions = new String[] { "!" + name, "1." + to };
@@ -344,6 +351,17 @@ public class CompilerRunSpecTest extends TestCase {
resultContains,
messagesContain);
}
+
+ /**
+ * Drive option-setting for CompilerRun.Spec, including
+ * expected errors.
+ * @param specOptions
+ * @param globalOptions
+ * @param expectAdopted
+ * @param resultContains
+ * @param messagesContain
+ * @return
+ */
MessageHandler runTest(
String specOptions,
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunTest.java
new file mode 100644
index 000000000..c68e6598d
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunTest.java
@@ -0,0 +1,180 @@
+/* *******************************************************************
+ * 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.harness.bridge;
+
+import java.io.File;
+import java.util.*;
+
+import junit.framework.TestCase;
+
+import org.aspectj.bridge.*;
+import org.aspectj.testing.run.*;
+import org.aspectj.util.*;
+import org.aspectj.util.LangUtil;
+
+/**
+ * Use a stub compiler/ICommand to verify command-line passed
+ * to the compiler by the harness.
+ */
+public class CompilerRunTest extends TestCase {
+
+ /** String for each dummy report: {run|repeat}: [{args}] */
+ private static ArrayList dummyReports = new ArrayList();
+
+ private static void dummyRunning(String[] args) {
+ dummyReports.add("run: " + Arrays.asList(args));
+ }
+
+ private static void dummyRepeating(String[] args) {
+ dummyReports.add("repeat: " + Arrays.asList(args));
+ }
+
+ private File testBaseDir;
+
+ public CompilerRunTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ testBaseDir = new File(".");
+ File f = new File(testBaseDir, "one");
+ f.mkdirs();
+ assertTrue(f.canRead());
+ f = new File(testBaseDir, "two");
+ f.mkdirs();
+ assertTrue(f.canRead());
+ f = new File(testBaseDir, "Foo.java");
+ String foo = "public class Foo { public void main(String[] s) { System.out.println(\"Hello!\");}}";
+ String err = FileUtil.writeAsString(f, foo);
+ assertTrue(err, null == err);
+ assertTrue(f.canRead());
+ }
+
+ public void tearDown() {
+ testBaseDir = null;
+ }
+
+ public void testExtDirs() {
+ String[] globals = null;
+ CompilerRun.Spec spec = new CompilerRun.Spec();
+ spec.setExtdirs("one,two");
+ spec.setFiles("Foo.java");
+ checkCommandLine(testBaseDir, spec, null, "-extdirs");
+ }
+
+ void checkCommandLine(
+ File testBaseDir,
+ CompilerRun.Spec spec,
+ String[] globals,
+ String expectedInCommand) {
+ assertTrue(0 == dummyReports.size());
+ assertTrue(checkCompilerRun(testBaseDir, spec, globals, null));
+ assertTrue(dummyReports.toString(), 1 == dummyReports.size());
+ String command = (String) dummyReports.remove(0);
+ assertTrue(0 == dummyReports.size());
+ if ((null == command)
+ || (-1 == command.indexOf(expectedInCommand))) {
+ assertTrue("expected "
+ + expectedInCommand
+ + "got "
+ + command,
+ false);
+ }
+ }
+
+ /** run with dummy compiler */
+ boolean checkCompilerRun(
+ File testBaseDir,
+ CompilerRun.Spec spec,
+ String[] globals,
+ MessageHandler handler) {
+ LangUtil.throwIaxIfNull(spec, "spec");
+ if (null == handler) {
+ handler = new MessageHandler();
+ }
+ spec.setPermitAnyCompiler(true);
+ spec.setCompiler(DummyCompiler.class.getName());
+ AbstractRunSpec.RT parentRuntime = new AbstractRunSpec.RT();
+
+ if (!LangUtil.isEmpty(globals)) {
+ parentRuntime.setOptions(globals);
+ }
+ boolean adopted =
+ spec.adoptParentValues(parentRuntime, handler);
+ if (!adopted) {
+ String s = "not adopted spec="
+ + spec
+ + " globals="
+ + (LangUtil.isEmpty(globals)
+ ? "[]"
+ : Arrays.asList(globals).toString())
+ + " -- "
+ + handler;
+ assertTrue(s, false);
+ }
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue("unexpected " + handler, false);
+ }
+ return run(testBaseDir, spec);
+ }
+
+ /** Run the compiler run specified by the spec */
+ protected boolean run(File testBaseDir, CompilerRun.Spec spec) {
+
+// his is created using the Spec.</li>
+// * <li>setupAjcRun(Sandbox, Validator) is invoked,
+// * at which point this populates the shared sandbox
+// * with values derived from the spec and also
+// * sets up internal state based on both the sandbox
+// * and the spec.</li>
+// * <li>run(IRunStatus) is invoked,
+
+ LangUtil.throwIaxIfNull(spec, "spec");
+ Runner runner = new Runner();
+ IMessageHolder holder = new MessageHandler();
+ RunStatus status = new RunStatus(holder, runner);
+ status.setIdentifier(spec);
+ Validator validator = new Validator(status);
+ validator.lock(this);
+ Sandbox sandbox = null;
+ try {
+ sandbox = new Sandbox(testBaseDir, validator);
+ IRunIterator test = spec.makeRunIterator(sandbox, validator);
+ return runner.runIterator(test, status, null);
+ } finally {
+ validator.unlock(this);
+ validator.deleteTempFiles(true);
+ }
+ }
+
+
+ public static class DummyCompiler implements ICommand {
+ private String[] command;
+
+ public DummyCompiler() {
+ }
+
+ public boolean runCommand(
+ String[] args,
+ IMessageHandler handler) {
+ command = (String[]) LangUtil.safeCopy(args, new String[0]);
+ CompilerRunTest.dummyRunning(command);
+ return true;
+ }
+
+ public boolean repeatCommand(IMessageHandler handler) {
+ CompilerRunTest.dummyRunning(command);
+ return true;
+ }
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java b/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java
index f8491b2fa..5bd32622c 100644
--- a/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java
@@ -26,6 +26,7 @@ public class TestingBridgeTests extends TestCase {
//$JUnit-BEGIN$
suite.addTestSuite(AbstractRunSpecTest.class);
suite.addTestSuite(AjcSpecTest.class);
+ suite.addTestSuite(CompilerRunTest.class);
suite.addTestSuite(CompilerRunSpecTest.class);
suite.addTestSuite(ParseTestCase.class);
//$JUnit-END$
diff --git a/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java b/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java
index f2ae8acad..6792d556c 100644
--- a/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java
+++ b/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java
@@ -19,8 +19,10 @@ import junit.framework.Assert;
import org.aspectj.testing.util.LangUtil;
/**
- * Checks that throw AssertionFailedError on failure.
- * Subclasses reimplement <code>assertionFailed(String)</code>
+ * Drivers to test a given set of Options.
+ * They now throw AssertionFailedError on failure,
+ * but subclasses can reimplement
+ * <code>assertionFailed(String)</code>
* to handle failures differently.
*/
public class OptionChecker {