[kotlin:tests] Cherry-pick commits about test infra from kt-212-master branch

Included changes:
a59d2cf30748c Revert "[New project wizard, tests]: no remote ops"
ae9dfe575f94e Simplify EapVersionDownloader -- use the Gradle plugin portal to determine the last eap version
6e092b4661339 [kotlin] Minor: remove redundant open modifier
35764bf5308d5 [kotlin] Add stdlib-jdk8 artifact to the all light classes tests
b4e99ed2a7ae0 LightClasses: Fix rendering for Foo.class in annotation value
03e00cb4c2d43 [kotlin] Add mapping for 1.7 and 1.8 language version
3f68cc5fbc2af [kotlin:tests] Fix KotlinUastGenerationTest.test method call generation with generics with context
e31345083589e [kotlin:tests] Use MOCK_JDK_1_6 in ResolveByStubTestGenerated
15a42d0c02508 [kotlin:tests] Enable support for compiler options in ResolveByStubTestGenerated
23ed90ec3ff8d [kotlin:tests] Fix JsKlibLookupTrackerTestGenerated
2fa29cbbbc7b3 [ULC] fix testData in the plugin (related to repeatable annotation)

GitOrigin-RevId: fb5ff3a3642717c756288387fd0718c03de3e5ce
This commit is contained in:
Stanislav Erokhin
2022-01-22 11:09:57 +00:00
committed by intellij-monorepo-bot
parent e42c2032bf
commit 0c188018a3
12 changed files with 73 additions and 51 deletions
@@ -9,7 +9,6 @@ import com.intellij.util.text.VersionComparatorUtil
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.compiler.configuration.Version
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.idePlatformKind
@@ -78,6 +77,7 @@ fun getDefaultLanguageLevel(
fun String?.toLanguageVersion(): LanguageVersion = when {
this == null -> LanguageVersion.LATEST_STABLE
startsWith("1.7") -> LanguageVersion.KOTLIN_1_7
startsWith("1.6") -> LanguageVersion.KOTLIN_1_6
startsWith("1.5") -> LanguageVersion.KOTLIN_1_5
startsWith("1.4") -> LanguageVersion.KOTLIN_1_4
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils
import java.io.File
abstract class AbstractUltraLightClassSanityTest : KotlinLightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_WITH_STDLIB_JDK8
fun doTest(testDataPath: String) {
val ioFile = File(testDataPath)
@@ -53,7 +53,12 @@ abstract class AbstractIdeLightClassTest : KotlinLightCodeInsightFixtureTestCase
else -> error("Invalid test data extension")
}
withCustomCompilerOptions(File(testDataPath, fileName).readText(), project, module) {
val fileText = File(testDataPath, fileName).readText()
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "SKIP_IDE_TEST")) {
return
}
withCustomCompilerOptions(fileText, project, module) {
val testFiles = if (File(testDataPath, extraFilePath).isFile) listOf(fileName, extraFilePath) else listOf(fileName)
val lazinessMode = lazinessModeByFileText()
myFixture.configureByFiles(*testFiles.toTypedArray())
@@ -90,7 +95,7 @@ abstract class AbstractIdeLightClassTest : KotlinLightCodeInsightFixtureTestCase
}
}
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_WITH_STDLIB_JDK8
open val fileExtension = ".kt"
}
@@ -105,7 +110,7 @@ abstract class AbstractIdeCompiledLightClassTest : KotlinDaemonAnalyzerTestCase(
val testFile = listOf(File(testDataDir, "$testName.kt"), File(testDataDir, "$testName.kts")).first { it.exists() }
?: error("Test file not found!")
val extraClasspath = mutableListOf(KotlinArtifacts.instance.jetbrainsAnnotations)
val extraClasspath = mutableListOf(KotlinArtifacts.instance.jetbrainsAnnotations, KotlinArtifacts.instance.kotlinStdlibJdk8)
if (testFile.extension == "kts") {
extraClasspath += KotlinArtifacts.instance.kotlinScriptRuntime
}
@@ -8,15 +8,12 @@ import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.test.AstAccessControl
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.*
import org.jetbrains.kotlin.idea.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden
import org.jetbrains.kotlin.idea.test.util.RecursiveDescriptorComparator
import org.jetbrains.kotlin.load.java.descriptors.PossiblyExternalAnnotationDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.idea.test.InTextDirectivesUtils
import org.jetbrains.kotlin.idea.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden
import org.jetbrains.kotlin.idea.test.util.RecursiveDescriptorComparator
import org.junit.Assert
import java.io.File
@@ -45,7 +42,10 @@ abstract class AbstractResolveByStubTest : KotlinLightCodeInsightFixtureTestCase
private fun performTest(path: String) {
val file = file as KtFile
val module = file.findModuleDescriptor()
val module = withCustomCompilerOptions(file.text, project, module) {
file.findModuleDescriptor()
}
val packageViewDescriptor = module.getPackage(FqName("test"))
Assert.assertFalse(packageViewDescriptor.isEmpty())
@@ -6,7 +6,6 @@ import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.kotlin.tools.projectWizard.core.div
import org.jetbrains.kotlin.tools.projectWizard.core.service.Services
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Repositories
import org.jetbrains.kotlin.tools.projectWizard.wizard.Wizard
import java.nio.file.Files
@@ -48,8 +47,7 @@ abstract class AbstractBuildFileGenerationTest : UsefulTestCase() {
if (testParameters.keepKotlinVersion) {
fileContent
} else {
val pluginVersion = wizard.context.read { KotlinPlugin.version.propertyValue.version.toString() }
fileContent.replace(pluginVersion, KOTLIN_VERSION_PLACEHOLDER)
fileContent.replace(KotlinVersionProviderTestWizardService.TEST_KOTLIN_VERSION.toString(), KOTLIN_VERSION_PLACEHOLDER)
}.also { it.replaceAllTo(
listOf(Repositories.JETBRAINS_KOTLIN_DEV.url),
KOTLIN_REPO_PLACEHOLDER
@@ -0,0 +1,27 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.tools.projectWizard.cli
import org.jetbrains.kotlin.tools.projectWizard.Versions
import org.jetbrains.kotlin.tools.projectWizard.core.service.EapVersionDownloader
import org.jetbrains.kotlin.tools.projectWizard.core.service.WizardKotlinVersion
import org.jetbrains.kotlin.tools.projectWizard.core.service.KotlinVersionKind
import org.jetbrains.kotlin.tools.projectWizard.core.service.KotlinVersionProviderService
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ProjectKind
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
class KotlinVersionProviderTestWizardService : KotlinVersionProviderService(), TestWizardService {
override fun getKotlinVersion(projectKind: ProjectKind): WizardKotlinVersion =
kotlinVersionWithDefaultValues(
when (projectKind) {
ProjectKind.COMPOSE -> Versions.KOTLIN_VERSION_FOR_COMPOSE
else -> TEST_KOTLIN_VERSION
}
)
companion object {
val TEST_KOTLIN_VERSION by lazy {
EapVersionDownloader.getLatestEapVersion()!!
}
}
}
@@ -6,10 +6,16 @@ import org.jetbrains.kotlin.tools.projectWizard.core.service.Services
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
import org.jetbrains.kotlin.tools.projectWizard.core.service.WizardService
interface TestWizardService : WizardService
interface TestWizardService : WizardService {
companion object {
val SERVICES = listOf(
KotlinVersionProviderTestWizardService()
)
}
}
val CLI_WIZARD_TEST_SERVICES_MANAGER = ServicesManager(
Services.IDEA_INDEPENDENT_SERVICES
Services.IDEA_INDEPENDENT_SERVICES + TestWizardService.SERVICES
) { services ->
services.firstOrNull { it is TestWizardService } ?: services.firstOrNull()
}
@@ -1,2 +1 @@
// runForGradleGroovy false
// keepKotlinVersion true
// runForGradleGroovy false
@@ -1,8 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.tools.projectWizard.core.service
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
import org.jetbrains.kotlin.tools.projectWizard.core.asNullable
@@ -15,28 +13,12 @@ import java.net.URL
import java.util.stream.Collectors
object EapVersionDownloader {
fun getLatestEapVersion() = downloadVersionFromMavenCentral(EAP_URL).firstOrNull()
fun getLatestDevVersion() = downloadVersions(DEV_URL).firstOrNull()
fun getLatestEapVersion() = downloadVersions(EAP_URL).firstOrNull()
private fun downloadPage(url: String): TaskResult<String> = safe {
BufferedReader(InputStreamReader(URL(url).openStream())).lines().collect(Collectors.joining("\n"))
}
@Suppress("SameParameterValue")
private fun downloadVersionFromMavenCentral(url: String) = compute {
val (text) = downloadPage(url)
val (versionString) = parseLatestVersionFromJson(text)
if (versionString.isNotEmpty())
listOf(Version.fromString(versionString))
else
emptyList()
}.asNullable.orEmpty()
private fun parseLatestVersionFromJson(text: String) = safe {
val json = JsonParser.parseString(text) as JsonObject
json.get("response").asJsonObject.get("docs").asJsonArray.get(0).asJsonObject.get("latestVersion").asString
}
@Suppress("SameParameterValue")
private fun downloadVersions(url: String): List<Version> = compute {
val (text) = downloadPage(url)
@@ -49,10 +31,7 @@ object EapVersionDownloader {
}.asNullable.orEmpty()
@NonNls
private val EAP_URL = "https://search.maven.org/solrsearch/select?q=g:org.jetbrains.kotlin%20AND%20a:kotlin-gradle-plugin"
@NonNls
private val DEV_URL = "https://dl.bintray.com/kotlin/kotlin-dev/org/jetbrains/kotlin/jvm/org.jetbrains.kotlin.jvm.gradle.plugin/"
private val EAP_URL = "https://plugins.gradle.org/m2/org/jetbrains/kotlin/jvm/org.jetbrains.kotlin.jvm.gradle.plugin/"
@NonNls
private val versionRegexp = """href="([^"\\]+)"""".toRegex()
@@ -3,7 +3,7 @@
package org.jetbrains.kotlin.tools.projectWizard.wizard.services
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.tools.projectWizard.wizard.service.IdeaKotlinVersionProviderService
import org.jetbrains.kotlin.tools.projectWizard.cli.KotlinVersionProviderTestWizardService
import org.jetbrains.kotlin.tools.projectWizard.cli.TestWizardService
import org.jetbrains.kotlin.tools.projectWizard.wizard.service.IdeaJvmTargetVersionProviderService
@@ -14,7 +14,7 @@ object TestWizardServices {
val PROJECT_INDEPENDENT = listOf(
FormattingTestWizardService(),
IdeaKotlinVersionProviderService(),
KotlinVersionProviderTestWizardService(),
IdeaJvmTargetVersionProviderService()
)
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.asJava.elements.KtLightPsiLiteral
import org.jetbrains.kotlin.load.kotlin.NON_EXISTENT_CLASS_NAME
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.KClassValue
fun PsiClass.renderClass() = PsiClassRenderer.renderClass(this)
@@ -143,12 +144,19 @@ class PsiClassRenderer private constructor(
it.name!! + bounds
} + "> "
private fun KtLightPsiLiteral.renderKtLightPsiLiteral(): String =
(value as? Pair<*, *>)?.let {
val classId = it.first as? ClassId
val name = it.second as? Name
if (classId != null && name != null) "${classId.asSingleFqName()}.${name.asString()}" else null
} ?: text
private fun KtLightPsiLiteral.renderKtLightPsiLiteral(): String {
val value = value
if (value is Pair<*, *>) {
val classId = value.first as? ClassId
val name = value.second as? Name
if (classId != null && name != null)
return "${classId.asSingleFqName()}.${name.asString()}"
}
if (value is KClassValue.Value.NormalClass && value.arrayDimensions == 0) {
return "${value.classId.asSingleFqName()}.class"
}
return text
}
private fun PsiAnnotationMemberValue.renderAnnotationMemberValue(): String = when (this) {
is KtLightPsiArrayInitializerMemberValue -> "{${initializers.joinToString { it.renderAnnotationMemberValue() }}}"
@@ -519,7 +519,7 @@ class KotlinUastGenerationTest : KotlinLightCodeInsightFixtureTestCase() {
""".trimIndent()
) as KtFile
val reference = file.findUElementByTextFromPsi<UElement>("println(a)")
val reference = file.findUElementByTextFromPsi<UElement>("println(a)", strict = true)
.findElementByTextFromPsi<UReferenceExpression>("a")
val callExpression = uastElementFactory.createCallExpression(