Minor in JS tests: cleanup RhinoFunctionResultChecker and dependent classes.
This commit is contained in:
+8
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.k2js.test.rhino;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeJavaObject;
|
||||
@@ -25,12 +26,13 @@ import org.mozilla.javascript.NativeJavaObject;
|
||||
*/
|
||||
public class RhinoFunctionNativeObjectResultChecker extends RhinoFunctionResultChecker {
|
||||
|
||||
public RhinoFunctionNativeObjectResultChecker(@Nullable String packageName, String functionName, Object expectedResult) {
|
||||
super(packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
public RhinoFunctionNativeObjectResultChecker(String functionName, Object expectedResult) {
|
||||
super(functionName, expectedResult);
|
||||
public RhinoFunctionNativeObjectResultChecker(
|
||||
@NotNull String moduleName,
|
||||
@Nullable String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult
|
||||
) {
|
||||
super(moduleName, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.k2js.test.rhino;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
@@ -32,21 +32,13 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
private final String functionName;
|
||||
private final Object expectedResult;
|
||||
|
||||
public RhinoFunctionResultChecker(@Nullable String packageName, String functionName, Object expectedResult) {
|
||||
this(Config.REWRITABLE_MODULE_NAME, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
public RhinoFunctionResultChecker(@Nullable String moduleId, @Nullable String packageName, String functionName, Object expectedResult) {
|
||||
public RhinoFunctionResultChecker(@NotNull String moduleId, @Nullable String packageName, @NotNull String functionName, @NotNull Object expectedResult) {
|
||||
this.moduleId = moduleId;
|
||||
this.packageName = packageName;
|
||||
this.functionName = functionName;
|
||||
this.expectedResult = expectedResult;
|
||||
}
|
||||
|
||||
public RhinoFunctionResultChecker(String functionName, Object expectedResult) {
|
||||
this(null, functionName, expectedResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception {
|
||||
Object result = evaluateFunction(context, scope);
|
||||
@@ -57,8 +49,6 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
protected void assertResultValid(Object result, Context context) {
|
||||
String ecmaVersion = context.getLanguageVersion() == Context.VERSION_1_8 ? "ecma5" : "ecma3";
|
||||
assertEquals("Result of " + packageName + "." + functionName + "() is not what expected (" + ecmaVersion + ")!", expectedResult, result);
|
||||
String report = packageName + "." + functionName + "() = " + Context.toString(result);
|
||||
System.out.println(report);
|
||||
}
|
||||
|
||||
private Object evaluateFunction(Context cx, Scriptable scope) {
|
||||
|
||||
@@ -16,36 +16,25 @@
|
||||
|
||||
package org.jetbrains.k2js.test.rhino;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.test.config.TestConfig;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.flushSystemOut;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Runs the QUnit test cases in headless mode (without requiring a browser) and asserts they all PASS
|
||||
*/
|
||||
public class RhinoQUnitResultChecker implements RhinoResultChecker {
|
||||
|
||||
private final String moduleId;
|
||||
|
||||
public RhinoQUnitResultChecker(@Nullable String moduleId) {
|
||||
this.moduleId = moduleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception {
|
||||
Object result = evaluateFunction(context, scope);
|
||||
flushSystemOut(context, scope);
|
||||
assertResultValid(result, context);
|
||||
assertResultValid(result);
|
||||
}
|
||||
|
||||
protected void assertResultValid(Object result, Context context) {
|
||||
protected void assertResultValid(Object result) {
|
||||
if (result instanceof NativeArray) {
|
||||
NativeArray array = (NativeArray) result;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
@@ -41,8 +41,7 @@ public abstract class StdLibQUnitTestSupport extends StdLibTestBase {
|
||||
}
|
||||
|
||||
protected void runQUnitTestCase(String path, EcmaVersion version, Map<String, Object> variables) throws Exception {
|
||||
String moduleId = moduleIdFromOutputFile(path);
|
||||
RhinoResultChecker checker = new RhinoQUnitResultChecker(moduleId);
|
||||
RhinoResultChecker checker = new RhinoQUnitResultChecker();
|
||||
runRhinoTest(Lists.newArrayList(path),
|
||||
checker, variables, version,
|
||||
Lists.newArrayList(
|
||||
|
||||
Reference in New Issue
Block a user