JS tests: added doTest and checkFooBoxIsOkByPath to BasicTest to simplify using generated tests.
This commit is contained in:
@@ -83,6 +83,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
this.relativePathToTestDir = relativePathToTestDir;
|
||||
}
|
||||
|
||||
protected abstract void checkFooBoxIsOkByPath(String filePath) throws Exception;
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES);
|
||||
@@ -116,13 +118,21 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
assert success;
|
||||
}
|
||||
|
||||
public void doTest(@NotNull String filePath) {
|
||||
try {
|
||||
checkFooBoxIsOkByPath(filePath);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String kotlinFilePath,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions
|
||||
) throws Exception {
|
||||
generateJavaScriptFiles(Collections.singletonList(getInputFilePath(kotlinFilename)),
|
||||
kotlinFilename, mainCallParameters, ecmaVersions);
|
||||
generateJavaScriptFiles(Collections.singletonList(kotlinFilePath), getBaseName(kotlinFilePath), mainCallParameters, ecmaVersions);
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(
|
||||
@@ -182,12 +192,12 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
protected void runRhinoTests(
|
||||
@NotNull String filename,
|
||||
@NotNull String testName,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull RhinoResultChecker checker
|
||||
) throws Exception {
|
||||
for (EcmaVersion ecmaVersion : ecmaVersions) {
|
||||
runRhinoTest(withAdditionalJsFiles(getOutputFilePath(filename, ecmaVersion), ecmaVersion),
|
||||
runRhinoTest(withAdditionalJsFiles(getOutputFilePath(testName, ecmaVersion), ecmaVersion),
|
||||
checker,
|
||||
getRhinoTestVariables(),
|
||||
ecmaVersion);
|
||||
@@ -219,8 +229,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final String getOutputFilePath(@NotNull String filename, @NotNull EcmaVersion ecmaVersion) {
|
||||
return getOutputPath() + convertFileNameToDotJsFile(filename, ecmaVersion);
|
||||
protected final String getOutputFilePath(@NotNull String testName, @NotNull EcmaVersion ecmaVersion) {
|
||||
return getOutputPath() + convertFileNameToDotJsFile(testName, ecmaVersion);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -294,4 +304,21 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
String packageName = jetFile.getPackageFqName().asString();
|
||||
return packageName.isEmpty() ? Namer.getRootPackageName() : packageName;
|
||||
}
|
||||
|
||||
protected static String getBaseName(String path) {
|
||||
String systemIndependentPath = FileUtil.toSystemIndependentName(path);
|
||||
|
||||
int start = systemIndependentPath.lastIndexOf("/");
|
||||
if (start == -1) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
int end = systemIndependentPath.lastIndexOf(".");
|
||||
if (end == -1) {
|
||||
end = path.length();
|
||||
}
|
||||
|
||||
return path.substring(start, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ public abstract class MultipleFilesTranslationTest extends BasicTest {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFooBoxIsOkByPath(String filePath) throws Exception {
|
||||
throw new UnsupportedOperationException("checkFooBoxIsOkByPath not supported yet in MultipleFilesTranslationTest");
|
||||
}
|
||||
|
||||
protected void generateJsFromDir(@NotNull String dirName, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
List<String> fullFilePaths = getAllFilesInDir(getInputFilePath(dirName));
|
||||
generateJavaScriptFiles(fullFilePaths, dirName, MainCallParameters.noCall(), ecmaVersions);
|
||||
|
||||
@@ -31,8 +31,12 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
super(main);
|
||||
}
|
||||
|
||||
public void runFunctionOutputTest(@NotNull String kotlinFilename, @NotNull String packageName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
protected void runFunctionOutputTest(
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, kotlinFilename, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
@@ -41,29 +45,36 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult) throws Exception {
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(TEST_MODULE, packageName, functionName, expectedResult));
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
runFunctionOutputTestByPath(ecmaVersions, getInputFilePath(kotlinFilename), packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
protected void runFunctionOutputTestByPath(
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String kotlinFilePath,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
generateJavaScriptFiles(kotlinFilePath, MainCallParameters.noCall(), ecmaVersions);
|
||||
runRhinoTests(getBaseName(kotlinFilePath), ecmaVersions, new RhinoFunctionResultChecker(TEST_MODULE, packageName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
private void checkFooBoxIsTrue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
runFunctionOutputTest(ecmaVersions, filename, TEST_PACKAGE, TEST_FUNCTION, true);
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename) throws Exception {
|
||||
protected void checkFooBoxIsTrue(@NotNull String filename) throws Exception {
|
||||
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, filename, TEST_PACKAGE, TEST_FUNCTION, true);
|
||||
}
|
||||
|
||||
public void checkFooBoxIsValue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions, Object expected) throws Exception {
|
||||
runFunctionOutputTest(ecmaVersions, filename, TEST_PACKAGE, TEST_FUNCTION, expected);
|
||||
}
|
||||
|
||||
protected void fooBoxTest() throws Exception {
|
||||
checkFooBoxIsTrue(getTestName(true) + ".kt", DEFAULT_ECMA_VERSIONS);
|
||||
}
|
||||
|
||||
protected void fooBoxIsValue(Object expected) throws Exception {
|
||||
checkFooBoxIsValue(getTestName(true) + ".kt", DEFAULT_ECMA_VERSIONS, expected);
|
||||
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, getTestName(true) + ".kt", TEST_PACKAGE, TEST_FUNCTION, expected);
|
||||
}
|
||||
|
||||
protected void fooBoxTest(@NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
@@ -75,19 +86,16 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
}
|
||||
|
||||
protected void checkFooBoxIsOk(@NotNull String filename) throws Exception {
|
||||
checkFooBoxIsOk(DEFAULT_ECMA_VERSIONS, filename);
|
||||
checkFooBoxIsOkByPath(getInputFilePath(filename));
|
||||
}
|
||||
|
||||
protected void checkFooBoxIsOk(@NotNull Iterable<EcmaVersion> versions, @NotNull String filename) throws Exception {
|
||||
runFunctionOutputTest(versions, filename, TEST_PACKAGE, TEST_FUNCTION, "OK");
|
||||
@Override
|
||||
protected void checkFooBoxIsOkByPath(@NotNull String filePath) throws Exception {
|
||||
runFunctionOutputTestByPath(DEFAULT_ECMA_VERSIONS, filePath, TEST_PACKAGE, TEST_FUNCTION, "OK");
|
||||
}
|
||||
|
||||
protected void checkBlackBoxIsOk(@NotNull String filename) throws Exception {
|
||||
checkBlackBoxIsOk(DEFAULT_ECMA_VERSIONS, filename);
|
||||
}
|
||||
|
||||
protected void checkBlackBoxIsOk(@NotNull Iterable<EcmaVersion> versions, @NotNull String filename) throws Exception {
|
||||
runFunctionOutputTest(versions, filename, getPackageName(filename), TEST_FUNCTION, "OK");
|
||||
protected void checkBlackBoxIsOkByPath(@NotNull String filePath) throws Exception {
|
||||
runFunctionOutputTestByPath(DEFAULT_ECMA_VERSIONS, filePath, getPackageName(filePath), TEST_FUNCTION, "OK");
|
||||
}
|
||||
|
||||
protected void checkOutput(@NotNull String kotlinFilename,
|
||||
@@ -96,22 +104,17 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
checkOutput(kotlinFilename, expectedResult, DEFAULT_ECMA_VERSIONS, args);
|
||||
}
|
||||
|
||||
protected void checkOutput(@NotNull String kotlinFilename,
|
||||
private void checkOutput(
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String expectedResult,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
String... args) throws Exception {
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.mainWithArguments(Lists.newArrayList(args)), ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoSystemOutputChecker(expectedResult));
|
||||
}
|
||||
|
||||
protected void performTestWithMain(@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String testName,
|
||||
@NotNull String testId,
|
||||
@NotNull String... args) throws Exception {
|
||||
checkOutput(testName + ".kt", readFile(expectedFilePath(testName + testId)), ecmaVersions, args);
|
||||
String... args
|
||||
) throws Exception {
|
||||
generateJavaScriptFiles(getInputFilePath(kotlinFilename), MainCallParameters.mainWithArguments(Lists.newArrayList(args)), ecmaVersions);
|
||||
runRhinoTests(getBaseName(kotlinFilename), ecmaVersions, new RhinoSystemOutputChecker(expectedResult));
|
||||
}
|
||||
|
||||
protected void performTestWithMain(@NotNull String testName, @NotNull String testId, @NotNull String... args) throws Exception {
|
||||
performTestWithMain(DEFAULT_ECMA_VERSIONS, testName, testId, args);
|
||||
checkOutput(testName + ".kt", readFile(expectedFilePath(testName + testId)), DEFAULT_ECMA_VERSIONS, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,5 @@ import org.jetbrains.k2js.test.SingleFileTranslationTest
|
||||
|
||||
public abstract class AbstractBridgeTest : SingleFileTranslationTest("bridges/") {
|
||||
|
||||
override fun getInputPath(): String = ""
|
||||
|
||||
fun doTest(filename: String) = checkBlackBoxIsOk(filename)
|
||||
override fun doTest(filename: String) = checkBlackBoxIsOkByPath(filename)
|
||||
}
|
||||
@@ -18,6 +18,4 @@ package org.jetbrains.k2js.test.semantics
|
||||
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest
|
||||
|
||||
public abstract class AbstractReservedWordTest : SingleFileTranslationTest("reservedWords/") {
|
||||
fun doTest(fileName: String) = checkFooBoxIsOk()
|
||||
}
|
||||
public abstract class AbstractReservedWordTest : SingleFileTranslationTest("reservedWords/")
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class SimpleTest extends SingleFileTranslationTest {
|
||||
|
||||
@Override
|
||||
public void runTest() throws Exception {
|
||||
checkFooBoxIsTrue(filename, DEFAULT_ECMA_VERSIONS);
|
||||
checkFooBoxIsTrue(filename);
|
||||
}
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
|
||||
@@ -42,13 +42,13 @@ public final class StdLibTest extends SingleFileTranslationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateJavaScriptFiles(@NotNull String kotlinFilename,
|
||||
protected void generateJavaScriptFiles(@NotNull String kotlinFilePath,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
List<String> files = Arrays.asList(getInputFilePath(kotlinFilename));
|
||||
List<String> files = Arrays.asList(getInputFilePath(kotlinFilePath));
|
||||
|
||||
generateJavaScriptFiles(files, kotlinFilename, mainCallParameters, ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions,
|
||||
generateJavaScriptFiles(files, kotlinFilePath, mainCallParameters, ecmaVersions);
|
||||
runRhinoTests(kotlinFilePath, ecmaVersions,
|
||||
new RhinoFunctionNativeObjectResultChecker(TEST_MODULE, "test.browser", TEST_FUNCTION, "Some Dynamically Created Content!!!"));
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class StringTest extends AbstractExpressionTest {
|
||||
|
||||
private void checkHasNoToStringCalls() throws IOException {
|
||||
for (EcmaVersion ecmaVersion : DEFAULT_ECMA_VERSIONS) {
|
||||
String filePath = getOutputFilePath(getTestName(true) + ".kt", ecmaVersion);
|
||||
String filePath = getOutputFilePath(getTestName(true), ecmaVersion);
|
||||
String text = FileUtil.loadFile(new File(filePath), /*convertLineSeparators = */ true);
|
||||
assertFalse(filePath + " should not contain toString calls", text.contains("toString"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user