1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Mon Jan 07 18:27:01 2013 +0100
1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 11:59:25 2013 +0100
1.3 @@ -20,6 +20,7 @@
1.4 import java.io.File;
1.5 import java.io.FileWriter;
1.6 import java.io.IOException;
1.7 +import java.lang.reflect.Constructor;
1.8 import java.lang.reflect.InvocationTargetException;
1.9 import java.lang.reflect.Method;
1.10 import java.util.Map;
1.11 @@ -37,21 +38,56 @@
1.12 private final Method m;
1.13 private final Launcher l;
1.14 private final String type;
1.15 + private final boolean fail;
1.16 Object value;
1.17 private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
1.18 private Object inst;
1.19
1.20 - Bck2BrwsrCase(Method m, String type, Launcher l) {
1.21 + Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail) {
1.22 this.l = l;
1.23 this.m = m;
1.24 this.type = type;
1.25 + this.fail = fail;
1.26 }
1.27
1.28 @Test(groups = "run")
1.29 public void executeCode() throws Throwable {
1.30 if (l != null) {
1.31 MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName());
1.32 - value = c.toString();
1.33 + String res = c.toString();
1.34 + value = res;
1.35 + if (fail) {
1.36 + int idx = res.indexOf(':');
1.37 + if (idx >= 0) {
1.38 + Class<? extends Throwable> thrwbl = null;
1.39 + try {
1.40 + Class<?> exCls = Class.forName(res.substring(0, idx));
1.41 + if (Throwable.class.isAssignableFrom(exCls)) {
1.42 + thrwbl = exCls.asSubclass(Throwable.class);
1.43 + }
1.44 + } catch (Exception ex) {
1.45 + // ignore
1.46 + }
1.47 + if (thrwbl != null) {
1.48 + Throwable t = null;
1.49 + try {
1.50 + for (Constructor<?> cnstr : thrwbl.getConstructors()) {
1.51 + if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
1.52 + t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
1.53 + break;
1.54 + }
1.55 + }
1.56 + } catch (Throwable ex) {
1.57 + t = thrwbl.newInstance().initCause(ex);
1.58 + }
1.59 + if (t == null) {
1.60 + t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
1.61 + }
1.62 + throw t;
1.63 + }
1.64 + throw new AssertionError(res);
1.65 + }
1.66 + }
1.67 } else {
1.68 try {
1.69 value = m.invoke(m.getDeclaringClass().newInstance());