Files
kotlin-fork/compiler/tests/org/jetbrains/kotlin/codegen/JvmModuleProtoBufTest.kt
T
Alexander Udalov 927706883e Do not report pre-release errors if release LV is used in pre-release compiler
This commit effectively reverts
d386712903.

The reason is that when using a release language version, you can only
"see" the subset of a pre-release library which consists of released and
supported features, so reporting an error is not helpful there. Also, it
presents a problem currently when using kotlinc 1.3 (which is
pre-release) with language version 1.2 (stable) against the bundled
stdlib of version 1.3 (pre-release)

 #KT-21267 Declined
2018-08-30 14:57:33 +03:00

110 lines
4.2 KiB
Kotlin

/*
* 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.codegen
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.load.kotlin.loadModuleMapping
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
import org.jetbrains.kotlin.test.CompilerTestUtil
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import java.io.File
class JvmModuleProtoBufTest : KtUsefulTestCase() {
private fun doTest(
relativeDirectory: String,
compileWith: LanguageVersion = LanguageVersion.LATEST_STABLE,
loadWith: LanguageVersion = LanguageVersion.LATEST_STABLE,
extraOptions: List<String> = emptyList()
) {
val directory = KotlinTestUtils.getTestDataPathBase() + relativeDirectory
val tmpdir = KotlinTestUtils.tmpDir(this::class.simpleName)
val moduleName = "main"
CompilerTestUtil.executeCompilerAssertSuccessful(K2JVMCompiler(), listOf(
directory,
"-d", tmpdir.path,
"-module-name", moduleName,
"-language-version", compileWith.versionString
) + extraOptions)
val mapping = ModuleMapping.loadModuleMapping(
File(tmpdir, "META-INF/$moduleName.${ModuleMapping.MAPPING_FILE_EXT}").readBytes(), "test",
CompilerDeserializationConfiguration(
LanguageVersionSettingsImpl(loadWith, ApiVersion.createByLanguageVersion(loadWith))
),
::error
)
val result = buildString {
for (annotationClassId in mapping.moduleData.annotations) {
appendln("@$annotationClassId")
}
for ((fqName, packageParts) in mapping.packageFqName2Parts) {
appendln(fqName)
for (part in packageParts.parts) {
append(" ")
append(part)
val facadeName = packageParts.getMultifileFacadeName(part)
if (facadeName != null) {
append(" (")
append(facadeName)
append(")")
}
appendln()
}
}
}
KotlinTestUtils.assertEqualsToFile(File(directory, "module-proto.txt"), result)
}
fun testSimple() {
doTest("/moduleProtoBuf/simple")
}
fun testJvmPackageName() {
doTest("/moduleProtoBuf/jvmPackageName",
compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2)
}
fun testJvmPackageNameManyParts() {
doTest("/moduleProtoBuf/jvmPackageNameManyParts",
compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2)
}
fun testJvmPackageNameLanguageVersion11() {
doTest("/moduleProtoBuf/jvmPackageNameLanguageVersion11",
compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_1)
}
fun testExperimental() {
doTest(
"/moduleProtoBuf/experimental", extraOptions = listOf(
"-Xuse-experimental=kotlin.Experimental",
"-Xexperimental=org.foo.A",
"-Xexperimental=org.foo.B.C",
"-Xuse-experimental=org.foo.D"
)
)
}
}