KJS: remove obsolete kotlin.modules
This commit is contained in:
@@ -49,6 +49,10 @@ public class AntTaskJsTest extends AbstractAntTaskTest {
|
||||
}
|
||||
|
||||
private void doJsAntTest(String... jsFiles) throws Exception {
|
||||
doJsAntTest(false, jsFiles);
|
||||
}
|
||||
|
||||
private void doJsAntTest(boolean withModuleSystem, String... jsFiles) throws Exception {
|
||||
doTest();
|
||||
|
||||
List<String> fileNames = new ArrayList<String>(Arrays.asList(jsFiles));
|
||||
@@ -61,7 +65,7 @@ public class AntTaskJsTest extends AbstractAntTaskTest {
|
||||
}
|
||||
});
|
||||
|
||||
RhinoUtils.runRhinoTest(filePaths, new RhinoFunctionResultChecker("out", "foo", "box", "OK"));
|
||||
RhinoUtils.runRhinoTest(filePaths, new RhinoFunctionResultChecker("out", "foo", "box", "OK", withModuleSystem));
|
||||
}
|
||||
|
||||
private void doJsAntTestForPostfixPrefix(@Nullable String prefix, @Nullable String postfix) throws Exception {
|
||||
@@ -121,7 +125,7 @@ public class AntTaskJsTest extends AbstractAntTaskTest {
|
||||
}
|
||||
|
||||
public void testSimpleWithStdlibAndJsFileAsAnotherLibModuleKind() throws Exception {
|
||||
doJsAntTest("amd.js", "jslib-example.js");
|
||||
doJsAntTest(true, "amd.js", "jslib-example.js");
|
||||
}
|
||||
|
||||
public void testSimpleWithStdlibAndTwoJsFilesAsLibraries() throws Exception {
|
||||
|
||||
@@ -99,7 +99,6 @@ abstract class BasicBoxTest(
|
||||
val mainModuleName = if (TEST_MODULE in modules) TEST_MODULE else DEFAULT_MODULE
|
||||
val mainModule = modules[mainModuleName]!!
|
||||
|
||||
val checker = RhinoFunctionResultChecker(mainModuleName, testFactory.testPackage, TEST_FUNCTION, "OK")
|
||||
val globalCommonFiles = JsTestUtils.getFilesInDirectoryByExtension(
|
||||
TEST_DATA_DIR_PATH + COMMON_FILES_DIR, JavaScript.EXTENSION)
|
||||
val localCommonFile = file.parent + "/" + COMMON_FILES_NAME + JavaScript.DOT_EXTENSION
|
||||
@@ -118,9 +117,13 @@ abstract class BasicBoxTest(
|
||||
}
|
||||
|
||||
val additionalFiles = mutableListOf<String>()
|
||||
if ((modules.size > 1 || MODULE_KIND_PATTERN.matcher(expectedText).find()) &&
|
||||
!NO_MODULE_SYSTEM_PATTERN.matcher(expectedText).find()
|
||||
) {
|
||||
|
||||
val moduleKindMatcher = MODULE_KIND_PATTERN.matcher(expectedText)
|
||||
val moduleKind = if (moduleKindMatcher.find()) ModuleKind.valueOf(moduleKindMatcher.group(1)) else ModuleKind.PLAIN
|
||||
|
||||
val withModuleSystem = moduleKind != ModuleKind.PLAIN && !NO_MODULE_SYSTEM_PATTERN.matcher(expectedText).find()
|
||||
|
||||
if (withModuleSystem) {
|
||||
additionalFiles += MODULE_EMULATION_FILE
|
||||
}
|
||||
|
||||
@@ -138,6 +141,7 @@ abstract class BasicBoxTest(
|
||||
FileUtil.writeToFile(File(nodeRunnerName), nodeRunnerText)
|
||||
}
|
||||
|
||||
val checker = RhinoFunctionResultChecker(mainModuleName, testFactory.testPackage, TEST_FUNCTION, "OK", withModuleSystem)
|
||||
RhinoUtils.runRhinoTest(allJsFiles, checker)
|
||||
}
|
||||
}
|
||||
@@ -153,7 +157,7 @@ abstract class BasicBoxTest(
|
||||
val fileName = FileUtil.getRelativePath(dir, File(file))!!
|
||||
sb.append("text += fs.readFileSync(__dirname + \"/$fileName\") + \"\\n\";\n")
|
||||
}
|
||||
sb.append("text += 'return kotlin.modules.$moduleName;';\n")
|
||||
sb.append("text += 'return $moduleName;';\n")
|
||||
sb.append("text += \"};\";\n")
|
||||
|
||||
val fqn = testPackage?.let { ".$it" } ?: ""
|
||||
|
||||
+22
-5
@@ -30,12 +30,24 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
private final String packageName;
|
||||
private final String functionName;
|
||||
private final Object expectedResult;
|
||||
private final boolean withModuleSystem;
|
||||
|
||||
public RhinoFunctionResultChecker(@NotNull String moduleId, @Nullable String packageName, @NotNull String functionName, @NotNull Object expectedResult) {
|
||||
this(moduleId, packageName, functionName, expectedResult, false);
|
||||
}
|
||||
|
||||
public RhinoFunctionResultChecker(
|
||||
@NotNull String moduleId,
|
||||
@Nullable String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult,
|
||||
boolean withModuleSystem
|
||||
) {
|
||||
this.moduleId = moduleId;
|
||||
this.packageName = packageName;
|
||||
this.functionName = functionName;
|
||||
this.expectedResult = expectedResult;
|
||||
this.withModuleSystem = withModuleSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,12 +68,17 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
|
||||
private String functionCallString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("kotlin.modules");
|
||||
if (moduleId.contains(".")) {
|
||||
sb.append("['").append(moduleId).append("']");
|
||||
} else {
|
||||
sb.append(".").append(moduleId);
|
||||
|
||||
if (withModuleSystem) {
|
||||
sb.append("require('").append(moduleId).append("')");
|
||||
}
|
||||
else if (moduleId.contains(".")) {
|
||||
sb.append("this['").append(moduleId).append("']");
|
||||
}
|
||||
else {
|
||||
sb.append(moduleId);
|
||||
}
|
||||
|
||||
if (packageName != null) {
|
||||
sb.append('.').append(packageName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user