Use -Xmetadata-version in tests instead of custom preprocessing
Test data for the wrongMetadataVersion test has changed because now not only the .class files have the "future" version, but also the .kotlin_module file, which prevents the current compiler from being able to read what parts does a package in the library consist of. This is related to the TODO in ModuleMapping.kt:89
This commit is contained in:
+5
-9
@@ -31,20 +31,16 @@ compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/A.class
|
||||
val supertype = object : A() {}
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:11:13: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:11:13: error: unresolved reference: foo
|
||||
val x = foo()
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:12:13: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:12:13: error: unresolved reference: bar
|
||||
val y = bar
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:13:5: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:13:5: error: unresolved reference: bar
|
||||
bar = 239
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:14:12: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:14:12: error: unresolved reference: TA
|
||||
val z: TA = ""
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
COMPILATION_ERROR
|
||||
|
||||
+9
-19
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isObject
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
@@ -34,7 +33,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||
@@ -85,31 +83,23 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
}
|
||||
|
||||
private fun doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
libraryName: String,
|
||||
additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?,
|
||||
vararg additionalOptions: String
|
||||
libraryName: String,
|
||||
additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?,
|
||||
vararg additionalOptions: String
|
||||
) {
|
||||
val version = JvmMetadataVersion(42, 0, 0).toArray()
|
||||
val library = transformJar(
|
||||
compileLibrary(libraryName),
|
||||
{ _, bytes ->
|
||||
WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value ->
|
||||
additionalTransformation?.invoke(fieldName, value) ?:
|
||||
version.takeIf { JvmAnnotationNames.METADATA_VERSION_FIELD_NAME == fieldName }
|
||||
}
|
||||
compileLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0")),
|
||||
{ _, bytes ->
|
||||
WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value ->
|
||||
additionalTransformation?.invoke(fieldName, value)
|
||||
}
|
||||
}
|
||||
)
|
||||
compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList())
|
||||
}
|
||||
|
||||
private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) {
|
||||
val library = compileJsLibrary(libraryName)
|
||||
|
||||
library.writeText(library.readText(Charsets.UTF_8).replace(
|
||||
"(" + JsMetadataVersion.INSTANCE.toInteger() + ", ",
|
||||
"(" + JsMetadataVersion(42, 0, 0).toInteger() + ", "
|
||||
), Charsets.UTF_8)
|
||||
|
||||
val library = compileJsLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0"))
|
||||
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user