chore: improve error reporting in tests

This commit is contained in:
Skylot
2020-09-11 19:30:58 +01:00
parent 691bf8faca
commit 50cfa4c971
3 changed files with 19 additions and 17 deletions
@@ -39,6 +39,9 @@ public class MethodTypeVarsAttr implements IAttribute {
@Override
public String toString() {
if (this == EMPTY) {
return "TYPE_VARS: EMPTY";
}
return "TYPE_VARS: " + typeVars;
}
}
@@ -40,6 +40,7 @@ import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.DebugChecks;
import jadx.core.utils.Utils;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.files.FileUtils;
import jadx.core.xmlgen.ResourceStorage;
import jadx.core.xmlgen.entry.ResourceEntry;
@@ -322,17 +323,18 @@ public abstract class IntegrationTest extends TestUtils {
}
try {
limitExecTime(() -> checkMth.invoke(origCls.getConstructor().newInstance()));
} catch (Exception e) {
rethrow("Original check failed", e);
System.out.println("Source check: PASSED");
} catch (Throwable e) {
throw new JadxRuntimeException("Source check failed", e);
}
// run 'check' method from decompiled class
if (compile) {
try {
limitExecTime(() -> invoke(cls, "check"));
} catch (Exception e) {
rethrow("Decompiled check failed", e);
System.out.println("Decompiled check: PASSED");
} catch (Throwable e) {
throw new JadxRuntimeException("Decompiled check failed", e);
}
System.out.println("Auto check: PASSED");
}
} catch (Exception e) {
e.printStackTrace();
@@ -348,7 +350,7 @@ public abstract class IntegrationTest extends TestUtils {
} catch (TimeoutException ex) {
future.cancel(true);
rethrow("Execution timeout", ex);
} catch (Exception ex) {
} catch (Throwable ex) {
rethrow(ex.getMessage(), ex);
} finally {
executor.shutdownNow();
@@ -356,18 +358,15 @@ public abstract class IntegrationTest extends TestUtils {
return null;
}
private void rethrow(String msg, Throwable e) {
public static void rethrow(String msg, Throwable e) {
if (e instanceof InvocationTargetException) {
Throwable cause = e.getCause();
if (cause instanceof AssertionError) {
throw (AssertionError) cause;
} else {
fail(cause);
}
rethrow(msg, e.getCause());
} else if (e instanceof ExecutionException) {
rethrow(e.getMessage(), e.getCause());
} else if (e instanceof AssertionError) {
throw (AssertionError) e;
} else {
fail(msg, e);
throw new RuntimeException(msg, e);
}
}
@@ -15,10 +15,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import static javax.tools.JavaCompiler.CompilationTask;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
public class DynamicCompiler {
@@ -71,8 +71,8 @@ public class DynamicCompiler {
Method reflMth = getMethod(inst, methodName, types);
assertNotNull(reflMth, "Failed to get method " + methodName + '(' + Arrays.toString(types) + ')');
return reflMth.invoke(inst, args);
} catch (Exception e) {
fail(e.getMessage(), e);
} catch (Throwable e) {
IntegrationTest.rethrow("Invoke error", e);
return null;
}
}