diff -r c91483c86597 -r 5df0a239ebeb vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Mon Jan 07 18:27:01 2013 +0100 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 11:59:25 2013 +0100 @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; @@ -37,21 +38,56 @@ private final Method m; private final Launcher l; private final String type; + private final boolean fail; Object value; private static final Map compiled = new WeakHashMap<>(); private Object inst; - Bck2BrwsrCase(Method m, String type, Launcher l) { + Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail) { this.l = l; this.m = m; this.type = type; + this.fail = fail; } @Test(groups = "run") public void executeCode() throws Throwable { if (l != null) { MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName()); - value = c.toString(); + String res = c.toString(); + value = res; + if (fail) { + int idx = res.indexOf(':'); + if (idx >= 0) { + Class thrwbl = null; + try { + Class exCls = Class.forName(res.substring(0, idx)); + if (Throwable.class.isAssignableFrom(exCls)) { + thrwbl = exCls.asSubclass(Throwable.class); + } + } catch (Exception ex) { + // ignore + } + if (thrwbl != null) { + Throwable t = null; + try { + for (Constructor cnstr : thrwbl.getConstructors()) { + if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) { + t = (Throwable) cnstr.newInstance(res.substring(idx + 1)); + break; + } + } + } catch (Throwable ex) { + t = thrwbl.newInstance().initCause(ex); + } + if (t == null) { + t = thrwbl.newInstance().initCause(new Exception(res.substring(idx))); + } + throw t; + } + throw new AssertionError(res); + } + } } else { try { value = m.invoke(m.getDeclaringClass().newInstance());