mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add option to suppress decoding stack when running JUnit tests
This commit is contained in:
parent
b018e61615
commit
1c09a52ef9
|
@ -43,7 +43,7 @@ install:
|
||||||
- rm -rf tools/idea/idea-artifacts/dependencies
|
- rm -rf tools/idea/idea-artifacts/dependencies
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- $MVN_CMD -e install -Dteavm.junit.optimized=false -P with-idea -P with-cli -Dteavm.junit.js.runner=none -V
|
- $MVN_CMD -e install -Dteavm.junit.optimized=false -Dteavm.junit.js.decodeStack=false -P with-idea -P with-cli -Dteavm.junit.js.runner=none -V
|
||||||
- BASE_PATH=`pwd`
|
- BASE_PATH=`pwd`
|
||||||
- pushd tests/src/test/js
|
- pushd tests/src/test/js
|
||||||
- "export DISPLAY=:99.0"
|
- "export DISPLAY=:99.0"
|
||||||
|
|
|
@ -67,8 +67,9 @@ class HtmlUnitRunStrategy implements TestRunStrategy {
|
||||||
Object[] args = new Object[] { new NativeJavaObject(function, asyncResult, AsyncResult.class) };
|
Object[] args = new Object[] { new NativeJavaObject(function, asyncResult, AsyncResult.class) };
|
||||||
page.get().executeJavaScriptFunctionIfPossible(function, function, args, page.get());
|
page.get().executeJavaScriptFunctionIfPossible(function, function, args, page.get());
|
||||||
|
|
||||||
RhinoResultParser.parseResult((Scriptable) asyncResult.getResult(), run.getCallback(),
|
boolean decodeStack = Boolean.parseBoolean(System.getProperty(TeaVMTestRunner.JS_DECODE_STACK, "true"));
|
||||||
new File(run.getBaseDirectory(), run.getFileName() + ".teavmdbg"));
|
File debugFile = decodeStack ? new File(run.getBaseDirectory(), run.getFileName() + ".teavmdbg") : null;
|
||||||
|
RhinoResultParser.parseResult((Scriptable) asyncResult.getResult(), run.getCallback(), debugFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUp() {
|
private void cleanUp() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -50,21 +51,30 @@ final class RhinoResultParser {
|
||||||
callback.complete();
|
callback.complete();
|
||||||
break;
|
break;
|
||||||
case "exception": {
|
case "exception": {
|
||||||
DebugInformation debugInformation = getDebugInformation(debugFile);
|
DebugInformation debugInformation = debugFile != null ? getDebugInformation(debugFile) : null;
|
||||||
|
|
||||||
String className = String.valueOf(result.get("className", result));
|
String className = String.valueOf(result.get("className", result));
|
||||||
String decodedName = debugInformation.getClassNameByJsName(className);
|
if (debugInformation != null) {
|
||||||
if (decodedName != null) {
|
String decodedName = debugInformation.getClassNameByJsName(className);
|
||||||
className = decodedName;
|
if (decodedName != null) {
|
||||||
|
className = decodedName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String message = String.valueOf(result.get("message", result));
|
String message = String.valueOf(result.get("message", result));
|
||||||
|
|
||||||
String stack = result.get("stack", result).toString();
|
String stack = result.get("stack", result).toString();
|
||||||
String[] script = getScript(new File(debugFile.getParentFile(),
|
StackTraceElement[] decodedStack = null;
|
||||||
debugFile.getName().substring(0, debugFile.getName().length() - 9)));
|
if (debugInformation != null) {
|
||||||
StackTraceElement[] decodedStack = decodeStack(stack, script, debugInformation);
|
String[] script = getScript(new File(debugFile.getParentFile(),
|
||||||
if (decodedStack != null) {
|
debugFile.getName().substring(0, debugFile.getName().length() - 9)));
|
||||||
|
List<StackTraceElement> elements = new ArrayList<>();
|
||||||
|
elements.addAll(Arrays.asList(decodeStack(stack, script, debugInformation)));
|
||||||
|
List<StackTraceElement> currentElements = Arrays.asList(Thread.currentThread().getStackTrace());
|
||||||
|
elements.addAll(currentElements.subList(2, currentElements.size()));
|
||||||
|
decodedStack = elements.toArray(new StackTraceElement[0]);
|
||||||
stack = "";
|
stack = "";
|
||||||
|
} else {
|
||||||
|
stack = "\n" + stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
Throwable e;
|
Throwable e;
|
||||||
|
@ -73,7 +83,9 @@ final class RhinoResultParser {
|
||||||
} else {
|
} else {
|
||||||
e = new RuntimeException(className + ": " + message + stack);
|
e = new RuntimeException(className + ": " + message + stack);
|
||||||
}
|
}
|
||||||
e.setStackTrace(decodedStack);
|
if (decodedStack != null) {
|
||||||
|
e.setStackTrace(decodedStack);
|
||||||
|
}
|
||||||
callback.error(e);
|
callback.error(e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class TeaVMTestRunner extends Runner implements Filterable {
|
||||||
private static final String JS_RUNNER = "teavm.junit.js.runner";
|
private static final String JS_RUNNER = "teavm.junit.js.runner";
|
||||||
private static final String THREAD_COUNT = "teavm.junit.js.threads";
|
private static final String THREAD_COUNT = "teavm.junit.js.threads";
|
||||||
private static final String JS_ENABLED = "teavm.junit.js";
|
private static final String JS_ENABLED = "teavm.junit.js";
|
||||||
|
static final String JS_DECODE_STACK = "teavm.junit.js.decodeStack";
|
||||||
private static final String C_ENABLED = "teavm.junit.c";
|
private static final String C_ENABLED = "teavm.junit.c";
|
||||||
private static final String WASM_ENABLED = "teavm.junit.wasm";
|
private static final String WASM_ENABLED = "teavm.junit.wasm";
|
||||||
private static final String C_COMPILER = "teavm.junit.c.compiler";
|
private static final String C_COMPILER = "teavm.junit.c.compiler";
|
||||||
|
@ -552,33 +553,39 @@ public class TeaVMTestRunner extends Runner implements Filterable {
|
||||||
|
|
||||||
private CompileResult compileToJs(Method method, TeaVMTestConfiguration<JavaScriptTarget> configuration,
|
private CompileResult compileToJs(Method method, TeaVMTestConfiguration<JavaScriptTarget> configuration,
|
||||||
File path) {
|
File path) {
|
||||||
|
boolean decodeStack = Boolean.parseBoolean(System.getProperty(JS_DECODE_STACK, "true"));
|
||||||
DebugInformationBuilder debugEmitter = new DebugInformationBuilder();
|
DebugInformationBuilder debugEmitter = new DebugInformationBuilder();
|
||||||
Supplier<JavaScriptTarget> targetSupplier = () -> {
|
Supplier<JavaScriptTarget> targetSupplier = () -> {
|
||||||
JavaScriptTarget target = new JavaScriptTarget();
|
JavaScriptTarget target = new JavaScriptTarget();
|
||||||
target.setDebugEmitter(debugEmitter);
|
if (decodeStack) {
|
||||||
|
target.setDebugEmitter(debugEmitter);
|
||||||
|
}
|
||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
CompilePostProcessor postBuild = (vm, file) -> {
|
CompilePostProcessor postBuild = null;
|
||||||
DebugInformation debugInfo = debugEmitter.getDebugInformation();
|
if (decodeStack) {
|
||||||
File sourceMapsFile = new File(file.getPath() + ".map");
|
postBuild = (vm, file) -> {
|
||||||
File debugFile = new File(file.getPath() + ".teavmdbg");
|
DebugInformation debugInfo = debugEmitter.getDebugInformation();
|
||||||
try {
|
File sourceMapsFile = new File(file.getPath() + ".map");
|
||||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file, true), UTF_8)) {
|
File debugFile = new File(file.getPath() + ".teavmdbg");
|
||||||
writer.write("\n//# sourceMappingURL=");
|
try {
|
||||||
writer.write(sourceMapsFile.getName());
|
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file, true), UTF_8)) {
|
||||||
}
|
writer.write("\n//# sourceMappingURL=");
|
||||||
|
writer.write(sourceMapsFile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), UTF_8)) {
|
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), UTF_8)) {
|
||||||
debugInfo.writeAsSourceMaps(sourceMapsOut, "", file.getPath());
|
debugInfo.writeAsSourceMaps(sourceMapsOut, "", file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
try (OutputStream out = new FileOutputStream(debugFile)) {
|
try (OutputStream out = new FileOutputStream(debugFile)) {
|
||||||
debugInfo.write(out);
|
debugInfo.write(out);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
};
|
||||||
throw new RuntimeException(e);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
return compileTest(method, configuration, targetSupplier, TestEntryPoint.class.getName(), path, ".js",
|
return compileTest(method, configuration, targetSupplier, TestEntryPoint.class.getName(), path, ".js",
|
||||||
postBuild);
|
postBuild);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user