Fix JDK-dependent stdlib tests after advancing jvmTarget

This commit is contained in:
Abduqodiri Qurbonzoda
2022-08-16 13:36:04 +03:00
parent 9e35815ae3
commit 6c4777dcdd
14 changed files with 72 additions and 167 deletions
+4
View File
@@ -133,6 +133,10 @@ compileTestKotlin {
}
}
test {
systemProperty("supportsNamedCapturingGroup", false)
}
compileLongRunningTestKotlin {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.ExperimentalStdlibApi"
}
@@ -48,24 +48,18 @@ internal open class PlatformImplementations {
@JvmField
internal val IMPLEMENTATIONS: PlatformImplementations = run {
val version = getJavaVersion()
if (version >= 0x10008 || version < 0x10000) {
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
}
if (version >= 0x10007 || version < 0x10000) {
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
}
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
PlatformImplementations()
}
@@ -84,25 +78,6 @@ private inline fun <reified T : Any> castToBaseType(instance: Any): T {
}
}
private fun getJavaVersion(): Int {
val default = 0x10006
val version = System.getProperty("java.specification.version") ?: return default
val firstDot = version.indexOf('.')
if (firstDot < 0)
return try { version.toInt() * 0x10000 } catch (e: NumberFormatException) { default }
var secondDot = version.indexOf('.', firstDot + 1)
if (secondDot < 0) secondDot = version.length
val firstPart = version.substring(0, firstDot)
val secondPart = version.substring(firstDot + 1, secondDot)
return try {
firstPart.toInt() * 0x10000 + secondPart.toInt()
} catch (e: NumberFormatException) {
default
}
}
/**
* Constant check of api version used during compilation
*
@@ -6,7 +6,6 @@
package test.exceptions
import test.collections.assertArrayNotSameButEquals
import test.testOnJvm7AndAbove
import java.io.*
import java.nio.charset.Charset
import kotlin.test.*
@@ -96,9 +95,8 @@ class ExceptionJVMTest {
e1.initCause(e2)
assertSame(e1, e2.cause)
assertSame(e2, e1.cause)
testOnJvm7AndAbove {
val trace = e2.stackTraceToString()
assertTrue("CIRCULAR REFERENCE" in trace, trace)
}
val trace = e2.stackTraceToString()
assertTrue("CIRCULAR REFERENCE" in trace, trace)
}
}
+2 -23
View File
@@ -12,25 +12,6 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
assertEquals(expected?.javaClass, actual?.javaClass)
}
private val isJava6 = System.getProperty("java.version").startsWith("1.6.")
internal actual fun String.removeLeadingPlusOnJava6(): String =
if (isJava6) removePrefix("+") else this
private val isJava7 = System.getProperty("java.version").startsWith("1.7.")
private val isJava8AndAbove = !isJava6 && !isJava7
internal actual inline fun testOnNonJvm6And7(f: () -> Unit) {
if (isJava8AndAbove) {
f()
}
}
internal inline fun testOnJvm7AndAbove(f: () -> Unit) {
if (!isJava6) {
f()
}
}
public actual fun testOnJvm(action: () -> Unit) = action()
public actual fun testOnJs(action: () -> Unit) {}
@@ -39,10 +20,8 @@ public fun <T> platformNull() = Collections.singletonList(null as T).first()
public actual val isFloat32RangeEnforced: Boolean = true
public actual val supportsSuppressedExceptions: Boolean get() = !isJava6
// Named capturing groups are supported starting from java 7. However, retrieving them by name is not supported in java 7.
public actual val supportsNamedCapturingGroup: Boolean get() = isJava8AndAbove
public actual val supportsNamedCapturingGroup: Boolean
get() = System.getProperty("supportsNamedCapturingGroup")?.toBooleanStrict() ?: true
public actual val supportsOctalLiteralInRegex: Boolean get() = true