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