Always print class id in proto comparison test
A name of class file was used for added and removed classes before the change. The change is required for reusing the test data in js proto comparison tests (there is no classfiles in js, so it is hard to emulate jvm classfiles names for inner/nested classes).
This commit is contained in:
+20
-20
@@ -37,8 +37,9 @@ abstract class AbstractProtoComparisonTest : UsefulTestCase() {
|
||||
val oldClassFiles = compileFileAndGetClasses(testDataPath, testDir, "old")
|
||||
val newClassFiles = compileFileAndGetClasses(testDataPath, testDir, "new")
|
||||
|
||||
val oldClassMap = oldClassFiles.associateBy { it.name }
|
||||
val newClassMap = newClassFiles.associateBy { it.name }
|
||||
|
||||
val oldClassMap = oldClassFiles.map { LocalFileKotlinClass.create(it)!!.let { it.classId to it } }.toMap()
|
||||
val newClassMap = newClassFiles.map { LocalFileKotlinClass.create(it)!!.let { it.classId to it } }.toMap()
|
||||
|
||||
val sb = StringBuilder()
|
||||
val p = Printer(sb)
|
||||
@@ -46,17 +47,17 @@ abstract class AbstractProtoComparisonTest : UsefulTestCase() {
|
||||
val oldSetOfNames = oldClassFiles.map { it.name }.toSet()
|
||||
val newSetOfNames = newClassFiles.map { it.name }.toSet()
|
||||
|
||||
val removedNames = (oldSetOfNames - newSetOfNames).sorted()
|
||||
val removedNames = (oldClassMap.keys - newClassMap.keys).map { it.toString() }.sorted()
|
||||
removedNames.forEach {
|
||||
p.println("REMOVED: class $it")
|
||||
}
|
||||
|
||||
val addedNames = (newSetOfNames - oldSetOfNames).sorted()
|
||||
val addedNames = (newClassMap.keys - oldClassMap.keys).map { it.toString() }.sorted()
|
||||
addedNames.forEach {
|
||||
p.println("ADDED: class $it")
|
||||
}
|
||||
|
||||
val commonNames = oldSetOfNames.intersect(newSetOfNames).sorted()
|
||||
val commonNames = oldClassMap.keys.intersect(newClassMap.keys).sortedBy { it.toString() }
|
||||
|
||||
for(name in commonNames) {
|
||||
p.printDifference(oldClassMap[name]!!, newClassMap[name]!!)
|
||||
@@ -78,31 +79,30 @@ abstract class AbstractProtoComparisonTest : UsefulTestCase() {
|
||||
return File(classesDirectory, "test").listFiles() { it -> it.name.endsWith(".class") }?.sortedBy { it.name }!!
|
||||
}
|
||||
|
||||
private fun Printer.printDifference(oldClassFile: File, newClassFile: File) {
|
||||
private fun Printer.printDifference(oldClass: LocalFileKotlinClass, newClass: LocalFileKotlinClass) {
|
||||
fun KotlinJvmBinaryClass.readProto(): ProtoMapValue? {
|
||||
assert(classHeader.metadataVersion.isCompatible()) { "Incompatible class ($classHeader): $location" }
|
||||
|
||||
val bytes by lazy { BitEncoding.decodeBytes(classHeader.data!!) }
|
||||
val strings by lazy { classHeader.strings!! }
|
||||
|
||||
return when (classHeader.kind) {
|
||||
KotlinClassHeader.Kind.CLASS, KotlinClassHeader.Kind.FILE_FACADE, KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
|
||||
ProtoMapValue(
|
||||
classHeader.kind != KotlinClassHeader.Kind.CLASS,
|
||||
BitEncoding.decodeBytes(classHeader.data!!),
|
||||
classHeader.strings!!
|
||||
)
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
ProtoMapValue(false, bytes, strings)
|
||||
}
|
||||
KotlinClassHeader.Kind.FILE_FACADE,
|
||||
KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
|
||||
ProtoMapValue(true, bytes, strings)
|
||||
}
|
||||
else -> {
|
||||
println("skip $classId")
|
||||
return null
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val oldClass = LocalFileKotlinClass.create(oldClassFile)!!
|
||||
val newClass = LocalFileKotlinClass.create(newClassFile)!!
|
||||
|
||||
val diff = difference(
|
||||
oldClass.readProto() ?: return,
|
||||
newClass.readProto() ?: return
|
||||
)
|
||||
val diff = difference(oldClass.readProto() ?: return,
|
||||
newClass.readProto() ?: return)
|
||||
|
||||
val changes = SmartList<String>()
|
||||
|
||||
|
||||
Vendored
+5
-5
@@ -1,12 +1,12 @@
|
||||
REMOVED: class ClassWithChangedCompanionObject$FirstName.class
|
||||
REMOVED: class ClassWithRemovedCompanionObject$Companion.class
|
||||
ADDED: class ClassWithAddedCompanionObject$Companion.class
|
||||
ADDED: class ClassWithChangedCompanionObject$SecondName.class
|
||||
REMOVED: class test/ClassWithChangedCompanionObject.FirstName
|
||||
REMOVED: class test/ClassWithRemovedCompanionObject.Companion
|
||||
ADDED: class test/ClassWithAddedCompanionObject.Companion
|
||||
ADDED: class test/ClassWithChangedCompanionObject.SecondName
|
||||
changes in test/ClassWithAddedCompanionObject: CLASS_SIGNATURE, MEMBERS
|
||||
[Companion]
|
||||
changes in test/ClassWithChangedCompanionObject: CLASS_SIGNATURE, MEMBERS
|
||||
[FirstName, SecondName]
|
||||
changes in test/ClassWithChangedVisibilityForCompanionObject.Companion: CLASS_SIGNATURE
|
||||
changes in test/ClassWithChangedVisibilityForCompanionObject: NONE
|
||||
changes in test/ClassWithChangedVisibilityForCompanionObject.Companion: CLASS_SIGNATURE
|
||||
changes in test/ClassWithRemovedCompanionObject: CLASS_SIGNATURE, MEMBERS
|
||||
[Companion]
|
||||
|
||||
Vendored
+5
-5
@@ -1,9 +1,9 @@
|
||||
REMOVED: class ClassWithNestedClasses$NestedClassRemoved.class
|
||||
ADDED: class ClassWithNestedClasses$InnerClassAdded.class
|
||||
ADDED: class ClassWithNestedClasses$NestedClassAdded.class
|
||||
REMOVED: class test/ClassWithNestedClasses.NestedClassRemoved
|
||||
ADDED: class test/ClassWithNestedClasses.InnerClassAdded
|
||||
ADDED: class test/ClassWithNestedClasses.NestedClassAdded
|
||||
changes in test/ClassWithChangedVisibilityForNestedClasses: NONE
|
||||
changes in test/ClassWithChangedVisibilityForNestedClasses.InnerClass: CLASS_SIGNATURE
|
||||
changes in test/ClassWithChangedVisibilityForNestedClasses.NestedClass: CLASS_SIGNATURE
|
||||
changes in test/ClassWithChangedVisibilityForNestedClasses: NONE
|
||||
changes in test/ClassWithNestedClasses.InnerClass: NONE
|
||||
changes in test/ClassWithNestedClasses: MEMBERS
|
||||
[InnerClassAdded, NestedClassAdded, NestedClassRemoved]
|
||||
changes in test/ClassWithNestedClasses.InnerClass: NONE
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
ADDED: class Base$C.class
|
||||
changes in test/Base.A: NONE
|
||||
changes in test/Base.B: NONE
|
||||
ADDED: class test/Base.C
|
||||
changes in test/Base: CLASS_SIGNATURE, MEMBERS
|
||||
[C]
|
||||
changes in test/Base.A: NONE
|
||||
changes in test/Base.B: NONE
|
||||
|
||||
+2
-2
@@ -15,10 +15,10 @@ changes in test/EnumFlagUnchanged: NONE
|
||||
changes in test/FinalFlagAdded: NONE
|
||||
changes in test/FinalFlagRemoved: NONE
|
||||
changes in test/FinalFlagUnchanged: NONE
|
||||
changes in test/InnerClassHolder: NONE
|
||||
changes in test/InnerClassHolder.InnerFlagAdded: CLASS_SIGNATURE
|
||||
changes in test/InnerClassHolder.InnerFlagRemoved: CLASS_SIGNATURE
|
||||
changes in test/InnerClassHolder.InnerFlagUnchanged: NONE
|
||||
changes in test/InnerClassHolder: NONE
|
||||
changes in test/InternalFlagAdded: CLASS_SIGNATURE
|
||||
changes in test/InternalFlagRemoved: CLASS_SIGNATURE
|
||||
changes in test/InternalFlagUnchanged: NONE
|
||||
@@ -28,10 +28,10 @@ changes in test/OpenFlagUnchanged: NONE
|
||||
changes in test/PrivateFlagAdded: CLASS_SIGNATURE
|
||||
changes in test/PrivateFlagRemoved: CLASS_SIGNATURE
|
||||
changes in test/PrivateFlagUnchanged: NONE
|
||||
changes in test/ProtectedClassHolder: NONE
|
||||
changes in test/ProtectedClassHolder.ProtectedFlagAdded: CLASS_SIGNATURE
|
||||
changes in test/ProtectedClassHolder.ProtectedFlagRemoved: CLASS_SIGNATURE
|
||||
changes in test/ProtectedClassHolder.ProtectedFlagUnchanged: NONE
|
||||
changes in test/ProtectedClassHolder: NONE
|
||||
changes in test/PublicFlagAdded: NONE
|
||||
changes in test/PublicFlagRemoved: NONE
|
||||
changes in test/PublicFlagUnchanged: NONE
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
REMOVED: class MainKt$Companion.class
|
||||
REMOVED: class TestPackage.class
|
||||
REMOVED: class test/MainKt.Companion
|
||||
REMOVED: class test/TestPackage
|
||||
changes in test/MainKt: CLASS_SIGNATURE
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
ADDED: class MainKt$Companion.class
|
||||
ADDED: class TestPackage.class
|
||||
ADDED: class test/MainKt.Companion
|
||||
ADDED: class test/TestPackage
|
||||
changes in test/MainKt: CLASS_SIGNATURE
|
||||
|
||||
Reference in New Issue
Block a user