[tests] fix ConfigureKotlinTest

GitOrigin-RevId: 862447d83ac0cc827d5b5e6756fb29b7c63dd79a
This commit is contained in:
Dmitry Gridin
2020-09-16 14:21:43 +03:00
committed by intellij-monorepo-bot
parent 314bae711c
commit 8323c5fa5d
12 changed files with 95 additions and 74 deletions
@@ -5,14 +5,39 @@
package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Ref
import com.intellij.util.ThrowableRunnable
import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts
import org.jetbrains.kotlin.idea.test.runAll
import org.jetbrains.kotlin.test.KotlinRoot
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
abstract class AbstractConfigureKotlinInTempDirTest : AbstractConfigureKotlinTest() {
private lateinit var vfsDisposable: Ref<Disposable>
override fun createProjectRoot(): File = KotlinTestUtils.tmpDirForReusableFolder("configure")
override fun setUp() {
super.setUp()
vfsDisposable = KotlinTestUtils.allowRootAccess(this, projectRoot.path)
}
override fun tearDown() {
runAll(
ThrowableRunnable { KotlinTestUtils.disposeVfsRootAccess(vfsDisposable) },
ThrowableRunnable { super.tearDown() }
)
}
override fun getProjectDirOrFile(isDirectoryBasedProject: Boolean): Path {
val projectRoot = super.getProjectDirOrFile(isDirectoryBasedProject)
val originalDir = KotlinRoot.DIR.resolve("idea/testData/configuration").resolve(projectName)
originalDir.copyRecursively(projectRoot)
val projectFile = projectRoot.resolve("projectFile.ipr")
val projectRoot = (if (projectFile.exists()) projectFile else projectRoot).toPath()
val kotlinRuntime = projectRoot.resolve("lib/kotlin-stdlib.jar")
if (getTestName(true).toLowerCase().contains("latestruntime") && Files.exists(kotlinRuntime)) {
@@ -1,28 +1,19 @@
package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Ref
import com.intellij.testFramework.HeavyPlatformTestCase
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.util.ThrowableRunnable
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase.addJdk
import org.jetbrains.kotlin.idea.test.runAll
import org.jetbrains.kotlin.test.KotlinRoot
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.KotlinTestUtils.disposeVfsRootAccess
import java.io.File
import java.nio.file.Path
abstract class AbstractConfigureKotlinTestBase : HeavyPlatformTestCase() {
protected lateinit var projectRoot: File
private set
private lateinit var vfsDisposable: Ref<Disposable>
protected val jvmConfigurator: KotlinJavaModuleConfigurator by lazy {
object : KotlinJavaModuleConfigurator() {
@@ -39,21 +30,15 @@ abstract class AbstractConfigureKotlinTestBase : HeavyPlatformTestCase() {
protected val modules: Array<Module>
get() = ModuleManager.getInstance(myProject).modules
private val projectName: String
protected val projectName: String
get() = getTestName(true).substringBefore("_")
override fun setUp() {
projectRoot = KotlinTestUtils.tmpDirForReusableFolder("configure")
vfsDisposable = KotlinTestUtils.allowRootAccess(this, projectRoot.path)
projectRoot = createProjectRoot()
super.setUp()
}
override fun tearDown() {
runAll(
ThrowableRunnable { disposeVfsRootAccess(vfsDisposable) },
ThrowableRunnable { super.tearDown() }
)
}
open fun createProjectRoot(): File = KotlinRoot.DIR.resolve("idea/testData/configuration").resolve(projectName)
override fun initApplication() {
super.initApplication()
@@ -68,16 +53,13 @@ abstract class AbstractConfigureKotlinTestBase : HeavyPlatformTestCase() {
}
override fun getProjectDirOrFile(isDirectoryBasedProject: Boolean): Path {
val originalDir = KotlinRoot.DIR.resolve("idea/testData/configuration").resolve(projectName)
originalDir.copyRecursively(projectRoot)
val projectFile = projectRoot.resolve("projectFile.ipr")
return (if (projectFile.exists()) projectFile else projectRoot).toPath()
}
override fun setUpModule() {
val modules = ModuleManager.getInstance(project).modules
myModule = modules.singleOrNull() ?: error("Single module expected, got $modules")
myModule = modules.first()
}
protected fun getOppositeConfigurator(configurator: KotlinWithLibraryConfigurator): KotlinWithLibraryConfigurator {
@@ -7,10 +7,13 @@ package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.impl.ApplicationImpl
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.VersionView
import org.jetbrains.kotlin.idea.artifacts.KotlinArtifactNames
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings
@@ -18,6 +21,7 @@ import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.junit.Assert
import org.junit.internal.runners.JUnit38ClassRunner
import org.junit.runner.RunWith
import java.io.File
@RunWith(JUnit38ClassRunner::class)
open class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinInTempDirTest() {
@@ -30,6 +34,29 @@ open class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinInTempDirTest()
Assert.assertTrue(project.baseDir.findFileByRelativePath(".idea/kotlinc.xml") == null)
}
fun testTwoModulesWithNonDefaultPath_doNotCopyInDefault() {
doTestConfigureModulesWithNonDefaultSetup(jvmConfigurator)
assertEmpty(getCanBeConfiguredModules(myProject, jsConfigurator))
}
fun testTwoModulesWithJSNonDefaultPath_doNotCopyInDefault() {
doTestConfigureModulesWithNonDefaultSetup(jsConfigurator)
assertEmpty(getCanBeConfiguredModules(myProject, jvmConfigurator))
}
fun testLibraryNonDefault_libExistInDefault() {
val module = module
// Move fake runtime jar to default library path to pretend library is already configured
FileUtil.copy(
File(project.basePath + "/lib/" + KotlinArtifactNames.KOTLIN_STDLIB),
File(jvmConfigurator.getDefaultPathToJarFile(project) + "/" + KotlinArtifactNames.KOTLIN_STDLIB)
)
assertNotConfigured(module, jvmConfigurator)
jvmConfigurator.configure(myProject, emptyList())
assertProperlyConfigured(module, jvmConfigurator)
}
fun testNoKotlincExistsNoSettingsLatestRuntime() {
val application = ApplicationManager.getApplication() as ApplicationImpl
application.isSaveAllowed = true
@@ -104,7 +131,6 @@ open class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinInTempDirTest()
Assert.assertEquals(moduleFileContentBefore, moduleFileContentAfter)
}
fun testLoadAndSaveOldNativePlatformOldNativeFacet() = doTestLoadAndSaveProjectWithFacetConfig(
"platform=\"Native \"",
"platform=\"Native (general) \" allPlatforms=\"Native []/Native [general]\""
@@ -16,7 +16,6 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.RootPolicy;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiJavaModule;
import com.intellij.psi.PsiRequiresStatement;
@@ -40,11 +39,10 @@ import org.jetbrains.kotlin.platform.TargetPlatform;
import org.jetbrains.kotlin.platform.js.JsPlatforms;
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms;
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleKt;
import org.jetbrains.kotlin.utils.PathUtil;
import org.junit.internal.runners.JUnit38ClassRunner;
import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.StreamSupport;
@@ -60,11 +58,21 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
ModuleRootManager.getInstance(getModule()).orderEntries().forEachLibrary(library -> {
assertSameElements(
Arrays.stream(library.getRootProvider().getFiles(OrderRootType.CLASSES)).map(VirtualFile::getName).toArray(),
KotlinArtifactNames.KOTLIN_STDLIB, KotlinArtifactNames.KOTLIN_REFLECT, KotlinArtifactNames.KOTLIN_TEST);
KotlinArtifactNames.KOTLIN_STDLIB,
KotlinArtifactNames.KOTLIN_REFLECT,
KotlinArtifactNames.KOTLIN_TEST,
KotlinArtifactNames.KOTLIN_STDLIB_JDK7,
KotlinArtifactNames.KOTLIN_STDLIB_JDK8
);
assertSameElements(
Arrays.stream(library.getRootProvider().getFiles(OrderRootType.SOURCES)).map(VirtualFile::getName).toArray(),
KotlinArtifactNames.KOTLIN_STDLIB, KotlinArtifactNames.KOTLIN_REFLECT, KotlinArtifactNames.KOTLIN_TEST);
KotlinArtifactNames.KOTLIN_STDLIB_SOURCES,
PathUtil.KOTLIN_TEST_SRC_JAR,
PathUtil.KOTLIN_REFLECT_SRC_JAR,
KotlinArtifactNames.KOTLIN_STDLIB_JDK7_SOURCES,
KotlinArtifactNames.KOTLIN_STDLIB_JDK8_SOURCES
);
return true;
});
@@ -96,8 +104,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
if (module.getName().equals("module1")) {
configure(module, KotlinWithLibraryConfigurator.FileState.DO_NOT_COPY, getJvmConfigurator());
assertConfigured(module, getJvmConfigurator());
}
else if (module.getName().equals("module2")) {
} else if (module.getName().equals("module2")) {
assertNotConfigured(module, getJvmConfigurator());
configure(module, KotlinWithLibraryConfigurator.FileState.EXISTS, getJvmConfigurator());
assertConfigured(module, getJvmConfigurator());
@@ -105,29 +112,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
}
}
public void testLibraryNonDefault_libExistInDefault() throws IOException {
Module module = getModule();
// Move fake runtime jar to default library path to pretend library is already configured
FileUtil.copy(
new File(getProject().getBasePath() + "/lib/" + KotlinArtifactNames.KOTLIN_STDLIB),
new File(getJvmConfigurator().getDefaultPathToJarFile(getProject()) + "/" + KotlinArtifactNames.KOTLIN_STDLIB));
assertNotConfigured(module, getJvmConfigurator());
getJvmConfigurator().configure(myProject, emptyList());
assertProperlyConfigured(module, getJvmConfigurator());
}
public void testTwoModulesWithNonDefaultPath_doNotCopyInDefault() {
doTestConfigureModulesWithNonDefaultSetup(getJvmConfigurator());
assertEmpty(ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModules(myProject, getJsConfigurator()));
}
public void testTwoModulesWithJSNonDefaultPath_doNotCopyInDefault() {
doTestConfigureModulesWithNonDefaultSetup(getJsConfigurator());
assertEmpty(ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModules(myProject, getJvmConfigurator()));
}
public void testNewLibrary_jarExists_js() {
doTestSingleJsModule(KotlinWithLibraryConfigurator.FileState.EXISTS);
}
@@ -212,7 +196,8 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check",
settings.getCompilerSettings().getAdditionalArguments());
}
public void testJsProjectWithV1FacetConfig() {
@@ -240,7 +225,8 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check",
settings.getCompilerSettings().getAdditionalArguments());
}
public void testJsProjectWithV2FacetConfig() {
@@ -268,7 +254,8 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check",
settings.getCompilerSettings().getAdditionalArguments());
}
public void testJvmProjectWithJvmTarget11() {
@@ -286,7 +273,8 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assert module2 != null;
assertEquals(emptyList(), KotlinFacet.Companion.get(module1).getConfiguration().getSettings().getImplementedModuleNames());
assertEquals(singletonList("module1"), KotlinFacet.Companion.get(module2).getConfiguration().getSettings().getImplementedModuleNames());
assertEquals(singletonList("module1"),
KotlinFacet.Companion.get(module2).getConfiguration().getSettings().getImplementedModuleNames());
}
public void testJava9WithModuleInfo() {
@@ -298,7 +286,8 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
}
public void testProjectWithFreeArgs() {
assertEquals(singletonList("true"), KotlinCommonCompilerArgumentsHolder.Companion.getInstance(myProject).getSettings().getFreeArgs());
assertEquals(singletonList("true"),
KotlinCommonCompilerArgumentsHolder.Companion.getInstance(myProject).getSettings().getFreeArgs());
}
public void testProjectWithInternalArgs() {
@@ -347,8 +336,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(platform, facet.getConfiguration().getSettings().getTargetPlatform());
assertEquals(jvmTarget.getDescription(),
((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).getJvmTarget());
}
finally {
} finally {
modelsProvider.dispose();
}
}
@@ -5,15 +5,15 @@
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1" project-jdk-name="11" project-jdk-type="JavaSDK"/>
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-stblib.jar!/" />
<root url="jar://$PROJECT_DIR$/kotlin-stblib.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-stblib.jar!/src" />
<root url="jar://$PROJECT_DIR$/kotlin-stblib.jar!/src" />
</SOURCES>
</library>
</component>
@@ -7,7 +7,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="org.jetbrains.kotlin:kotlin-test-js:1.2.31" level="project" />
</component>
</module>
@@ -5,6 +5,6 @@
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK"/>
</project>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" inherit-compiler-output="true"/>
</module>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" inherit-compiler-output="true"/>
</module>
@@ -6,6 +6,6 @@
<module fileurl="file://$PROJECT_DIR$/module2.iml" filepath="$PROJECT_DIR$/module2.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK"/>
</project>
@@ -10,11 +10,11 @@
<component name="libraryTable">
<library name="KotlinJavaScript" type="kotlin.js">
<CLASSES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-stdlib-js.jar!/" />
<root url="jar://$PROJECT_DIR$/kotlin-stdlib-js.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-stdlib-js-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/kotlin-stdlib-js-sources.jar!/" />
</SOURCES>
</library>
</component>
@@ -10,11 +10,11 @@
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/" />
<root url="jar://$PROJECT_DIR$/kotlin-runtime.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/src" />
<root url="jar://$PROJECT_DIR$/kotlin-runtime.jar!/src" />
</SOURCES>
</library>
</component>