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
@@ -16,20 +16,12 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
} }
} }
internal actual fun String.removeLeadingPlusOnJava6(): String = this
internal actual inline fun testOnNonJvm6And7(f: () -> Unit) {
f()
}
actual fun testOnJvm(action: () -> Unit) {} actual fun testOnJvm(action: () -> Unit) {}
actual fun testOnJs(action: () -> Unit) {} actual fun testOnJs(action: () -> Unit) {}
public actual val isFloat32RangeEnforced: Boolean get() = true public actual val isFloat32RangeEnforced: Boolean get() = true
public actual val supportsSuppressedExceptions: Boolean get() = true
public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsNamedCapturingGroup: Boolean get() = true
public actual val supportsOctalLiteralInRegex: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = true
@@ -7,17 +7,11 @@ package test
public expect fun assertTypeEquals(expected: Any?, actual: Any?) public expect fun assertTypeEquals(expected: Any?, actual: Any?)
internal expect fun String.removeLeadingPlusOnJava6(): String
internal expect inline fun testOnNonJvm6And7(f: () -> Unit)
public expect fun testOnJvm(action: () -> Unit) public expect fun testOnJvm(action: () -> Unit)
public expect fun testOnJs(action: () -> Unit) public expect fun testOnJs(action: () -> Unit)
public expect val isFloat32RangeEnforced: Boolean public expect val isFloat32RangeEnforced: Boolean
public expect val supportsSuppressedExceptions: Boolean
public expect val supportsNamedCapturingGroup: Boolean public expect val supportsNamedCapturingGroup: Boolean
public expect val supportsOctalLiteralInRegex: Boolean public expect val supportsOctalLiteralInRegex: Boolean
+4
View File
@@ -79,6 +79,10 @@ compileTestKotlin {
] ]
} }
tasks.withType(Test) {
systemProperty("supportsNamedCapturingGroup", false)
}
configureFrontendIr(project) configureFrontendIr(project)
LibrariesCommon.configureJava9Compilation(project, 'kotlin.stdlib.jdk7') LibrariesCommon.configureJava9Compilation(project, 'kotlin.stdlib.jdk7')
@@ -11,13 +11,6 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js }) assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js })
} }
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun String.removeLeadingPlusOnJava6(): String = this
internal actual inline fun testOnNonJvm6And7(f: () -> Unit) {
f()
}
public actual fun testOnJvm(action: () -> Unit) { } public actual fun testOnJvm(action: () -> Unit) { }
public actual fun testOnJs(action: () -> Unit) = action() public actual fun testOnJs(action: () -> Unit) = action()
@@ -25,8 +18,6 @@ public actual fun testOnJs(action: () -> Unit) = action()
// TODO: should be true at least in JS IR after implementing KT-24975 // TODO: should be true at least in JS IR after implementing KT-24975
public actual val isFloat32RangeEnforced: Boolean = false public actual val isFloat32RangeEnforced: Boolean = false
actual val supportsSuppressedExceptions: Boolean get() = true
public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsNamedCapturingGroup: Boolean get() = true
public actual val supportsOctalLiteralInRegex: Boolean get() = false public actual val supportsOctalLiteralInRegex: Boolean get() = false
+4
View File
@@ -133,6 +133,10 @@ compileTestKotlin {
} }
} }
test {
systemProperty("supportsNamedCapturingGroup", false)
}
compileLongRunningTestKotlin { compileLongRunningTestKotlin {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.ExperimentalStdlibApi" kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.ExperimentalStdlibApi"
} }
@@ -48,24 +48,18 @@ internal open class PlatformImplementations {
@JvmField @JvmField
internal val IMPLEMENTATIONS: PlatformImplementations = run { internal val IMPLEMENTATIONS: PlatformImplementations = run {
val version = getJavaVersion() try {
if (version >= 0x10008 || version < 0x10000) { return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance())
try { } catch (e: ClassNotFoundException) { }
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance()) try {
} catch (e: ClassNotFoundException) { } return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance())
try { } catch (e: ClassNotFoundException) { }
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance()) try {
} catch (e: ClassNotFoundException) { } return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance())
} } catch (e: ClassNotFoundException) { }
try {
if (version >= 0x10007 || version < 0x10000) { return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance())
try { } catch (e: ClassNotFoundException) { }
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() 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 * Constant check of api version used during compilation
* *
@@ -6,7 +6,6 @@
package test.exceptions package test.exceptions
import test.collections.assertArrayNotSameButEquals import test.collections.assertArrayNotSameButEquals
import test.testOnJvm7AndAbove
import java.io.* import java.io.*
import java.nio.charset.Charset import java.nio.charset.Charset
import kotlin.test.* import kotlin.test.*
@@ -96,9 +95,8 @@ class ExceptionJVMTest {
e1.initCause(e2) e1.initCause(e2)
assertSame(e1, e2.cause) assertSame(e1, e2.cause)
assertSame(e2, e1.cause) assertSame(e2, e1.cause)
testOnJvm7AndAbove {
val trace = e2.stackTraceToString() val trace = e2.stackTraceToString()
assertTrue("CIRCULAR REFERENCE" in trace, trace) 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) 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 testOnJvm(action: () -> Unit) = action()
public actual fun testOnJs(action: () -> Unit) {} 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 isFloat32RangeEnforced: Boolean = true
public actual val supportsSuppressedExceptions: Boolean get() = !isJava6 public actual val supportsNamedCapturingGroup: Boolean
get() = System.getProperty("supportsNamedCapturingGroup")?.toBooleanStrict() ?: true
// 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 supportsOctalLiteralInRegex: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = true
@@ -6,7 +6,6 @@
package test.collections package test.collections
import test.collections.behaviors.* import test.collections.behaviors.*
import test.testOnNonJvm6And7
import kotlin.test.* import kotlin.test.*
class AbstractCollectionsTest { class AbstractCollectionsTest {
@@ -128,9 +127,7 @@ class AbstractCollectionsTest {
assertEquals(listOf("ok", "element"), list) assertEquals(listOf("ok", "element"), list)
testOnNonJvm6And7 { assertFailsWith<IndexOutOfBoundsException> { list.addAll(-1, listOf()) }
assertFailsWith<IndexOutOfBoundsException> { list.addAll(-1, listOf()) }
}
compare(list.storage, list) { compare(list.storage, list) {
listBehavior() listBehavior()
@@ -5,7 +5,6 @@
package test.exceptions package test.exceptions
import test.supportsSuppressedExceptions
import kotlin.test.* import kotlin.test.*
@Suppress("Reformat") // author's formatting @Suppress("Reformat") // author's formatting
@@ -81,11 +80,7 @@ class ExceptionTest {
e1.addSuppressed(c1) e1.addSuppressed(c1)
e1.addSuppressed(c2) e1.addSuppressed(c2)
if (supportsSuppressedExceptions) { assertEquals(listOf(c1, c2), e1.suppressedExceptions)
assertEquals(listOf(c1, c2), e1.suppressedExceptions)
} else {
assertTrue(e1.suppressedExceptions.isEmpty())
}
} }
@Test @Test
@@ -122,12 +117,10 @@ class ExceptionTest {
val cause = assertNotNull(e.cause, "Should have cause") val cause = assertNotNull(e.cause, "Should have cause")
assertInTrace(cause) assertInTrace(cause)
if (supportsSuppressedExceptions) { val topLevelSuppressed = e.suppressedExceptions.single()
val topLevelSuppressed = e.suppressedExceptions.single() assertInTrace(topLevelSuppressed)
assertInTrace(topLevelSuppressed) cause.suppressedExceptions.forEach {
cause.suppressedExceptions.forEach { assertInTrace(it)
assertInTrace(it)
}
} }
// fail(topLevelTrace) // to dump the entire trace // fail(topLevelTrace) // to dump the entire trace
@@ -135,8 +128,6 @@ class ExceptionTest {
@Test @Test
fun circularSuppressedDetailedTrace() { fun circularSuppressedDetailedTrace() {
if (!supportsSuppressedExceptions) return
// Testing an exception of the following structure // Testing an exception of the following structure
// e1 // e1
// -- suppressed: e0 (same stack as e1) // -- suppressed: e0 (same stack as e1)
+16 -21
View File
@@ -5,7 +5,6 @@
package test.text package test.text
import test.testOnNonJvm6And7
import kotlin.test.* import kotlin.test.*
class CharTest { class CharTest {
@@ -525,32 +524,28 @@ class CharTest {
@Test @Test
fun otherLowercaseProperty() { fun otherLowercaseProperty() {
testOnNonJvm6And7 { val feminineOrdinalIndicator = '\u00AA'
val feminineOrdinalIndicator = '\u00AA' assertTrue(feminineOrdinalIndicator.isLowerCase())
assertTrue(feminineOrdinalIndicator.isLowerCase()) assertTrue(feminineOrdinalIndicator.isLetter())
assertTrue(feminineOrdinalIndicator.isLetter()) assertFalse(feminineOrdinalIndicator.isUpperCase())
assertFalse(feminineOrdinalIndicator.isUpperCase())
val circledLatinSmallLetterA = '\u24D0' val circledLatinSmallLetterA = '\u24D0'
assertTrue(circledLatinSmallLetterA.isLowerCase()) assertTrue(circledLatinSmallLetterA.isLowerCase())
assertFalse(circledLatinSmallLetterA.isLetter()) assertFalse(circledLatinSmallLetterA.isLetter())
assertFalse(circledLatinSmallLetterA.isUpperCase()) assertFalse(circledLatinSmallLetterA.isUpperCase())
}
} }
@Test @Test
fun otherUppercaseProperty() { fun otherUppercaseProperty() {
testOnNonJvm6And7 { val romanNumberOne = '\u2160'
val romanNumberOne = '\u2160' assertTrue(romanNumberOne.isUpperCase())
assertTrue(romanNumberOne.isUpperCase()) assertFalse(romanNumberOne.isLetter())
assertFalse(romanNumberOne.isLetter()) assertFalse(romanNumberOne.isLowerCase())
assertFalse(romanNumberOne.isLowerCase())
val circledLatinCapitalLetterZ = '\u24CF' val circledLatinCapitalLetterZ = '\u24CF'
assertTrue(circledLatinCapitalLetterZ.isUpperCase()) assertTrue(circledLatinCapitalLetterZ.isUpperCase())
assertFalse(circledLatinCapitalLetterZ.isLetter()) assertFalse(circledLatinCapitalLetterZ.isLetter())
assertFalse(circledLatinCapitalLetterZ.isLowerCase()) assertFalse(circledLatinCapitalLetterZ.isLowerCase())
}
} }
@Test @Test
@@ -6,7 +6,6 @@
package test.text package test.text
import test.assertArrayContentEquals import test.assertArrayContentEquals
import test.testOnNonJvm6And7
import kotlin.test.* import kotlin.test.*
// When decoding utf-8, JVM and JS implementations replace the sequence reflecting a surrogate code point differently. // When decoding utf-8, JVM and JS implementations replace the sequence reflecting a surrogate code point differently.
@@ -207,28 +206,26 @@ class StringEncodingTest {
testDecoding(false, "z", bytes(0xE0, 0xAF, 0x7A)) // 3-byte char, third byte starts with 0 bit testDecoding(false, "z", bytes(0xE0, 0xAF, 0x7A)) // 3-byte char, third byte starts with 0 bit
testDecoding(true, "\u1FFF", bytes(0xE1, 0xBF, 0xBF)) // 3-byte char testDecoding(true, "\u1FFF", bytes(0xE1, 0xBF, 0xBF)) // 3-byte char
testOnNonJvm6And7 { testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF)) // 3-byte high-surrogate char
testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF)) // 3-byte high-surrogate char testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xB3, 0x9A)) // 3-byte low-surrogate char
testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xB3, 0x9A)) // 3-byte low-surrogate char testDecoding(
testDecoding( false,
false, surrogateCodePointDecoding + surrogateCodePointDecoding,
surrogateCodePointDecoding + surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF, /**/ 0xED, 0xB3, 0x9A)
bytes(0xED, 0xAF, 0xBF, /**/ 0xED, 0xB3, 0x9A) ) // surrogate pair chars
) // surrogate pair chars testDecoding(false, "z", bytes(0xEF, 0x7A)) // 3-byte char, second byte starts with 0 bit, third byte missing
testDecoding(false, "z", bytes(0xEF, 0x7A)) // 3-byte char, second byte starts with 0 bit, third byte missing
testDecoding(false, "", bytes(0xF9, 0x94, 0x80, 0x80, 0x80)) // 5-byte code point larger than 0x10FFFF testDecoding(false, "", bytes(0xF9, 0x94, 0x80, 0x80, 0x80)) // 5-byte code point larger than 0x10FFFF
testDecoding(false, "", bytes(0xFD, 0x94, 0x80, 0x80, 0x80, 0x80)) // 6-byte code point larger than 0x10FFFF testDecoding(false, "", bytes(0xFD, 0x94, 0x80, 0x80, 0x80, 0x80)) // 6-byte code point larger than 0x10FFFF
// Ill-Formed Sequences for Surrogates // Ill-Formed Sequences for Surrogates
testDecoding( testDecoding(
false, false,
surrogateCodePointDecoding + surrogateCodePointDecoding + truncatedSurrogateDecoding() + "A", surrogateCodePointDecoding + surrogateCodePointDecoding + truncatedSurrogateDecoding() + "A",
bytes(0xED, 0xA0, 0x80, /**/ 0xED, 0xBF, 0xBF, /**/ 0xED, 0xAF, /**/ 0x41) bytes(0xED, 0xA0, 0x80, /**/ 0xED, 0xBF, 0xBF, /**/ 0xED, 0xAF, /**/ 0x41)
) )
// Truncated Sequences // Truncated Sequences
testDecoding(false, "A", bytes(0xE1, 0x80, /**/ 0xE2, /**/ 0xF0, 0x91, 0x92, /**/ 0xF1, 0xBF, /**/ 0x41)) testDecoding(false, "A", bytes(0xE1, 0x80, /**/ 0xE2, /**/ 0xF0, 0x91, 0x92, /**/ 0xF1, 0xBF, /**/ 0x41))
}
testDecoding(false, "", bytes(0xE0, 0xAF)) // 3-byte char, third byte missing testDecoding(false, "", bytes(0xE0, 0xAF)) // 3-byte char, third byte missing
@@ -275,13 +272,11 @@ class StringEncodingTest {
testDecoding(false, "z", bytes(0xEF, 0xAF, 0x7A), startIndex = 1, endIndex = 3) testDecoding(false, "z", bytes(0xEF, 0xAF, 0x7A), startIndex = 1, endIndex = 3)
testDecoding(true, "z", bytes(0xEF, 0xAF, 0x7A), startIndex = 2, endIndex = 3) testDecoding(true, "z", bytes(0xEF, 0xAF, 0x7A), startIndex = 2, endIndex = 3)
testOnNonJvm6And7 { testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF), startIndex = 0, endIndex = 3)
testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF), startIndex = 0, endIndex = 3) testDecoding(false, truncatedSurrogateDecoding(), bytes(0xED, 0xB3, 0x9A), startIndex = 0, endIndex = 2)
testDecoding(false, truncatedSurrogateDecoding(), bytes(0xED, 0xB3, 0x9A), startIndex = 0, endIndex = 2) testDecoding(false, "", bytes(0xED, 0xAF, 0xBF, 0xED, 0xB3, 0x9A), startIndex = 1, endIndex = 4)
testDecoding(false, "", bytes(0xED, 0xAF, 0xBF, 0xED, 0xB3, 0x9A), startIndex = 1, endIndex = 4) testDecoding(false, "", bytes(0xEF, 0x7A), startIndex = 0, endIndex = 1)
testDecoding(false, "", bytes(0xEF, 0x7A), startIndex = 0, endIndex = 1) testDecoding(true, "z", bytes(0xEF, 0x7A), startIndex = 1, endIndex = 2)
testDecoding(true, "z", bytes(0xEF, 0x7A), startIndex = 1, endIndex = 2)
}
testDecoding(true, "\uD83D\uDFDF", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 0, endIndex = 4) testDecoding(true, "\uD83D\uDFDF", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 0, endIndex = 4)
testDecoding(false, "", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 2, endIndex = 4) testDecoding(false, "", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 2, endIndex = 4)
@@ -5,7 +5,6 @@
package test.text package test.text
import test.*
import kotlin.test.* import kotlin.test.*
class StringNumberConversionTest { class StringNumberConversionTest {
@@ -439,7 +438,7 @@ internal class ConversionContext<T : Any>(
} }
fun assertProduces(input: String, output: T) { fun assertProduces(input: String, output: T) {
assertEquals(output, convertOrFail(input.removeLeadingPlusOnJava6()), input, "convertOrFail") assertEquals(output, convertOrFail(input), input, "convertOrFail")
assertEquals(output, convertOrNull(input), input, "convertOrNull") assertEquals(output, convertOrNull(input), input, "convertOrNull")
} }
@@ -454,7 +453,7 @@ internal class ConversionWithRadixContext<T : Any>(
val convertOrNull: (String, Int) -> T? val convertOrNull: (String, Int) -> T?
) { ) {
fun assertProduces(radix: Int, input: String, output: T) { fun assertProduces(radix: Int, input: String, output: T) {
assertEquals(output, convertOrFail(input.removeLeadingPlusOnJava6(), radix)) assertEquals(output, convertOrFail(input, radix))
assertEquals(output, convertOrNull(input, radix)) assertEquals(output, convertOrNull(input, radix))
} }
-9
View File
@@ -12,13 +12,6 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
assertEquals(expected?.let { it::class }, actual?.let { it::class }) assertEquals(expected?.let { it::class }, actual?.let { it::class })
} }
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun String.removeLeadingPlusOnJava6(): String = this
internal actual inline fun testOnNonJvm6And7(f: () -> Unit) {
f()
}
public actual fun testOnJvm(action: () -> Unit) { } public actual fun testOnJvm(action: () -> Unit) { }
public actual fun testOnJs(action: () -> Unit) { } public actual fun testOnJs(action: () -> Unit) { }
@@ -26,8 +19,6 @@ public actual fun testOnJs(action: () -> Unit) { }
// TODO: See KT-24975 // TODO: See KT-24975
public actual val isFloat32RangeEnforced: Boolean = false public actual val isFloat32RangeEnforced: Boolean = false
actual val supportsSuppressedExceptions: Boolean get() = true
public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsNamedCapturingGroup: Boolean get() = true
public actual val supportsOctalLiteralInRegex: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = true