diff options
author | aclement <aclement> | 2008-08-27 00:38:55 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-08-27 00:38:55 +0000 |
commit | 9d91bcb8d2d6342f005752bd6dc0be858164b1ea (patch) | |
tree | fb76fb115e4144e78c4610516002af674d53f74e /testing-drivers | |
parent | c478a53fee1518aec9a057c317df1fcc666d36bc (diff) | |
download | aspectj-9d91bcb8d2d6342f005752bd6dc0be858164b1ea.tar.gz aspectj-9d91bcb8d2d6342f005752bd6dc0be858164b1ea.zip |
findbugs/eclipse warnings fixed
Diffstat (limited to 'testing-drivers')
3 files changed, 70 insertions, 52 deletions
diff --git a/testing-drivers/src/org/aspectj/testing/drivers/Harness.java b/testing-drivers/src/org/aspectj/testing/drivers/Harness.java index 24a2f8022..09b8a7199 100644 --- a/testing-drivers/src/org/aspectj/testing/drivers/Harness.java +++ b/testing-drivers/src/org/aspectj/testing/drivers/Harness.java @@ -54,18 +54,6 @@ import java.io.PrintWriter; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.StringTokenizer; /** * Test harness for running AjcTest.Suite test suites. @@ -240,7 +228,7 @@ public class Harness { return; } String[] globalOptions = (String[]) globals.toArray(new String[0]); - String[][] globalOptionVariants = LangUtil.optionVariants(globalOptions); + String[][] globalOptionVariants = optionVariants(globalOptions); AbstractRunSpec.RT runtime = new AbstractRunSpec.RT(); if (verboseHarness) { runtime.setVerbose(true); @@ -298,7 +286,7 @@ public class Harness { } finally { doEndSuite(suiteFile,elapsed); } - if (exitOnFailure && (null != result)) { + if (exitOnFailure) { int numFailures = RunUtils.numFailures(result.status, true); if (0 < numFailures) { System.exit(numFailures); @@ -329,6 +317,64 @@ public class Harness { } } } + /** + * Generate variants of String[] options by creating an extra set for + * each option that ends with "-". If none end with "-", then an + * array equal to <code>new String[][] { options }</code> is returned; + * if one ends with "-", then two sets are returned, + * three causes eight sets, etc. + * @return String[][] with each option set. + * @throws IllegalArgumentException if any option is null or empty. + */ + public static String[][] optionVariants(String[] options) { + if ((null == options) || (0 == options.length)) { + return new String[][] { new String[0]}; + } + // be nice, don't stomp input + String[] temp = new String[options.length]; + System.arraycopy(options, 0, temp, 0, temp.length); + options = temp; + boolean[] dup = new boolean[options.length]; + int numDups = 0; + + for (int i = 0; i < options.length; i++) { + String option = options[i]; + if (LangUtil.isEmpty(option)) { + throw new IllegalArgumentException("empty option at " + i); + } + if (option.endsWith("-")) { + options[i] = option.substring(0, option.length()-1); + dup[i] = true; + numDups++; + } + } + final String[] NONE = new String[0]; + final int variants = exp(2, numDups); + final String[][] result = new String[variants][]; + // variant is a bitmap wrt doing extra value when dup[k]=true + for (int variant = 0; variant < variants; variant++) { + ArrayList next = new ArrayList(); + int nextOption = 0; + for (int k = 0; k < options.length; k++) { + if (!dup[k] || (0 != (variant & (1 << (nextOption++))))) { + next.add(options[k]); + } + } + result[variant] = (String[]) next.toArray(NONE); + } + return result; + } + + private static int exp(int base, int power) { // not in Math? + if (0 > power) { + throw new IllegalArgumentException("negative power: " + power); + } + int result = 1; + while (0 < power--) { + result *= base; + } + return result; + } /** * @param suiteFile @@ -1255,7 +1301,7 @@ class XmlLogger extends TestCompleteListener { */ class JUnitXMLLogger extends TestCompleteListener { - private File suite; +// private File suite; private StringBuffer junitOutput; private long startTimeMillis; private int numTests = 0; @@ -1277,7 +1323,7 @@ class JUnitXMLLogger extends TestCompleteListener { long duration = System.currentTimeMillis() - startTimeMillis; numTests++; junitOutput.append("<testcase name=\"" + run.getIdentifier() + "\" "); - junitOutput.append("time=\"" + timeFormatter.format(((float)duration)/1000.0) + "\""); + junitOutput.append("time=\"" + timeFormatter.format((duration)/1000.0f) + "\""); junitOutput.append(">"); if (!run.runResult()) { numFails++; @@ -1321,7 +1367,7 @@ class JUnitXMLLogger extends TestCompleteListener { */ protected void doStartSuite(File suite) { super.doStartSuite(suite); - this.suite = suite; +// this.suite = suite; numTests = 0; numFails = 0; junitOutput = new StringBuffer(); diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java index bc224ee69..05efb60e6 100644 --- a/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java @@ -80,7 +80,7 @@ public class AjctestsAdapter extends TestSuite { log("loading " + tests.length + " tests in " + suitePath); } for (int i = 0; i < tests.length; i++) { - AjcTest.Spec ajcTest = (AjcTest.Spec) tests[i]; + AjcTest.Spec ajcTest = tests[i]; result.addTest(new AjcTestSpecAsTest(ajcTest, result)); } return result; @@ -244,9 +244,9 @@ public class AjctestsAdapter extends TestSuite { public static class SpecTests { private static final HashMap TESTS = new HashMap(); - private static void putSpecTestsFor(String id, SpecTests tests) { - TESTS.put(id, tests); - } +// private static void putSpecTestsFor(String id, SpecTests tests) { +// TESTS.put(id, tests); +// } private static SpecTests getSpecTestsFor(String id) { SpecTests result = (SpecTests) TESTS.get(id); @@ -255,35 +255,7 @@ public class AjctestsAdapter extends TestSuite { } return result; } - - private static String safeName(String name) { - return HarnessJUnitUtil.cleanTestName(name); - } - - private static String filename(String path) { - if (null == path) { - throw new IllegalArgumentException("null path"); - } - int loc = path.lastIndexOf(File.pathSeparator); - if (-1 != loc) { - path = path.substring(loc+1); - } - loc = path.lastIndexOf('/'); - if (-1 != loc) { - path = path.substring(loc+1); - } - loc = path.lastIndexOf("."); - if (-1 != loc) { - path = path.substring(0, loc); - } - return path; - } - - private static String classnameToPath(String classname) { - return classname.replace('.', File.separatorChar) + ".class"; - } - - + // ------------------------------------ final AjctestsAdapter mAjctestsAdapter; @@ -296,7 +268,7 @@ public class AjctestsAdapter extends TestSuite { for (int i = 0; i < tests.length; i++) { map.put(tests[i].getDescription(), tests[i]); } - ; + mDescriptionToAjcTestSpec = Collections.unmodifiableMap(map); } diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java index 24419a189..d3e05f84c 100644 --- a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java @@ -149,7 +149,7 @@ public class HarnessJUnitUtil { String m = safeTestName(test) + " " + description; throw new Error(m); } else if (isFailure) { - String m = safeTestName(test) + " " + description; +// String m = safeTestName(test) + " " + description; throw new AssertionFailedError(description); } // no need to log success } |