pluotsorbet/tests/RunTests.java

135 строки
3.5 KiB
Java
Исходник Обычный вид История

2014-07-27 01:19:59 +04:00
import gnu.testlet.*;
2014-09-03 04:14:30 +04:00
import javax.microedition.midlet.*;
import java.util.Vector;
2014-09-03 04:14:30 +04:00
public class RunTests extends MIDlet {
2014-07-27 01:19:59 +04:00
private static class Harness extends TestHarness {
2014-08-26 19:59:10 +04:00
private String testName;
private int testNumber = 0;
private String testNote = null;
private int pass = 0;
private int fail = 0;
private int knownFail = 0;
private int unknownPass = 0;
2014-07-27 01:19:59 +04:00
2014-08-26 19:59:10 +04:00
public Harness(String note) {
this.testName = note;
}
2014-07-27 01:19:59 +04:00
2014-08-26 19:59:10 +04:00
public void setNote(String note) {
testNote = note;
}
2014-07-27 01:19:59 +04:00
2014-08-26 19:59:10 +04:00
public void debug(String msg) {
System.out.println(testName + "-" + testNumber + ": " + msg + ((testNote != null) ? (" [" + testNote + "]") : ""));
}
2014-07-27 01:19:59 +04:00
2014-08-26 19:59:10 +04:00
public void check(boolean ok) {
if (ok) {
2014-08-26 19:59:10 +04:00
++pass;
}
2014-08-26 19:59:10 +04:00
else {
++fail;
debug("fail");
}
++testNumber;
setNote(null);
}
2014-07-27 01:19:59 +04:00
public void todo(boolean ok) {
if (ok)
++unknownPass;
else
++knownFail;
++testNumber;
setNote(null);
}
2014-08-26 19:59:10 +04:00
public void report() {
System.out.println(testName + ": " + pass + " pass, " + fail + " fail");
}
2014-07-29 20:36:28 +04:00
2014-08-26 19:59:10 +04:00
public int passed() {
return pass;
}
2014-07-29 20:36:28 +04:00
2014-08-26 19:59:10 +04:00
public int failed() {
return fail;
}
public int knownFailed() {
return knownFail;
}
public int unknownPassed() {
return unknownPass;
}
2014-07-27 01:19:59 +04:00
};
int pass = 0, fail = 0, knownFail = 0, unknownPass = 0;
void runTest(String name) {
name = name.replace('/', '.');
Harness harness = new Harness(name);
Class c = null;
try {
c = Class.forName(name);
} catch (Exception e) {
System.err.println(e);
harness.fail("Can't load test");
}
Object obj = null;
try {
obj = c.newInstance();
} catch (Exception e) {
System.err.println(e);
harness.fail("Can't instantiate test");
}
Testlet t = (Testlet) obj;
t.test(harness);
if (harness.failed() > 0)
harness.report();
pass += harness.passed();
fail += harness.failed();
knownFail += harness.knownFailed();
unknownPass += harness.unknownPassed();
}
2014-09-03 04:14:30 +04:00
public void startApp() {
2014-10-23 02:47:47 +04:00
String arg = getAppProperty("arg-0");
2014-10-23 02:47:47 +04:00
if (arg != null && arg.length() > 0) {
Vector v = new Vector();
2014-10-23 02:47:47 +04:00
for (int n = 0; n < Testlets.list.length; ++n) {
v.addElement(Testlets.list[n]);
}
2014-10-23 02:47:47 +04:00
int i = 0;
while (arg != null && arg.length() > 0) {
if (v.contains(arg)) {
runTest(arg);
} else {
System.err.println("can't find test " + arg);
}
arg = getAppProperty("arg-" + ++i);
2014-08-26 19:59:10 +04:00
}
} else {
for (int n = 0; n < Testlets.list.length; ++n) {
String name = Testlets.list[n];
if (name == null)
break;
runTest(name);
2014-08-26 19:59:10 +04:00
}
}
System.out.println("DONE: " + pass + " pass, " + fail + " fail, " + knownFail + " known fail, " + unknownPass + " unknown pass");
2014-07-27 01:19:59 +04:00
}
2014-09-03 04:14:30 +04:00
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
};