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.
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);
} finally {
doEndSuite(suiteFile,elapsed);
}
- if (exitOnFailure && (null != result)) {
+ if (exitOnFailure) {
int numFailures = RunUtils.numFailures(result.status, true);
if (0 < numFailures) {
System.exit(numFailures);
}
}
}
+ /**
+ * 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
*/
class JUnitXMLLogger extends TestCompleteListener {
- private File suite;
+// private File suite;
private StringBuffer junitOutput;
private long startTimeMillis;
private int numTests = 0;
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++;
*/
protected void doStartSuite(File suite) {
super.doStartSuite(suite);
- this.suite = suite;
+// this.suite = suite;
numTests = 0;
numFails = 0;
junitOutput = new StringBuffer();
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;
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);
}
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;
for (int i = 0; i < tests.length; i++) {
map.put(tests[i].getDescription(), tests[i]);
}
- ;
+
mDescriptionToAjcTestSpec = Collections.unmodifiableMap(map);
}