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:
Alexander Udalov
2018-07-17 20:08:26 +02:00
parent 871b896a21
commit ea3c5c0107
2 changed files with 14 additions and 28 deletions
@@ -31,20 +31,16 @@ compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source
The class is loaded from $TMP_DIR$/library-after.jar!/a/A.class The class is loaded from $TMP_DIR$/library-after.jar!/a/A.class
val supertype = object : A() {} 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$. compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:11:13: error: unresolved reference: foo
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
val x = 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$. compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:12:13: error: unresolved reference: bar
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
val y = 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$. compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:13:5: error: unresolved reference: bar
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
bar = 239 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$. compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:14:12: error: unresolved reference: TA
The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class
val z: TA = "" val z: TA = ""
^ ^
COMPILATION_ERROR COMPILATION_ERROR
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.load.java.JvmAnnotationNames 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
import org.jetbrains.kotlin.resolve.DescriptorUtils.isObject import org.jetbrains.kotlin.resolve.DescriptorUtils.isObject
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil 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.MockLibraryUtil
import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.TestJdkKind
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile 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.*
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
@@ -85,31 +83,23 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
} }
private fun doTestKotlinLibraryWithWrongMetadataVersion( private fun doTestKotlinLibraryWithWrongMetadataVersion(
libraryName: String, libraryName: String,
additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?, additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?,
vararg additionalOptions: String vararg additionalOptions: String
) { ) {
val version = JvmMetadataVersion(42, 0, 0).toArray()
val library = transformJar( val library = transformJar(
compileLibrary(libraryName), compileLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0")),
{ _, bytes -> { _, bytes ->
WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value -> WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value ->
additionalTransformation?.invoke(fieldName, value) ?: additionalTransformation?.invoke(fieldName, value)
version.takeIf { JvmAnnotationNames.METADATA_VERSION_FIELD_NAME == fieldName }
}
} }
}
) )
compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList()) compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList())
} }
private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) { private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) {
val library = compileJsLibrary(libraryName) val library = compileJsLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0"))
library.writeText(library.readText(Charsets.UTF_8).replace(
"(" + JsMetadataVersion.INSTANCE.toInteger() + ", ",
"(" + JsMetadataVersion(42, 0, 0).toInteger() + ", "
), Charsets.UTF_8)
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList()) compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList())
} }