[Tests] FIR support in JUnit 3 tests, port necessary subclasses
^KT-64404 Fixed ^KT-64438 Fixed ^KT-64407 Fixed
This commit is contained in:
committed by
Space Team
parent
e69d6d2d05
commit
9a2e4c6b41
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.testFramework.FrontendBackendConfiguration
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJvmVersionRequirementTest : AbstractVersionRequirementTest(), FrontendBackendConfiguration {
|
||||
override fun compileFiles(
|
||||
files: List<File>,
|
||||
outputDirectory: File,
|
||||
languageVersion: LanguageVersion,
|
||||
analysisFlags: Map<AnalysisFlag<*>, Any?>,
|
||||
specificFeatures: Map<LanguageFeature, LanguageFeature.State>,
|
||||
) {
|
||||
LoadDescriptorUtil.compileKotlinToDirAndGetModule(
|
||||
listOf(File("compiler/testData/versionRequirement/${getTestName(true)}.kt")), outputDirectory,
|
||||
KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, outputDirectory).apply {
|
||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||
languageVersion,
|
||||
ApiVersion.createByLanguageVersion(languageVersion),
|
||||
analysisFlags.toMap() + mapOf(AnalysisFlags.explicitApiVersion to true),
|
||||
specificFeatures
|
||||
)
|
||||
}.also {
|
||||
configureIrFir(it)
|
||||
},
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadModule(directory: File): ModuleDescriptor = JvmResolveUtil.analyze(
|
||||
KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir).also {
|
||||
configureIrFir(it)
|
||||
},
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
).moduleDescriptor
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirement
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import java.io.File
|
||||
|
||||
class JvmVersionRequirementTest : AbstractVersionRequirementTest() {
|
||||
override fun compileFiles(
|
||||
files: List<File>,
|
||||
outputDirectory: File,
|
||||
languageVersion: LanguageVersion,
|
||||
analysisFlags: Map<AnalysisFlag<*>, Any?>,
|
||||
specificFeatures: Map<LanguageFeature, LanguageFeature.State>
|
||||
) {
|
||||
LoadDescriptorUtil.compileKotlinToDirAndGetModule(
|
||||
listOf(File("compiler/testData/versionRequirement/${getTestName(true)}.kt")), outputDirectory,
|
||||
KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, outputDirectory).apply {
|
||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||
languageVersion,
|
||||
ApiVersion.createByLanguageVersion(languageVersion),
|
||||
analysisFlags.toMap() + mapOf(AnalysisFlags.explicitApiVersion to true),
|
||||
specificFeatures
|
||||
)
|
||||
},
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadModule(directory: File): ModuleDescriptor = JvmResolveUtil.analyze(
|
||||
KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
).moduleDescriptor
|
||||
|
||||
fun testAllJvmDefault() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
analysisFlags = mapOf(JvmAnalysisFlags.jvmDefaultMode to JvmDefaultMode.ALL),
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.Base",
|
||||
"test.Derived",
|
||||
"test.BaseWithProperty",
|
||||
"test.DerivedWithProperty",
|
||||
"test.Empty",
|
||||
"test.EmptyWithNested",
|
||||
"test.WithAbstractDeclaration",
|
||||
"test.DerivedFromWithAbstractDeclaration"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun testAllCompatibilityJvmDefault() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
analysisFlags = mapOf(JvmAnalysisFlags.jvmDefaultMode to JvmDefaultMode.ALL_COMPATIBILITY),
|
||||
fqNamesWithRequirements = emptyList(),
|
||||
fqNamesWithoutRequirement = listOf(
|
||||
"test.Base",
|
||||
"test.Derived",
|
||||
"test.BaseWithProperty",
|
||||
"test.DerivedWithProperty",
|
||||
"test.Empty",
|
||||
"test.EmptyWithNested",
|
||||
"test.WithAbstractDeclaration",
|
||||
"test.DerivedFromWithAbstractDeclaration"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineParameterNullCheck() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 3, 50), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.doRun",
|
||||
"test.lambdaVarProperty",
|
||||
"test.extensionProperty"
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineClassReturnTypeMangled() {
|
||||
// Class members returning inline class values are mangled,
|
||||
// and have "language >= 1.4" and "compiler >= 1.4.30" version requirements.
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null, LANGUAGE_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.C.returnsInlineClassType",
|
||||
"test.C.propertyOfInlineClassType"
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4,
|
||||
shouldBeSingleRequirement = false
|
||||
)
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 30), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.C.returnsInlineClassType",
|
||||
"test.C.propertyOfInlineClassType",
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4,
|
||||
shouldBeSingleRequirement = false,
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineClassesAndRelevantDeclarations1430() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 30), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.simpleFun",
|
||||
"test.aliasedFun",
|
||||
),
|
||||
shouldBeSingleRequirement = false
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||
import org.jetbrains.kotlin.config.JvmDefaultMode
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirement
|
||||
|
||||
class K1JvmVersionRequirementTest : AbstractJvmVersionRequirementTest() {
|
||||
fun testAllJvmDefault() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION, null,
|
||||
analysisFlags = mapOf(JvmAnalysisFlags.jvmDefaultMode to JvmDefaultMode.ALL),
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.Base",
|
||||
"test.Derived",
|
||||
"test.BaseWithProperty",
|
||||
"test.DerivedWithProperty",
|
||||
"test.Empty",
|
||||
"test.EmptyWithNested",
|
||||
"test.WithAbstractDeclaration",
|
||||
"test.DerivedFromWithAbstractDeclaration"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun testAllCompatibilityJvmDefault() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION, null,
|
||||
analysisFlags = mapOf(JvmAnalysisFlags.jvmDefaultMode to JvmDefaultMode.ALL_COMPATIBILITY),
|
||||
fqNamesWithRequirements = emptyList(),
|
||||
fqNamesWithoutRequirement = listOf(
|
||||
"test.Base",
|
||||
"test.Derived",
|
||||
"test.BaseWithProperty",
|
||||
"test.DerivedWithProperty",
|
||||
"test.Empty",
|
||||
"test.EmptyWithNested",
|
||||
"test.WithAbstractDeclaration",
|
||||
"test.DerivedFromWithAbstractDeclaration"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineParameterNullCheck() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 3, 50), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.doRun",
|
||||
"test.lambdaVarProperty",
|
||||
"test.extensionProperty"
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineClassReturnTypeMangled() {
|
||||
// Class members returning inline class values are mangled,
|
||||
// and have "language >= 1.4" and "compiler >= 1.4.30" version requirements.
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 0), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.C.returnsInlineClassType",
|
||||
"test.C.propertyOfInlineClassType"
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4,
|
||||
shouldBeSingleRequirement = false
|
||||
)
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 30), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.C.returnsInlineClassType",
|
||||
"test.C.propertyOfInlineClassType",
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_4,
|
||||
shouldBeSingleRequirement = false,
|
||||
)
|
||||
}
|
||||
|
||||
fun testInlineClassesAndRelevantDeclarations1430() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 4, 30), DeprecationLevel.ERROR, null,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.simpleFun",
|
||||
"test.aliasedFun",
|
||||
),
|
||||
shouldBeSingleRequirement = false
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
|
||||
@Suppress("JUnitTestCaseWithNoTests")
|
||||
class K2JvmVersionRequirementTest : AbstractJvmVersionRequirementTest() {
|
||||
override val useFir: Boolean
|
||||
get() = true
|
||||
|
||||
override val backend: TargetBackend
|
||||
get() = TargetBackend.JVM_IR
|
||||
}
|
||||
Reference in New Issue
Block a user