aboutsummaryrefslogtreecommitdiffstats
path: root/testing/testsrc
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-10-29 08:56:38 +0000
committerwisberg <wisberg>2003-10-29 08:56:38 +0000
commited96631f11efc4895a90a68f86f0e75eef8e9e2d (patch)
tree89a9d5fb905a2e87b41b4480d45651c84c9e5602 /testing/testsrc
parent7a01c23476bda528f577b9fe4861f40ad1086381 (diff)
downloadaspectj-ed96631f11efc4895a90a68f86f0e75eef8e9e2d.tar.gz
aspectj-ed96631f11efc4895a90a68f86f0e75eef8e9e2d.zip
revamped option handling: n-element options, collision/conflict detection/resolution via forcing as an attribute, option families. More compiler options actually handled, and error messages for unhandled options.
Diffstat (limited to 'testing/testsrc')
-rw-r--r--testing/testsrc/TestingModuleTests.java1
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java496
-rw-r--r--testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java195
-rw-r--r--testing/testsrc/org/aspectj/testing/util/options/OptionsTest.java486
-rw-r--r--testing/testsrc/org/aspectj/testing/util/options/OptionsTests.java30
-rw-r--r--testing/testsrc/org/aspectj/testing/util/options/ValuesTest.java69
6 files changed, 1217 insertions, 60 deletions
diff --git a/testing/testsrc/TestingModuleTests.java b/testing/testsrc/TestingModuleTests.java
index 452d2e0b1..4c904ac90 100644
--- a/testing/testsrc/TestingModuleTests.java
+++ b/testing/testsrc/TestingModuleTests.java
@@ -25,6 +25,7 @@ public class TestingModuleTests extends TestCase {
suite.addTest(org.aspectj.testing.harness.bridge.TestingBridgeTests.suite());
suite.addTest(org.aspectj.testing.taskdefs.TaskdefTests.suite());
suite.addTest(org.aspectj.testing.util.UtilTests.suite());
+ suite.addTest(org.aspectj.testing.util.options.OptionsTests.suite());
suite.addTest(org.aspectj.testing.xml.TestingXmlTests.suite());
return suite;
}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
index a876db105..8d05160b4 100644
--- a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
@@ -1,6 +1,6 @@
/* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation,
- * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * Copyright (c) 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,14 +9,22 @@
*
* Contributors:
* Xerox/PARC initial implementation
+ * Wes Isberg 2003 modifications
* ******************************************************************/
package org.aspectj.testing.harness.bridge;
+import java.util.*;
+import java.util.Arrays;
+
import junit.framework.TestCase;
import org.aspectj.bridge.MessageHandler;
import org.aspectj.bridge.MessageUtil;
+import org.aspectj.testing.harness.bridge.CompilerRun.Spec.CRSOptions;
+import org.aspectj.testing.util.options.*;
+import org.aspectj.testing.util.options.Options;
+import org.aspectj.util.LangUtil;
/**
*
@@ -24,147 +32,515 @@ import org.aspectj.bridge.MessageUtil;
public class CompilerRunSpecTest extends TestCase {
private static boolean PRINTING = true;
-
- /**
- * Constructor for CompilerRunSpecTest.
- * @param name
- */
- public CompilerRunSpecTest(String name) {
- super(name);
- }
+ private static final boolean SETUP_JAVA13 =
+ haveProperty(Globals.J2SE13_RTJAR_NAME);
+ private static final boolean SETUP_JAVA14 =
+ haveProperty(Globals.J2SE14_RTJAR_NAME);
+ static {
+ if (!SETUP_JAVA14) {
+ System.err.println(
+ "warning: set -D"
+ + Globals.J2SE14_RTJAR_NAME
+ + "=... in order to run all tests");
+ }
+ if (!SETUP_JAVA13) {
+ System.err.println(
+ "warning: set -D"
+ + Globals.J2SE13_RTJAR_NAME
+ + "=... in order to run all tests");
+ }
+ }
+ private static boolean haveProperty(String key) {
+ try {
+ return (null != System.getProperty(key));
+ } catch (Throwable t) {
+ // ignore
+ }
+ return false;
+ }
+
+ /**
+ * Constructor for CompilerRunSpecTest.
+ * @param name
+ */
+ public CompilerRunSpecTest(String name) {
+ super(name);
+ }
public void testSetupArgs() {
- checkSetupArgs("verbose", false);
- // XXX skipping since eclipse is default
- // checkSetupArgs("lenient", false);
- // checkSetupArgs("strict", false);
- // checkSetupArgs("ajc", true); // XXX need to predict/test compiler selection
- // eclipse-only
checkSetupArgs("eclipse", true);
+ checkSetupArgs("verbose", false);
+ }
+
+ public void testCompliance() {
+ // 1.3 should work
+ String specOptions = "-1.3";
+ String[] globalOptions = new String[0];
+ boolean expectAdopted = true;
+ String resultContains = "1.3";
+ String messagesContain = null;
+ MessageHandler handler =
+ runTest(
+ specOptions,
+ globalOptions,
+ expectAdopted,
+ resultContains,
+ messagesContain);
+ checkMessages(handler, null);
+
+ // 1.3 should work with collision?
+ globalOptions = new String[] { "-1.3" };
+ resultContains = "1.3";
+ handler =
+ runTest(
+ specOptions,
+ globalOptions,
+ expectAdopted,
+ resultContains,
+ messagesContain);
+ checkMessages(handler, null);
+
+ // 1.4 should work
+ globalOptions = new String[0];
+ specOptions = "-1.4";
+ resultContains = "1.4";
+ handler =
+ runTest(
+ specOptions,
+ globalOptions,
+ expectAdopted,
+ resultContains,
+ messagesContain);
+ checkMessages(handler, null);
+
+ // compliance not checked for valid numbers, so -1.2 would pass
+ }
+
+ private void checkMessages(MessageHandler handler, String contains) {
+ if (null == contains) {
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue("" + handler, false);
+ }
+ } else {
+ String messages = "" + handler;
+ if (-1 == messages.indexOf(contains)) {
+ assertTrue(messages, false);
+ }
+ }
+ }
+
+ /** @testcase check -target converts for 1.1 and 1.2, not others */
+ public void testTarget() {
+ final boolean PASS = true;
+ final boolean FAIL = false;
+ checkSourceTargetVersionConversion("target", 1, PASS, null);
+ checkSourceTargetVersionConversion("target", 2, PASS, null);
+ checkSourceTargetVersionConversion(
+ "target",
+ 3,
+ FAIL,
+ "illegal input");
+ }
+
+ /** @testcase check -source converts for 1.3 and 1.4, not others */
+ public void testSource() {
+ final boolean PASS = true;
+ final boolean FAIL = false;
+ if (SETUP_JAVA13) {
+ checkSourceTargetVersionConversion("source", 3, PASS, null);
+ }
+ if (SETUP_JAVA14) {
+ checkSourceTargetVersionConversion("source", 4, PASS, null);
+ }
+
+ checkSourceTargetVersionConversion(
+ "source",
+ 2,
+ FAIL,
+ "not permitted");
+ checkSourceTargetVersionConversion(
+ "source",
+ 6,
+ FAIL,
+ "not permitted");
+ }
+
+ public void testSourceOverride() {
+ if (SETUP_JAVA13 && SETUP_JAVA14) {
+ checkSourceTargetOverride("source", 3, 4);
+ checkSourceTargetOverride("source", 4, 3);
+ checkSourceTargetOverride("source", 3, 3);
+ checkSourceTargetOverride("source", 4, 4);
+ }
+ }
+
+ public void testTargetOverride() {
+ checkSourceTargetOverride("target", 1, 2);
+ checkSourceTargetOverride("target", 2, 1);
+ checkSourceTargetOverride("target", 1, 1);
+ checkSourceTargetOverride("target", 2, 2);
}
- void checkSetupArgs(String arg, boolean isTestArg) {
+ public void testCompilerOptions() {
+ checkCompilerOption(null, CompilerRun.Spec.DEFAULT_COMPILER);
+ CRSOptions crsOptions = CompilerRun.Spec.testAccessToCRSOptions();
+ Set options = crsOptions.compilerOptions();
+ assertTrue(null != options);
+ StringBuffer notLoaded = new StringBuffer();
+ for (Iterator iter = options.iterator(); iter.hasNext();) {
+ Option compilerOption = (Option) iter.next();
+ if (!(crsOptions.compilerIsLoadable(compilerOption))) {
+ notLoaded.append(" " + compilerOption);
+ } else {
+ String className = crsOptions.compilerClassName(compilerOption);
+ String argValue = compilerOption.toString(); // XXX snoop
+ String arg = Option.ON.render(argValue);
+ checkCompilerOption(arg, className);
+ }
+ }
+ if (0 < notLoaded.length()) {
+ System.err.println(
+ getClass().getName()
+ + ".testCompilerOptions()"
+ + " warning: compiler options not tested because not loadable: "
+ + notLoaded);
+ }
+ }
+
+ void checkCompilerOption(String arg, String className) {
+ MessageHandler handler = new MessageHandler();
+ try {
+ CompilerRun.Spec spec = null;
+ try {
+ spec = new CompilerRun.Spec();
+ } catch (Throwable t) {
+ t.printStackTrace(System.err);
+ }
+ assertTrue(spec != null);
+ AbstractRunSpec.RT parentRuntime = new AbstractRunSpec.RT();
+ String result;
+ String expResult;
+
+ if (null != arg) {
+ parentRuntime.setOptions(new String[] { arg });
+ }
+ if (!spec.adoptParentValues(parentRuntime, handler)) {
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ } else {
+ assertTrue("adopt failed, but no messages", false);
+ }
+ }
+ result = "" + spec.testSetup.commandOptions;
+ assertEquals("[]", result);
+ assertEquals(className, spec.testSetup.compilerName);
+ } finally {
+ }
+ }
+
+ public void testSpecOptions() {
+ Options options = CompilerRun.Spec.testAccessToOptions();
+ OptionChecker optionChecker = new OptionChecker(options);
+ // known failures: extdirs, aspectpath, Xlintfile <file>
+ // progress, time, noExit, repeat <n>,
+ // help,
+ String[][] input =
+ new String[][] {
+ new String[] { "-verbose" },
+ new String[] { "-incremental" },
+ new String[] { "-emacssym" },
+ new String[] { "-Xlint" },
+ new String[] { "-Xlint:error" },
+ new String[] { "-1.3" },
+ new String[] { "-1.4" },
+ new String[] { "-source", "1.3" },
+ new String[] { "-source", "1.4" },
+ new String[] { "-target", "1.1" },
+ new String[] { "-target", "1.2" },
+ new String[] { "-preserveAllLocals" },
+ new String[] { "-referenceInfo" },
+ new String[] { "-deprecation" },
+ new String[] { "-noImportError" },
+ new String[] { "-proceedOnError" }
+ };
+ String[][] literalInput =
+ new String[][] {
+ new String[] { "-nowarn" },
+ new String[] { "-warn:deprecated" },
+ new String[] { "-warn:deprecated,unverified" },
+ new String[] { "-warn:deprecated", "-warn:unusedLocals" },
+ new String[] { "-g" },
+ new String[] { "-g", "-g:none" },
+ new String[] { "-g:vars,source" },
+ new String[] { "-verbose", "-g:vars,source" },
+ };
+ // normal
+ for (int i = 0; i < input.length; i++) {
+ optionChecker.checkOptions(input[i], input[i]);
+ }
+ for (int i = 0; i < literalInput.length; i++) {
+ optionChecker.checkOptions(literalInput[i], literalInput[i]);
+ }
+ // force-on
+ String[][] forceInput = duplicate(input, "!");
+ for (int i = 0; i < input.length; i++) {
+ optionChecker.checkOptions(forceInput[i], input[i]);
+ }
+ // force-off
+ forceInput = duplicate(input, "^");
+ String[] none = new String[0];
+ for (int i = 0; i < input.length; i++) {
+ optionChecker.checkOptions(forceInput[i], none);
+ }
+ }
+
+ 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 };
+ boolean expectAdopted = true;
+ String resultContains = "[-" + name + ", 1." + to;
+ String messagesContain = null;
+ MessageHandler handler =
+ runTest(
+ specOptions,
+ globalOptions,
+ expectAdopted,
+ resultContains,
+ messagesContain);
+ checkMessages(handler, null);
+ }
+
+ void checkSourceTargetVersionConversion(
+ String name,
+ int i,
+ boolean expectPass,
+ String expectedErr) {
+ final String specOptions = "-" + name + ", 1." + i;
+ String[] globalOptions = new String[0];
+ boolean expectAdopted = expectPass;
+ String resultContains =
+ !expectPass ? null : "[-" + name + ", 1." + i;
+ String messagesContain = expectedErr;
+ MessageHandler handler =
+ runTest(
+ specOptions,
+ globalOptions,
+ expectAdopted,
+ resultContains,
+ messagesContain);
+ }
+
+ MessageHandler runTest(
+ String specOptions,
+ String[] globalOptions,
+ boolean expectAdopted,
+ String resultContains,
+ String messagesContain) {
MessageHandler handler = new MessageHandler();
try {
CompilerRun.Spec spec = new CompilerRun.Spec();
AbstractRunSpec.RT parentRuntime = new AbstractRunSpec.RT();
+
+ if (!LangUtil.isEmpty(specOptions)) {
+ spec.setOptions(specOptions);
+ }
+ if (!LangUtil.isEmpty(globalOptions)) {
+ parentRuntime.setOptions(globalOptions);
+ }
+ boolean adopted =
+ spec.adoptParentValues(parentRuntime, handler);
+ if (adopted != expectAdopted) {
+ String s =
+ (expectAdopted ? "not " : "")
+ + "adopted spec="
+ + specOptions
+ + " globals="
+ + (LangUtil.isEmpty(globalOptions)
+ ? "[]"
+ : Arrays.asList(globalOptions).toString())
+ + " -- "
+ + handler;
+ assertTrue(s, false);
+ }
+ if (null != resultContains) {
+ String result = "" + spec.testSetup.commandOptions;
+ if (-1 == result.indexOf(resultContains)) {
+ assertTrue(
+ "expected " + resultContains + " got " + result,
+ false);
+ }
+ }
+ if (null != messagesContain) {
+ boolean haveMessages =
+ (0 != handler.numMessages(null, true));
+ if (!haveMessages) {
+ assertTrue("expected " + messagesContain, false);
+ } else {
+ String messages = handler.toString();
+ if (-1 == messages.indexOf(messagesContain)) {
+ assertTrue(
+ "expected "
+ + messagesContain
+ + " got "
+ + messages,
+ false);
+ }
+ }
+ }
+ return handler;
+ } finally {
+ }
+ }
+
+ void checkSetupArgs(String arg, final boolean isTestArg) {
+ MessageHandler handler = new MessageHandler();
+ try {
+ CompilerRun.Spec spec = null;
+ try {
+ spec = new CompilerRun.Spec();
+ } catch (Throwable t) {
+ t.printStackTrace(System.err);
+ }
+ assertTrue(spec != null);
+ AbstractRunSpec.RT parentRuntime = new AbstractRunSpec.RT();
String result;
String expResult;
-
+
// -------- local set
+ // global - (set) does not change local-set
+ parentRuntime.setOptions(new String[] { "-" + arg });
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = "" + spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
// global ^ (force-off) to disable
spec.setOptions("-" + arg);
- parentRuntime.setOptions(new String[] {"^" + arg});
+ parentRuntime.setOptions(new String[] { "^" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
assertTrue(result, "[]".equals(result));
-
+
// global ! (force-on) does not change local-set
- parentRuntime.setOptions(new String[] {"!" + arg});
+ parentRuntime.setOptions(new String[] { "!" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
expResult = (isTestArg ? "[]" : "[-" + arg + "]");
- assertTrue(result, expResult.equals(result));
-
- // global - (set) does not change local-set
- parentRuntime.setOptions(new String[] {"-" + arg});
- assertTrue(spec.adoptParentValues(parentRuntime, handler));
- if (0 != handler.numMessages(null, true)) {
- assertTrue(handler.toString(), false);
+ if (!expResult.equals(result)) {
+ assertTrue(
+ "expected " + expResult + " got " + result,
+ false);
}
- result = ""+spec.testSetup.commandOptions;
- expResult = (isTestArg ? "[]" : "[-" + arg + "]");
- assertTrue(result, expResult.equals(result));
-
+
// global (unset) does not change local-set
- parentRuntime.setOptions(new String[] {""});
+ parentRuntime.setOptions(new String[] { "" });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
expResult = (isTestArg ? "[]" : "[-" + arg + "]");
assertTrue(result, expResult.equals(result));
-
+
// -------- local force-on
// global ^ (force-off) conflicts with local force-on
spec.setOptions("!" + arg);
- parentRuntime.setOptions(new String[] {"^" + arg});
+ parentRuntime.setOptions(new String[] { "^" + arg });
assertTrue(!spec.adoptParentValues(parentRuntime, handler));
assertTrue(0 != handler.numMessages(null, true));
handler.init();
-
+
// global ! (force-on) does not change local force-on
- parentRuntime.setOptions(new String[] {"!" + arg});
+ parentRuntime.setOptions(new String[] { "!" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
expResult = (isTestArg ? "[]" : "[-" + arg + "]");
assertTrue(result, expResult.equals(result));
-
+
// global - (set) does not change local force-on
- parentRuntime.setOptions(new String[] {"-" + arg});
+ parentRuntime.setOptions(new String[] { "-" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
expResult = (isTestArg ? "[]" : "[-" + arg + "]");
assertTrue(result, expResult.equals(result));
-
+
// global (unset) does not change local force-on
- parentRuntime.setOptions(new String[] {""});
+ parentRuntime.setOptions(new String[] { "" });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
expResult = (isTestArg ? "[]" : "[-" + arg + "]");
assertTrue(result, expResult.equals(result));
-
-
+
// -------- local force-off
// global ^ (force-off) does not change local force-off
spec.setOptions("^" + arg);
- parentRuntime.setOptions(new String[] {"^" + arg});
+ parentRuntime.setOptions(new String[] { "^" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
assertTrue(result, ("[]").equals(result));
-
+
// global ! (force-on) conflicts with local force-off
- parentRuntime.setOptions(new String[] {"!" + arg});
+ parentRuntime.setOptions(new String[] { "!" + arg });
assertTrue(!spec.adoptParentValues(parentRuntime, handler));
assertTrue(0 != handler.numMessages(null, true));
handler.init();
-
- // global - (set) overridden by local force-off // XXX??
- parentRuntime.setOptions(new String[] {"-" + arg});
+
+ // global - (set) overridden by local force-off
+ parentRuntime.setOptions(new String[] { "-" + arg });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
assertTrue(result, ("[]").equals(result));
-
+
// global (unset) does not change local force-off
- parentRuntime.setOptions(new String[] {""});
+ parentRuntime.setOptions(new String[] { "" });
assertTrue(spec.adoptParentValues(parentRuntime, handler));
if (0 != handler.numMessages(null, true)) {
assertTrue(handler.toString(), false);
}
- result = ""+spec.testSetup.commandOptions;
+ result = "" + spec.testSetup.commandOptions;
assertTrue(result, ("[]").equals(result));
+
+ // undefined whether global set overrides local set
+ // for different sibling options
} finally {
if (PRINTING && (0 < handler.numMessages(null, true))) {
MessageUtil.print(System.err, handler, "checkSetupArgs: ");
diff --git a/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java b/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java
new file mode 100644
index 000000000..f2ae8acad
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/options/OptionChecker.java
@@ -0,0 +1,195 @@
+/* *******************************************************************
+ * 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.util.options;
+
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+import org.aspectj.testing.util.LangUtil;
+
+/**
+ * Checks that throw AssertionFailedError on failure.
+ * Subclasses reimplement <code>assertionFailed(String)</code>
+ * to handle failures differently.
+ */
+public class OptionChecker {
+ private final Options options;
+
+ public OptionChecker(Options options) {
+ this.options = options;
+ LangUtil.throwIaxIfNull(options, "options");
+ }
+
+ /**
+ * Subclasses override this to throw different exceptions
+ * on assertion failures.
+ * This implementation delegates to
+ * <code>Assert.assertTrue(label, false)</code>.
+ * @param label the String message for the assertion
+ *
+ */
+ public void assertionFailed(String label) {
+ Assert.assertTrue(label, false);
+ }
+
+ public void checkAssertion(String label, boolean test) {
+ if (!test) {
+ assertionFailed(label);
+ }
+ }
+
+ public void checkOptions(String[] input, String[] expected) {
+ checkOptions(input, expected, true);
+ }
+
+ public void checkOptions(
+ String[] input,
+ String[] expected,
+ boolean resolve) {
+ Values values = getValues(input);
+ if (resolve) {
+ String err = values.resolve();
+ checkAssertion("error: \"" + err + "\"", null == err);
+ }
+ String[] actual = values.render(); // Value.render(values);
+ checkEqual(expected, actual);
+ }
+
+ public void checkOptionsNegative(
+ String[] input,
+ String expectedMissedMatchErr,
+ String expectedResolveErr) {
+ checkOptionsNegative(
+ input,
+ null,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+ }
+
+ public void checkOptionsNegative(
+ String[] input,
+ String expectedInValuesException,
+ String expectedMissedMatchErr,
+ String expectedResolveErr) {
+ Values values =
+ getValuesNegative(input, expectedInValuesException);
+ if (null == expectedInValuesException) {
+ String err = Options.missedMatchError(input, values);
+ checkContains(expectedMissedMatchErr, err);
+ err = values.resolve();
+ checkContains(expectedResolveErr, err);
+ }
+ }
+
+ private Values getValuesNegative(
+ String[] input,
+ String expectedInExceptionMessage,
+ Options options) {
+ try {
+ return options.acceptInput(input);
+ } catch (Option.InvalidInputException e) {
+ String m = e.getFullMessage();
+ boolean ok =
+ (null != expectedInExceptionMessage)
+ && (-1 != m.indexOf(expectedInExceptionMessage));
+ if (!ok) {
+ e.printStackTrace(System.err);
+ if (null != expectedInExceptionMessage) {
+ m =
+ "expected \""
+ + expectedInExceptionMessage
+ + "\" in "
+ + m;
+ }
+ assertionFailed(m);
+ }
+ return null; // actually never executed
+ }
+ }
+
+ private Values getValuesNegative(
+ String[] input,
+ String expectedInExceptionMessage) {
+ return getValuesNegative(
+ input,
+ expectedInExceptionMessage,
+ options);
+ }
+
+ private Values getValues(String[] input, Options options) {
+ return getValuesNegative(input, null, options);
+ }
+
+ private Values getValues(String[] input) {
+ return getValuesNegative(input, null);
+ }
+
+ private void checkContains(String expected, String expectedIn) {
+ if (null == expected) {
+ if (null != expectedIn) {
+ assertionFailed("did not expect \"" + expectedIn + "\"");
+ }
+ } else {
+ if ((null == expectedIn)
+ || (-1 == expectedIn.indexOf(expected))) {
+ assertionFailed(
+ "expected \""
+ + expected
+ + "\" in \""
+ + expectedIn
+ + "\"");
+ }
+ }
+ }
+
+ private String safeString(String[] ra) {
+ return (null == ra ? "null" : Arrays.asList(ra).toString());
+ }
+
+ private void checkEqual(String[] expected, String[] actual) {
+ if (!isEqual(expected, actual)) {
+ assertionFailed(
+ "expected \""
+ + safeString(expected)
+ + "\" got \""
+ + safeString(actual)
+ + "\"");
+ }
+ }
+
+ private boolean isEqual(String[] expected, String[] actual) {
+ if (null == expected) {
+ return (null == actual ? true : false);
+ } else if (null == actual) {
+ return false;
+ } else if (expected.length != actual.length) {
+ return false;
+ }
+ for (int i = 0; i < actual.length; i++) {
+ String e = expected[i];
+ String a = actual[i];
+ if (null == e) {
+ if (null != a) {
+ return false;
+ }
+ } else if (null == a) {
+ return false;
+ } else if (!(e.equals(a))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/options/OptionsTest.java b/testing/testsrc/org/aspectj/testing/util/options/OptionsTest.java
new file mode 100644
index 000000000..29048aa07
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/options/OptionsTest.java
@@ -0,0 +1,486 @@
+/* *******************************************************************
+ * 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.util.options;
+
+import junit.framework.*;
+
+import org.aspectj.testing.util.options.Option.InvalidInputException;
+
+/**
+ */
+public class OptionsTest extends TestCase {
+
+ private static Options OPTIONS;
+
+ private static Options getOptions() {
+ if (null == OPTIONS) {
+ OPTIONS = new Options(true);
+ Option.Factory factory = new Option.Factory("OptionsTest");
+ OPTIONS.addOption(factory.create("verbose"));
+ OPTIONS.addOption(factory.create("quiet"));
+ OPTIONS.addOption(factory.create("debug"));
+ OPTIONS.addOption(
+ factory.create("ajc", "compiler", Option.FORCE_PREFIXES, false));
+ OPTIONS.addOption(
+ factory.create(
+ "eclipse",
+ "compiler",
+ Option.FORCE_PREFIXES,
+ false));
+ OPTIONS.addOption(
+ factory.create(
+ "ajdeCompiler",
+ "compiler",
+ Option.FORCE_PREFIXES,
+ false));
+ OPTIONS.addOption(
+ factory.create("1.3", "compliance", Option.FORCE_PREFIXES, false));
+ OPTIONS.addOption(
+ factory.create("1.4", "compliance", Option.FORCE_PREFIXES, false));
+
+ // treating multi-arg as single - extrinsic flatten/unflatten
+ OPTIONS.addOption(
+ factory.create("target11", "target", Option.FORCE_PREFIXES, false));
+ OPTIONS.addOption(
+ factory.create("target12", "target", Option.FORCE_PREFIXES, false));
+ OPTIONS.addOption(
+ factory.create("source13", "source", Option.FORCE_PREFIXES, false));
+ OPTIONS.addOption(
+ factory.create("source14", "source", Option.FORCE_PREFIXES, false));
+
+ // suffix options (a) -warn:... (b) -g, -g:...
+ Assert.assertTrue(factory.setupFamily("warning", true));
+ OPTIONS.addOption(
+ factory.create("warn", "warning", Option.STANDARD_PREFIXES, true));
+
+ Assert.assertTrue(factory.setupFamily("debugSymbols", true));
+ OPTIONS.addOption(
+ factory.create(
+ "g",
+ "debugSymbols",
+ Option.STANDARD_PREFIXES,
+ false));
+ OPTIONS.addOption(
+ factory.create(
+ "g:",
+ "debugSymbols",
+ Option.STANDARD_PREFIXES,
+ true));
+
+ // treating multi-arg as single - intrinsic flatten/unflatten
+ OPTIONS
+ .addOption(
+ factory
+ .create(
+ "target",
+ "target",
+ Option.FORCE_PREFIXES,
+ false,
+ new String[][] {
+ new String[] { "1.1", "1.2" }
+ }));
+ OPTIONS
+ .addOption(
+ factory
+ .create(
+ "source",
+ "source",
+ Option.FORCE_PREFIXES,
+ false,
+ new String[][] {
+ new String[] { "1.3", "1.4" }
+ }));
+ OPTIONS.freeze();
+ }
+ return OPTIONS;
+ }
+
+ private boolean verbose;
+ private OptionChecker localOptionChecker;
+
+ public void testDebugCase() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] {
+ };
+ String[] expected = new String[0];
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-target", "1.1", "^target", "1.2" };
+ expected = new String[] { "-target", "1.1" };
+
+ optionChecker.checkOptions(input, expected);
+ }
+ public void testNegDebugCase() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] { "-target" };
+ String expectedInValuesException = "not enough arguments";
+ String expectedMissedMatchErr = null;
+ String expectedResolveErr = null;
+
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedInValuesException,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+ }
+
+ public void testOptionsPositive() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] {
+ };
+ String[] expected = new String[0];
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-verbose" };
+ expected = new String[] { "-verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!verbose" };
+ expected = new String[] { "-verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!verbose", "-verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-verbose", "!verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "^verbose" };
+ expected = new String[] {
+ };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "^verbose", "-verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-verbose", "^verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-verbose", "-debug" };
+ expected = new String[] { "-verbose", "-debug" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!verbose", "!debug" };
+ expected = new String[] { "-verbose", "-debug" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-verbose", "^verbose", "!debug" };
+ expected = new String[] { "-debug" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "^verbose", "-verbose", "!debug" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!debug", "^verbose", "-verbose" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-ajc" };
+ expected = new String[] { "-ajc" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-eclipse" };
+ expected = new String[] { "-eclipse" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-eclipse", "-ajc", "!ajc" };
+ expected = new String[] { "-ajc" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-eclipse", "!ajc" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-ajdeCompiler", "^ajc" };
+ expected = new String[] { "-ajdeCompiler" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!ajdeCompiler", "^ajc" };
+ optionChecker.checkOptions(input, expected);
+
+ input =
+ new String[] {
+ "-verbose",
+ "^verbose",
+ "!quiet",
+ "-quiet",
+ "-debug",
+ "^debug" };
+ expected = new String[] { "-quiet" };
+ optionChecker.checkOptions(input, expected);
+
+ input =
+ new String[] {
+ "-verbose",
+ "^debug",
+ "!quiet",
+ "!quiet",
+ "-debug",
+ "^verbose" };
+ expected = new String[] { "-quiet" };
+ optionChecker.checkOptions(input, expected);
+ }
+
+ public void testOptionsNegative() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] { "-unknown" };
+ String expectedMissedMatchErr = "-unknown";
+ String expectedResolveErr = null;
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+
+ input = new String[] { "!verbose", "^verbose" };
+ expectedMissedMatchErr = null;
+ expectedResolveErr = "conflict";
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+
+ input = new String[] { "!ajc", "!eclipse" };
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+
+ input = new String[] { "-ajc", "-eclipse" };
+ expectedResolveErr = "collision";
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+
+ input = new String[] { "-verbose", "-verbose" };
+ expectedResolveErr = null; // duplicates redundant, not colliding
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedMissedMatchErr,
+ expectedResolveErr);
+ }
+
+ public void testMissedMatches() throws InvalidInputException {
+ checkMissedMatches(new int[0], Values.EMPTY);
+ checkMissedMatches(new int[] { 0 },
+ Values.wrapValues(new Option.Value[1])); // null in [0]
+ checkMissedMatches(
+ new int[] { 0, 1, 2 },
+ Values.wrapValues(new Option.Value[] { null, null, null }));
+
+ Option.Factory factory = new Option.Factory("testMissedMatches");
+ Option single = factory.create("verbose");
+ Option multiple =
+ factory
+ .create(
+ "source",
+ "source",
+ Option.STANDARD_PREFIXES,
+ false,
+ new String[][] { new String[] { "1.3", "1.4" }
+ });
+
+ Options options = new Options(false);
+ options.addOption(single);
+ options.addOption(multiple);
+ options.freeze();
+ int[] expectNone = new int[0];
+ String[] input = new String[] { "-verbose" };
+ Values result = options.acceptInput(input);
+ checkMissedMatches(expectNone, result);
+
+ input = new String[] { "-verbose", "-verbose" };
+ result = options.acceptInput(input);
+ checkMissedMatches(expectNone, result);
+
+ input = new String[] { "-source", "1.3" };
+ result = options.acceptInput(input);
+ checkMissedMatches(expectNone, result);
+
+ input = new String[] { "-source", "1.4" };
+ result = options.acceptInput(input);
+ checkMissedMatches(expectNone, result);
+
+ input = new String[] { "-verbose", "-missed" };
+ result = options.acceptInput(input);
+ checkMissedMatches(new int[] { 1 }, result);
+
+ input = new String[] { "-source", "1.4", "-missed" };
+ result = options.acceptInput(input);
+ checkMissedMatches(new int[] { 2 }, result);
+
+ input = new String[] { "-source", "1.4", "-missed", "-verbose" };
+ result = options.acceptInput(input);
+ checkMissedMatches(new int[] { 2 }, result);
+
+ }
+
+ void checkMissedMatches(int[] expected, Values actual) {
+ int[] result = actual.indexMissedMatches();
+ boolean failed = (result.length != expected.length);
+
+ for (int i = 0; !failed && (i < result.length); i++) {
+ failed = (result[i] != expected[i]);
+ }
+ if (failed) {
+ assertTrue(
+ "expected "
+ + Values.IntList.render(expected)
+ + " got "
+ + Values.IntList.render(result)
+ + " for "
+ + actual,
+ false);
+ }
+ }
+
+ public void testComplexOptionsPositive() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] {
+ };
+ String[] expected = new String[0];
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-target11" };
+ expected = new String[] { "-target11" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!target12" };
+ expected = new String[] { "-target12" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!target12", "-target11" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!target12", "^target11" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "^target12", "^target11" };
+ expected = new String[] {
+ };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!1.3" };
+ expected = new String[] { "-1.3" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!1.3", "-1.4" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!1.3", "^1.4" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "^1.3", "^1.4" };
+ expected = new String[] {
+ };
+ optionChecker.checkOptions(input, expected);
+
+ }
+
+ public void testMultiArgOptionsPositive() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] {
+ };
+ String[] expected = new String[0];
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-target", "1.1" };
+ expected = new String[] { "-target", "1.1" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!target", "1.1" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!target", "1.1", "-target", "1.2" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-target", "1.1", "^target", "1.2" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-source", "1.3" };
+ expected = new String[] { "-source", "1.3" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "!source", "1.3", "-source", "1.4" };
+ optionChecker.checkOptions(input, expected);
+
+ input = new String[] { "-source", "1.3", "^source", "1.4" };
+ input =
+ new String[] {
+ "-source",
+ "1.3",
+ "^source",
+ "1.4",
+ "!source",
+ "1.3",
+ "-source",
+ "1.4" };
+ optionChecker.checkOptions(input, expected);
+ }
+
+ public void testMultiArgOptionsNegative() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[] input = new String[] { "-target" };
+ String expectedException = "not enough arguments";
+
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedException,
+ null,
+ null);
+
+ input = new String[] { "-source" };
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedException,
+ null,
+ null);
+
+ input = new String[] { "-source", "1.1" };
+ expectedException = "not permitted";
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedException,
+ null,
+ null);
+
+ input = new String[] { "-target", "1.3" };
+ optionChecker.checkOptionsNegative(
+ input,
+ expectedException,
+ null,
+ null);
+ }
+
+ public void testMultipleInput() {
+ OptionChecker optionChecker = getOptionChecker();
+ String[][] input =
+ new String[][] {
+ new String[] { "-warn:deprecated" },
+ new String[] { "-warn:deprecated,unverified" },
+ new String[] { "-warn:deprecated", "-warn:unusedLocals" },
+ new String[] { "-g" },
+ new String[] { "-g", "-g:none" },
+ new String[] { "-g:vars,source" },
+ new String[] { "-verbose", "-g:vars,source" },
+ };
+ for (int i = 0; i < input.length; i++) {
+ optionChecker.checkOptions(input[i], input[i]);
+ }
+ }
+
+ private OptionChecker getOptionChecker() {
+ if (null == localOptionChecker) {
+ localOptionChecker = new OptionChecker(getOptions());
+ }
+ return localOptionChecker;
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/options/OptionsTests.java b/testing/testsrc/org/aspectj/testing/util/options/OptionsTests.java
new file mode 100644
index 000000000..2cc937935
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/options/OptionsTests.java
@@ -0,0 +1,30 @@
+/* *******************************************************************
+ * 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.util.options;
+
+import junit.framework.*;
+
+public class OptionsTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(OptionsTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(OptionsTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public OptionsTests(String name) { super(name); }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/options/ValuesTest.java b/testing/testsrc/org/aspectj/testing/util/options/ValuesTest.java
new file mode 100644
index 000000000..cc6623ffc
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/options/ValuesTest.java
@@ -0,0 +1,69 @@
+/* *******************************************************************
+ * 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.util.options;
+
+import junit.framework.TestCase;
+
+/**
+ */
+public class ValuesTest extends TestCase {
+
+ public ValuesTest(String s) {
+ super(s);
+ }
+ public void testInvert() {
+ checkInvert(new int[0], 0, new int[0]); // no input or missed => none found
+ checkInvert(new int[0], 1, new int[] {0}); // no missed, input 1 => 1 found
+ checkInvert(new int[] {0}, 1, new int[] {}); // 1 (all) missed, input 1 => none found
+ checkInvert(new int[] {}, 1, new int[] {0}); // 0 (none) missed, input 1 => 1 found
+ checkInvert(new int[] {1,2}, 3, new int[] {0}); // 2 missed, input 3 => 1 (first) found
+ checkInvert(new int[] {0,2}, 3, new int[] {1}); // 2 missed, input 3 => 1 (middle) found
+ checkInvert(new int[] {0,1}, 3, new int[] {2}); // 2 missed, input 3 => 1 (last) found
+ checkInvert(new int[] {1,3}, 4, new int[] {0,2}); // 2 missed, input 4 => 2 found
+ checkInvert(new int[] {5,6,7}, 8, new int[] {0,1,2,3,4}); // starting run
+ checkInvert(new int[] {0,1,2,3,4}, 8, new int[] {5,6,7}); // ending run
+ checkInvert(new int[] {0,5,6,7}, 8, new int[] {1,2,3,4}); // middle run
+ checkInvert(new int[] {0,5,6,9},10, new int[] {1,2,3,4,7,8}); // two middle run
+ checkInvert(new int[] {1,2,5,6,9},10, new int[] {0,3,4,7,8}); // start, 2 middle run
+ checkInvert(new int[] {0,1,2,5,6},10, new int[] {3,4,7,8,9}); // middle, end run
+ }
+
+ void checkInvert(int[] missed, int length, int[] expected) {
+ int[] actual = Values.invert(missed, length);
+ assertTrue(null != actual);
+ assertTrue(actual.length == expected.length);
+ for (int i = 0; i < actual.length; i++) {
+ if (expected[i] != actual[i]) {
+ assertTrue("failed at " + i + render(expected, actual), false);
+ }
+ }
+ }
+ static String render(int[] expected, int[] actual) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(" expected ");
+ render(expected, sb);
+ sb.append(" actual ");
+ render(actual, sb);
+ return sb.toString();
+ }
+ static void render(int[] ra, StringBuffer sb) {
+ sb.append("[");
+ for (int i = 0; i < ra.length; i++) {
+ if (i > 0) {
+ sb.append(", ");
+ }
+ sb.append("" + ra[i]);
+ }
+ sb.append("]");
+ }
+}