ICU-2732 add -filter options
X-SVN-Rev: 13316
This commit is contained in:
parent
fd7d8e1dc5
commit
63f0e270e9
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java,v $
|
||||
* $Date: 2003/10/02 20:50:57 $
|
||||
* $Revision: 1.51 $
|
||||
* $Date: 2003/10/04 00:27:28 $
|
||||
* $Revision: 1.52 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -25,7 +25,6 @@ import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/**
|
||||
* TestFmwk is a base class for tests that can be run conveniently from
|
||||
* the command line as well as under the Java test harness.
|
||||
@ -41,7 +40,7 @@ import java.util.Random;
|
||||
public class TestFmwk extends AbstractTestLog {
|
||||
/**
|
||||
* Puts a copyright in the .class file
|
||||
*/
|
||||
*/
|
||||
private static final String copyrightNotice
|
||||
= "Copyright \u00a91997-2003 IBM Corp. All rights reserved.";
|
||||
|
||||
@ -159,7 +158,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
newTarget = this.new Target(names[i]);
|
||||
}
|
||||
} else {
|
||||
/// syn wee check here
|
||||
TestFmwk test = getSubtest(i, groupOnly);
|
||||
if (test != null) {
|
||||
newTarget = test.new ClassTarget();
|
||||
@ -189,7 +187,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
return getSubtest(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
throw new TestFmwkException(testName);
|
||||
}
|
||||
|
||||
@ -247,14 +244,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
public class Target {
|
||||
private Target next;
|
||||
public final String name;
|
||||
/**
|
||||
* Caller class that run this target
|
||||
*/
|
||||
public Target caller;
|
||||
/**
|
||||
* Flag to indicate if this class is or has been executed
|
||||
*/
|
||||
public boolean flag = false;
|
||||
|
||||
public Target(String name) {
|
||||
this.name = name;
|
||||
@ -269,33 +258,27 @@ public class TestFmwk extends AbstractTestLog {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void printName()
|
||||
{
|
||||
if (caller != null && !caller.flag) {
|
||||
params.indentLevel --;
|
||||
caller.printName();
|
||||
params.indentLevel ++;
|
||||
}
|
||||
params.writeTestName(name);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Locale.setDefault(defaultLocale);
|
||||
TimeZone.setDefault(defaultTimeZone);
|
||||
|
||||
if (!validate()) {
|
||||
params.writeTestInvalid(name);
|
||||
int f = filter();
|
||||
if (f == -1) {
|
||||
++params.invalidCount;
|
||||
} else {
|
||||
if (params.listlevel > 0 && !flag) {
|
||||
params.writeTestName(name);
|
||||
flag = true;
|
||||
Locale.setDefault(defaultLocale);
|
||||
TimeZone.setDefault(defaultTimeZone);
|
||||
|
||||
if (!validate()) {
|
||||
params.writeTestInvalid(name);
|
||||
} else {
|
||||
params.push(name, getDescription(), f == 1);
|
||||
execute();
|
||||
params.pop();
|
||||
}
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int filter() {
|
||||
return params.filter(name);
|
||||
}
|
||||
|
||||
protected boolean validate() {
|
||||
return false;
|
||||
@ -314,9 +297,8 @@ public class TestFmwk extends AbstractTestLog {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
params.writeTestName(name);
|
||||
params.writeTestResult(params.errorCount, params.invalidCount);
|
||||
protected boolean validate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,18 +319,15 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
|
||||
protected void execute() {
|
||||
///
|
||||
if (params.filter != null && name.toLowerCase().indexOf(params.filter) < 0) {
|
||||
params.invalidCount ++;
|
||||
return;
|
||||
}
|
||||
printName();
|
||||
if (params.inDocMode()) {
|
||||
params.writeTestDescription(getDescription());
|
||||
// nothing to execute
|
||||
} else if (!params.stack.included) {
|
||||
++params.invalidCount;
|
||||
} else {
|
||||
final Object[] NO_ARGS = new Object[0];
|
||||
try {
|
||||
testMethod.invoke(TestFmwk.this, NO_ARGS);
|
||||
++params.testCount;
|
||||
} catch( IllegalAccessException e ) {
|
||||
errln("Can't access test method " + testMethod.getName());
|
||||
} catch( InvocationTargetException e ) {
|
||||
@ -360,7 +339,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
+" accessed under name " + name);
|
||||
}
|
||||
}
|
||||
params.writeTestResult(params.errorCount, params.invalidCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,24 +363,13 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
|
||||
protected void execute() {
|
||||
if (params.inDocMode()) {
|
||||
params.writeTestDescription(getDescription());
|
||||
}
|
||||
|
||||
params.indentLevel++;
|
||||
Target target = randomize(getTargets(targetName));
|
||||
int olderrorcount = params.errorCount;
|
||||
int oldinvalidcount = params.invalidCount;
|
||||
while (target != null) {
|
||||
///
|
||||
target.caller = this;
|
||||
target.run();
|
||||
target = target.next;
|
||||
}
|
||||
params.indentLevel--;
|
||||
if (flag) { // closing the printout brackets
|
||||
params.writeTestResult(olderrorcount, oldinvalidcount);
|
||||
}
|
||||
}
|
||||
|
||||
private Target randomize(Target t) {
|
||||
@ -475,6 +442,7 @@ public class TestFmwk extends AbstractTestLog {
|
||||
boolean prompt = false;
|
||||
int exitCode = 0;
|
||||
boolean usageError = false;
|
||||
String filter = null;
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
@ -529,8 +497,14 @@ public class TestFmwk extends AbstractTestLog {
|
||||
if (params.inclusion < 0 || params.inclusion > 10) {
|
||||
usageError = true;
|
||||
}
|
||||
} else if (arg.startsWith("-tfilter:")) {
|
||||
params.tfilter = arg.substring(8);
|
||||
} else if (arg.startsWith("-filter:")) {
|
||||
params.filter = arg.substring(8).toLowerCase();
|
||||
String temp = arg.substring(8).toLowerCase();
|
||||
filter = filter == null ? temp : filter + "," + temp;
|
||||
} else if (arg.startsWith("-f:")) {
|
||||
String temp = arg.substring(3).toLowerCase();
|
||||
filter = filter == null ? temp : filter + "," + temp;
|
||||
} else {
|
||||
System.out.println("*** Error: unrecognized argument: " + args[i]);
|
||||
exitCode = 1;
|
||||
@ -544,6 +518,10 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
}
|
||||
|
||||
if (filter != null) {
|
||||
params.filter = filter.toLowerCase();
|
||||
}
|
||||
|
||||
if (usageError) {
|
||||
usage();
|
||||
System.exit(exitCode);
|
||||
@ -625,7 +603,7 @@ public class TestFmwk extends AbstractTestLog {
|
||||
p = 0;
|
||||
e = targetPath.length();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
for (;;) {
|
||||
int n = targetPath.indexOf('/');
|
||||
@ -735,10 +713,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
return params.inclusion == 0;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return params.filter;
|
||||
}
|
||||
|
||||
public void msg(String message, int level, boolean incCount, boolean newln) {
|
||||
params.msg(message, level, incCount, newln);
|
||||
}
|
||||
@ -747,42 +721,6 @@ public class TestFmwk extends AbstractTestLog {
|
||||
return params.errorCount;
|
||||
}
|
||||
|
||||
/*
|
||||
protected void writeTestName(String testName) {
|
||||
indent(params.indentLevel);
|
||||
params.log.print(testName);
|
||||
params.log.flush();
|
||||
params.needLineFeed = true;
|
||||
}
|
||||
|
||||
protected void writeTestResult(int failCount, int invalidCount) {
|
||||
if (!params.needLineFeed) {
|
||||
indent(params.indentLevel);
|
||||
params.log.print("}");
|
||||
}
|
||||
params.needLineFeed = false;
|
||||
|
||||
if (failCount != 0) {
|
||||
params.log.println(" FAILED (" + failCount + " failures" +
|
||||
((invalidCount != 0) ?
|
||||
", " + invalidCount + " tests skipped)" :
|
||||
")"));
|
||||
} else if (invalidCount != 0) {
|
||||
params.log.println(" Qualified (" + invalidCount + " tests skipped)");
|
||||
} else {
|
||||
params.log.println(" Passed");
|
||||
}
|
||||
}
|
||||
|
||||
private final void indent(int distance) {
|
||||
if (params.needLineFeed) {
|
||||
params.log.println(" {");
|
||||
params.needLineFeed = false;
|
||||
}
|
||||
params.log.print(spaces.substring(0, distance * 2));
|
||||
}
|
||||
*/
|
||||
|
||||
protected TimeZone safeGetTimeZone(String id) {
|
||||
TimeZone tz = TimeZone.getTimeZone(id);
|
||||
if (tz == null) {
|
||||
@ -807,10 +745,19 @@ public class TestFmwk extends AbstractTestLog {
|
||||
System.out.println(" -e<n> Set exhaustiveness from 0..10. Default is 0, fewest tests.\n" +
|
||||
" To run all tests, specify -e10. Giving -e with no <n> is\n" +
|
||||
" the same as -e5.");
|
||||
System.out.println(" -filter:<str> Filters away test methods with \n"
|
||||
+ " names that do not contain the \n"
|
||||
+ " argument <str>.\n"
|
||||
+ " This operation is case insensitive.");
|
||||
System.out.println(" -filter:<str> Only tests matching filter will be run or listed.\n"
|
||||
+ " <str> is of the form ['^']text[','['^']text].\n"
|
||||
+ " Each string delimited by ',' is a separate filter argument.\n"
|
||||
+ " If '^' is prepended to the argument, the matches are excluded.\n"
|
||||
+ " Filtering operates on test groups as well as tests, if a test\n"
|
||||
+ " group is included, all subtests that are not excluded will be\n"
|
||||
+ " run. Examples:\n"
|
||||
+ " -filter:A -- only tests matching A are run. If A matches a group,\n"
|
||||
+ " all subtests of this group are run.\n"
|
||||
+ " -filter:^A -- all tests except those matching A are run. If A matches\n"
|
||||
+" a group, no subtest of that group will be run.\n"
|
||||
+ " -filter:A,B,^C,^D -- tests matching A or B and not C and not D are run\n"
|
||||
+ " Note: Filters are case insensitive.");
|
||||
System.out.println(" -h[elp] Print this help text and exit.");
|
||||
System.out.println(" -l[ist] List immediate targets of this test");
|
||||
System.out.println(" -la, -listAll List immediate targets of this test, and all subtests");
|
||||
@ -821,6 +768,7 @@ public class TestFmwk extends AbstractTestLog {
|
||||
System.out.println(" -r[andom][:<n>] If present, randomize targets. If n is present,\n" +
|
||||
" use it as the seed. If random is not set, targets will\n" +
|
||||
" be in alphabetical order to ensure cross-platform consistency.");
|
||||
System.out.println(" -tfilter:<str> Transliterator Test filter of ids.");
|
||||
System.out.println(" -v[erbose] Show log messages");
|
||||
System.out.println(" -w[arning] Continue in presence of warnings, and disable missing test warnings.");
|
||||
System.out.println(" -nodata | -nd Do not warn if resource data is not present.");
|
||||
@ -933,27 +881,40 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestParams {
|
||||
public boolean prompt = false;
|
||||
public boolean nothrow = false;
|
||||
public boolean verbose = false;
|
||||
public boolean quiet = false;
|
||||
public int listlevel = 0;;
|
||||
public boolean describe = false;
|
||||
public boolean warnings = false;
|
||||
public boolean nodata = false;
|
||||
public int inclusion = 0;
|
||||
public String filter = null;
|
||||
public long seed = 0;
|
||||
// filters
|
||||
// match against the entire hierarchy
|
||||
// A;B;!C;!D --> (A ||B) && (!C && !D)
|
||||
// positive, negative, unknown matches
|
||||
// positive -- known to be included, negative- known to be excluded
|
||||
// positive only if no excludes, and matches at least one include, if any
|
||||
// negative only if matches at least one exclude
|
||||
// otherwise, we wait
|
||||
|
||||
public PrintWriter log = new ASCIIWriter(System.out, true);
|
||||
public int indentLevel = 0;
|
||||
public boolean needLineFeed = false;
|
||||
public boolean suppressIndent = false;
|
||||
public int errorCount = 0;
|
||||
public int warnCount = 0;
|
||||
public int invalidCount = 0;
|
||||
public Random random = null;
|
||||
public static class TestParams {
|
||||
public boolean prompt;
|
||||
public boolean nothrow;
|
||||
public boolean verbose;
|
||||
public boolean quiet;
|
||||
public int listlevel;
|
||||
public boolean describe;
|
||||
public boolean warnings;
|
||||
public boolean nodata;
|
||||
public int inclusion;
|
||||
public String filter;
|
||||
public long seed;
|
||||
public String tfilter; // for transliterator tests
|
||||
|
||||
private State stack;
|
||||
|
||||
private PrintWriter log = new ASCIIWriter(System.out, true);
|
||||
private int indentLevel;
|
||||
private boolean needLineFeed;
|
||||
private boolean suppressIndent;
|
||||
private int errorCount;
|
||||
private int warnCount;
|
||||
private int invalidCount;
|
||||
private int testCount;
|
||||
public Random random;
|
||||
|
||||
public void init() {
|
||||
indentLevel = 0;
|
||||
@ -962,9 +923,73 @@ public class TestFmwk extends AbstractTestLog {
|
||||
errorCount = 0;
|
||||
warnCount = 0;
|
||||
invalidCount = 0;
|
||||
testCount = 0;
|
||||
random = seed == 0 ? null : new Random(seed);
|
||||
}
|
||||
|
||||
private class State {
|
||||
State link;
|
||||
String name;
|
||||
StringBuffer buffer;
|
||||
int level;
|
||||
int ec;
|
||||
int wc;
|
||||
int ic;
|
||||
int tc;
|
||||
boolean flushed;
|
||||
boolean included;
|
||||
|
||||
public State(State link, String name, boolean included) {
|
||||
this.link = link;
|
||||
this.name = name;
|
||||
if (link == null) {
|
||||
this.level = 0;
|
||||
this.included = included;
|
||||
} else {
|
||||
this.level = link.level + 1;
|
||||
this.included = included || link.included;
|
||||
}
|
||||
this.ec = errorCount;
|
||||
this.wc = warnCount;
|
||||
this.ic = invalidCount;
|
||||
this.tc = testCount;
|
||||
|
||||
if (link == null || this.included) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
void flush() {
|
||||
if (!flushed) {
|
||||
if (link != null) {
|
||||
link.flush();
|
||||
}
|
||||
|
||||
indent(level);
|
||||
log.print(name);
|
||||
log.flush();
|
||||
|
||||
flushed = true;
|
||||
|
||||
needLineFeed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void push(String name, String description, boolean included) {
|
||||
if (inDocMode() && describe && description != null) {
|
||||
name += ": " + description;
|
||||
}
|
||||
stack = new State(stack, name, included);
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
if (stack != null) {
|
||||
writeTestResult(stack.ec, stack.ic, stack.tc);
|
||||
stack = stack.link;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inDocMode() {
|
||||
return describe || listlevel != 0;
|
||||
}
|
||||
@ -980,8 +1005,47 @@ public class TestFmwk extends AbstractTestLog {
|
||||
public boolean doRecurseGroupsOnly() {
|
||||
return inDocMode() && (listlevel == 2 || (indentLevel == 1 && listlevel > 0));
|
||||
}
|
||||
|
||||
public void msg(String message, int level, boolean incCount, boolean newln) {
|
||||
|
||||
public int filter(String testName) {
|
||||
int result = 0;
|
||||
if (filter == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
boolean noIncludes = true;
|
||||
boolean noExcludes = filter.indexOf('^') == -1;
|
||||
testName = testName.toLowerCase();
|
||||
int ix = 0;
|
||||
while (ix < filter.length()) {
|
||||
int nix = filter.indexOf(',', ix);
|
||||
if (nix == -1) {
|
||||
nix = filter.length();
|
||||
}
|
||||
if (filter.charAt(ix) == '^') {
|
||||
if (testName.indexOf(filter.substring(ix + 1, nix)) != -1) {
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
noIncludes = false;
|
||||
if (testName.indexOf(filter.substring(ix, nix)) != -1) {
|
||||
result = 1;
|
||||
if (noExcludes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ix = nix + 1;
|
||||
}
|
||||
if (result == 0 && noIncludes) {
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
// System.out.println("filter: " + testName + " returns: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void msg(String message, int level, boolean incCount, boolean newln) {
|
||||
if (level == WARN && !warnings) {
|
||||
level = ERR;
|
||||
}
|
||||
@ -1017,17 +1081,11 @@ public class TestFmwk extends AbstractTestLog {
|
||||
suppressIndent = !newln;
|
||||
}
|
||||
|
||||
private void writeTestName(String testName) {
|
||||
indent(indentLevel);
|
||||
log.print(testName);
|
||||
log.flush();
|
||||
needLineFeed = true;
|
||||
}
|
||||
|
||||
public void writeTestInvalid(String name) {
|
||||
private void writeTestInvalid(String name) {
|
||||
// msg("***" + name + "*** not found or not valid.", WARN, true, true);
|
||||
if (inDocMode()) {
|
||||
if (!warnings) {
|
||||
writeTestName(name);
|
||||
stack.flush();
|
||||
log.println(" *** Target not found or not valid.");
|
||||
log.flush();
|
||||
needLineFeed = false;
|
||||
@ -1037,15 +1095,7 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTestDescription(String description) {
|
||||
if (describe && description != null) {
|
||||
log.println(": " + description);
|
||||
log.flush();
|
||||
needLineFeed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTestResult(int oldFail, int oldInvalid) {
|
||||
private void writeTestResult(int oldFail, int oldInvalid, int oldTestCount) {
|
||||
if (inDocMode()) {
|
||||
if (needLineFeed) {
|
||||
log.println();
|
||||
@ -1057,6 +1107,12 @@ public class TestFmwk extends AbstractTestLog {
|
||||
|
||||
int errorDelta = errorCount - oldFail;
|
||||
int invalidDelta = invalidCount - oldInvalid;
|
||||
int testDelta = testCount - oldTestCount;
|
||||
if (testDelta == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
stack.flush();
|
||||
|
||||
if (!needLineFeed) {
|
||||
indent(indentLevel);
|
||||
@ -1095,6 +1151,10 @@ public class TestFmwk extends AbstractTestLog {
|
||||
}
|
||||
}
|
||||
|
||||
public String getTranslitTestFilter() {
|
||||
return params.tfilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target name for a test class. This is either the
|
||||
* end of the class name, or if the class declares a public static
|
||||
|
Loading…
Reference in New Issue
Block a user