Fix reflection-related codegen tests on JDK 9+
In JDK 9, Class.simpleName changed behavior for local/anonymous Kotlin classes (see KT-23072), this is why we now check for both variants of the name in tests. Also, the format of annotation arguments changed a little, where float parameters no longer have the trailing "f", and class literals are rendered with ".class" at the end
This commit is contained in:
+3
-3
@@ -12,7 +12,7 @@ public @interface Anno {
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class C {
|
||||
@Anno
|
||||
@@ -23,7 +23,7 @@ class C {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("[@Anno(value=void)]", C::f1.annotations.toString())
|
||||
assertEquals("[@Anno(value=class java.lang.Void)]", C::f2.annotations.toString())
|
||||
assertTrue("\\[@Anno\\(value=void(\\.class)?\\)\\]".toRegex().matches(C::f1.annotations.toString()))
|
||||
assertTrue("\\[@Anno\\(value=(class )?java.lang.Void(\\.class)?\\)\\]".toRegex().matches(C::f2.annotations.toString()))
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+10
-6
@@ -7,6 +7,7 @@
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
annotation class D(val d: Double)
|
||||
annotation class F(val f: Float)
|
||||
@@ -30,11 +31,14 @@ fun fMinusZero() {}
|
||||
@F(+0.0f)
|
||||
fun fPlusZero() {}
|
||||
|
||||
fun check(x: Any, y: Any) {
|
||||
fun check(x: Any, y: Any, regexString: String) {
|
||||
assertEquals(x, y)
|
||||
assertEquals(y, x)
|
||||
assertEquals(x.hashCode(), y.hashCode())
|
||||
assertEquals(x.toString(), y.toString())
|
||||
|
||||
val regex = regexString.toRegex()
|
||||
assertTrue(regex.matches(x.toString()))
|
||||
assertTrue(regex.matches(y.toString()))
|
||||
}
|
||||
|
||||
fun checkNot(x: Any, y: Any) {
|
||||
@@ -54,10 +58,10 @@ fun box(): String {
|
||||
val dpz = D::class.constructors.single().call(+0.0)
|
||||
val fmz = F::class.constructors.single().call(-0.0f)
|
||||
val fpz = F::class.constructors.single().call(+0.0f)
|
||||
check(::dMinusZero.annotations.single() as D, dmz)
|
||||
check(::dPlusZero.annotations.single() as D, dpz)
|
||||
check(::fMinusZero.annotations.single() as F, fmz)
|
||||
check(::fPlusZero.annotations.single() as F, fpz)
|
||||
check(::dMinusZero.annotations.single() as D, dmz, "@D\\(d=-0.0\\)")
|
||||
check(::dPlusZero.annotations.single() as D, dpz, "@D\\(d=0.0\\)")
|
||||
check(::fMinusZero.annotations.single() as F, fmz, "@F\\(f=-0.0f?\\)")
|
||||
check(::fPlusZero.annotations.single() as F, fpz, "@F\\(f=0.0f?\\)")
|
||||
|
||||
checkNot(dmz, dpz)
|
||||
checkNot(fmz, fpz)
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ fun box(): String {
|
||||
class C
|
||||
|
||||
val name = C::class.java.getSimpleName()
|
||||
if (name != "box\$C") return "Fail: $name"
|
||||
if (name != "box\$C" && name != "C") return "Fail: $name"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user