IDEA: don't try to create run configuration by JUnit and TestNG producers for Kotlin JS modules.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
|
||||
@@ -65,6 +66,10 @@ public class JetJUnitConfigurationProducer extends RuntimeConfigurationProducer
|
||||
|
||||
JetFile jetFile = (JetFile) leaf.getContainingFile();
|
||||
|
||||
if (ProjectStructureUtil.isJsKotlinModule(jetFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JetNamedFunction function = PsiTreeUtil.getParentOfType(leaf, JetNamedFunction.class, false);
|
||||
if (function != null) {
|
||||
myElement = function;
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.theoryinpractice.testng.configuration.TestNGConfigurationProducer;
|
||||
import com.theoryinpractice.testng.util.TestNGUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
|
||||
@@ -62,6 +63,10 @@ public class JetTestNgConfigurationProducer extends TestNGConfigurationProducer
|
||||
|
||||
JetFile jetFile = (JetFile) leaf.getContainingFile();
|
||||
|
||||
if (ProjectStructureUtil.isJsKotlinModule(jetFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JetNamedFunction function = PsiTreeUtil.getParentOfType(leaf, JetNamedFunction.class, false);
|
||||
if (function != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package q
|
||||
|
||||
native
|
||||
class Foo {
|
||||
// RUN:
|
||||
fun foo(s: Array<String>) = noImpl
|
||||
}
|
||||
|
||||
|
||||
// RUN:
|
||||
native
|
||||
fun main(s: Array<String>) {
|
||||
println("Top-level")
|
||||
}
|
||||
@@ -47,8 +47,9 @@ import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.test.ConfigLibraryUtil
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
|
||||
private val RUN_PREFIX = "// RUN: "
|
||||
private val RUN_PREFIX = "// RUN:"
|
||||
|
||||
class RunConfigurationTest: CodeInsightTestCase() {
|
||||
fun getTestProject() = myProject!!
|
||||
@@ -87,11 +88,19 @@ class RunConfigurationTest: CodeInsightTestCase() {
|
||||
}
|
||||
|
||||
fun testClassesAndObjects() {
|
||||
doTest(ConfigLibraryUtil::configureKotlinRuntime)
|
||||
}
|
||||
|
||||
fun testInJsModule() {
|
||||
doTest(ConfigLibraryUtil::configureKotlinJsRuntime)
|
||||
}
|
||||
|
||||
private fun doTest(configureRuntime: (Module, Sdk) -> Unit) {
|
||||
val baseDir = getTestProject().getBaseDir()!!
|
||||
val createModuleResult = configureModule(moduleDirPath("module"), baseDir)
|
||||
val srcDir = createModuleResult.srcDir
|
||||
|
||||
ConfigLibraryUtil.configureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
||||
configureRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
||||
|
||||
try {
|
||||
val expectedClasses = ArrayList<String>()
|
||||
@@ -99,13 +108,14 @@ class RunConfigurationTest: CodeInsightTestCase() {
|
||||
|
||||
val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt"))
|
||||
testFile.accept(
|
||||
object: JetTreeVisitorVoid() {
|
||||
object : JetTreeVisitorVoid() {
|
||||
override fun visitComment(comment: PsiComment) {
|
||||
val declaration = comment.getStrictParentOfType<JetNamedDeclaration>()!!
|
||||
val text = comment.getText() ?: return
|
||||
if (!text.startsWith(RUN_PREFIX)) return
|
||||
|
||||
expectedClasses.add(text.substring(RUN_PREFIX.length()).trim())
|
||||
val expectedClass = text.substring(RUN_PREFIX.length()).trim()
|
||||
if (expectedClass.isNotEmpty()) expectedClasses.add(expectedClass)
|
||||
|
||||
val dataContext = MapDataContext()
|
||||
dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration))
|
||||
|
||||
@@ -26,27 +26,34 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Helper for configuring kotlin runtime in tested project.
|
||||
*/
|
||||
public class ConfigLibraryUtil {
|
||||
private static final String DEFAULT_JAVA_RUNTIME_LIB_NAME = "JAVA_RUNTIME_LIB_NAME";
|
||||
private static final String DEFAULT_KOTLIN_JS_STDLIB_NAME = "KOTLIN_JS_STDLIB_NAME";
|
||||
|
||||
private ConfigLibraryUtil() {
|
||||
}
|
||||
|
||||
private static NewLibraryEditor getKotlinRuntimeLibEditor(String libName) {
|
||||
private static NewLibraryEditor getKotlinRuntimeLibEditor(String libName, File library) {
|
||||
NewLibraryEditor editor = new NewLibraryEditor();
|
||||
editor.setName(libName);
|
||||
editor.addRoot(VfsUtil.getUrlForLibraryRoot(ForTestCompileRuntime.runtimeJarForTests()), OrderRootType.CLASSES);
|
||||
editor.addRoot(VfsUtil.getUrlForLibraryRoot(library), OrderRootType.CLASSES);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
public static void configureKotlinRuntime(Module module, Sdk sdk) {
|
||||
configureLibrary(module, sdk, getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME));
|
||||
configureLibrary(module, sdk, getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME, PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()));
|
||||
}
|
||||
|
||||
public static void configureKotlinJsRuntime(Module module, Sdk sdk) {
|
||||
configureLibrary(module, sdk, getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_JS_STDLIB_NAME, PathUtil.getKotlinPathsForDistDirectory().getJsStdLibJarPath()));
|
||||
}
|
||||
|
||||
public static void unConfigureKotlinRuntime(Module module, Sdk sdk) {
|
||||
|
||||
Reference in New Issue
Block a user