diff --git a/kotlin-native/backend.native/tests/stdlib_external/utils.kt b/kotlin-native/backend.native/tests/stdlib_external/utils.kt index 8ca0f9b13ef..b4ca95d825d 100644 --- a/kotlin-native/backend.native/tests/stdlib_external/utils.kt +++ b/kotlin-native/backend.native/tests/stdlib_external/utils.kt @@ -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 testOnJs(action: () -> Unit) {} public actual val isFloat32RangeEnforced: Boolean get() = true -public actual val supportsSuppressedExceptions: Boolean get() = true - public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = true diff --git a/libraries/stdlib/common/test/testUtils.kt b/libraries/stdlib/common/test/testUtils.kt index 5d2e02d3682..9b5ffaf3ee8 100644 --- a/libraries/stdlib/common/test/testUtils.kt +++ b/libraries/stdlib/common/test/testUtils.kt @@ -7,17 +7,11 @@ package test 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 testOnJs(action: () -> Unit) public expect val isFloat32RangeEnforced: Boolean -public expect val supportsSuppressedExceptions: Boolean - public expect val supportsNamedCapturingGroup: Boolean public expect val supportsOctalLiteralInRegex: Boolean diff --git a/libraries/stdlib/jdk7/build.gradle b/libraries/stdlib/jdk7/build.gradle index b1328dc1cbe..65dfcc577ce 100644 --- a/libraries/stdlib/jdk7/build.gradle +++ b/libraries/stdlib/jdk7/build.gradle @@ -79,6 +79,10 @@ compileTestKotlin { ] } +tasks.withType(Test) { + systemProperty("supportsNamedCapturingGroup", false) +} + configureFrontendIr(project) LibrariesCommon.configureJava9Compilation(project, 'kotlin.stdlib.jdk7') diff --git a/libraries/stdlib/js/test/core/testUtils.kt b/libraries/stdlib/js/test/core/testUtils.kt index 03f000201af..742834bd55f 100644 --- a/libraries/stdlib/js/test/core/testUtils.kt +++ b/libraries/stdlib/js/test/core/testUtils.kt @@ -11,13 +11,6 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) { 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 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 public actual val isFloat32RangeEnforced: Boolean = false -actual val supportsSuppressedExceptions: Boolean get() = true - public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = false diff --git a/libraries/stdlib/jvm/build.gradle b/libraries/stdlib/jvm/build.gradle index ecb2456b7e1..f56b1284e07 100644 --- a/libraries/stdlib/jvm/build.gradle +++ b/libraries/stdlib/jvm/build.gradle @@ -133,6 +133,10 @@ compileTestKotlin { } } +test { + systemProperty("supportsNamedCapturingGroup", false) +} + compileLongRunningTestKotlin { kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.ExperimentalStdlibApi" } diff --git a/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt b/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt index 950ea19d139..ad213cb9a6e 100644 --- a/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt +++ b/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt @@ -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(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance()) - } catch (e: ClassNotFoundException) { } - try { - return@run castToBaseType(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance()) - } catch (e: ClassNotFoundException) { } - } - - if (version >= 0x10007 || version < 0x10000) { - try { - return@run castToBaseType(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance()) - } catch (e: ClassNotFoundException) { } - try { - return@run castToBaseType(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance()) - } catch (e: ClassNotFoundException) { } - } + try { + return@run castToBaseType(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance()) + } catch (e: ClassNotFoundException) { } + try { + return@run castToBaseType(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance()) + } catch (e: ClassNotFoundException) { } + try { + return@run castToBaseType(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance()) + } catch (e: ClassNotFoundException) { } + try { + return@run castToBaseType(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance()) + } catch (e: ClassNotFoundException) { } PlatformImplementations() } @@ -84,25 +78,6 @@ private inline fun 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 * diff --git a/libraries/stdlib/jvm/test/exceptions/ExceptionJVMTest.kt b/libraries/stdlib/jvm/test/exceptions/ExceptionJVMTest.kt index ec515323019..a6d726da43c 100644 --- a/libraries/stdlib/jvm/test/exceptions/ExceptionJVMTest.kt +++ b/libraries/stdlib/jvm/test/exceptions/ExceptionJVMTest.kt @@ -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) } } diff --git a/libraries/stdlib/jvm/test/testUtilsJVM.kt b/libraries/stdlib/jvm/test/testUtilsJVM.kt index de8b0efd1b6..22a7d06535d 100644 --- a/libraries/stdlib/jvm/test/testUtilsJVM.kt +++ b/libraries/stdlib/jvm/test/testUtilsJVM.kt @@ -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 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 diff --git a/libraries/stdlib/test/collections/AbstractCollectionsTest.kt b/libraries/stdlib/test/collections/AbstractCollectionsTest.kt index 8de56a93de4..2d6bebb229d 100644 --- a/libraries/stdlib/test/collections/AbstractCollectionsTest.kt +++ b/libraries/stdlib/test/collections/AbstractCollectionsTest.kt @@ -6,7 +6,6 @@ package test.collections import test.collections.behaviors.* -import test.testOnNonJvm6And7 import kotlin.test.* class AbstractCollectionsTest { @@ -128,9 +127,7 @@ class AbstractCollectionsTest { assertEquals(listOf("ok", "element"), list) - testOnNonJvm6And7 { - assertFailsWith { list.addAll(-1, listOf()) } - } + assertFailsWith { list.addAll(-1, listOf()) } compare(list.storage, list) { listBehavior() diff --git a/libraries/stdlib/test/exceptions/ExceptionTest.kt b/libraries/stdlib/test/exceptions/ExceptionTest.kt index 0c44ea831ba..49fb408c02c 100644 --- a/libraries/stdlib/test/exceptions/ExceptionTest.kt +++ b/libraries/stdlib/test/exceptions/ExceptionTest.kt @@ -5,7 +5,6 @@ package test.exceptions -import test.supportsSuppressedExceptions import kotlin.test.* @Suppress("Reformat") // author's formatting @@ -81,11 +80,7 @@ class ExceptionTest { e1.addSuppressed(c1) e1.addSuppressed(c2) - if (supportsSuppressedExceptions) { - assertEquals(listOf(c1, c2), e1.suppressedExceptions) - } else { - assertTrue(e1.suppressedExceptions.isEmpty()) - } + assertEquals(listOf(c1, c2), e1.suppressedExceptions) } @Test @@ -122,12 +117,10 @@ class ExceptionTest { val cause = assertNotNull(e.cause, "Should have cause") assertInTrace(cause) - if (supportsSuppressedExceptions) { - val topLevelSuppressed = e.suppressedExceptions.single() - assertInTrace(topLevelSuppressed) - cause.suppressedExceptions.forEach { - assertInTrace(it) - } + val topLevelSuppressed = e.suppressedExceptions.single() + assertInTrace(topLevelSuppressed) + cause.suppressedExceptions.forEach { + assertInTrace(it) } // fail(topLevelTrace) // to dump the entire trace @@ -135,8 +128,6 @@ class ExceptionTest { @Test fun circularSuppressedDetailedTrace() { - if (!supportsSuppressedExceptions) return - // Testing an exception of the following structure // e1 // -- suppressed: e0 (same stack as e1) diff --git a/libraries/stdlib/test/text/CharTest.kt b/libraries/stdlib/test/text/CharTest.kt index ffef7d6af4c..6207b56be02 100644 --- a/libraries/stdlib/test/text/CharTest.kt +++ b/libraries/stdlib/test/text/CharTest.kt @@ -5,7 +5,6 @@ package test.text -import test.testOnNonJvm6And7 import kotlin.test.* class CharTest { @@ -525,32 +524,28 @@ class CharTest { @Test fun otherLowercaseProperty() { - testOnNonJvm6And7 { - val feminineOrdinalIndicator = '\u00AA' - assertTrue(feminineOrdinalIndicator.isLowerCase()) - assertTrue(feminineOrdinalIndicator.isLetter()) - assertFalse(feminineOrdinalIndicator.isUpperCase()) + val feminineOrdinalIndicator = '\u00AA' + assertTrue(feminineOrdinalIndicator.isLowerCase()) + assertTrue(feminineOrdinalIndicator.isLetter()) + assertFalse(feminineOrdinalIndicator.isUpperCase()) - val circledLatinSmallLetterA = '\u24D0' - assertTrue(circledLatinSmallLetterA.isLowerCase()) - assertFalse(circledLatinSmallLetterA.isLetter()) - assertFalse(circledLatinSmallLetterA.isUpperCase()) - } + val circledLatinSmallLetterA = '\u24D0' + assertTrue(circledLatinSmallLetterA.isLowerCase()) + assertFalse(circledLatinSmallLetterA.isLetter()) + assertFalse(circledLatinSmallLetterA.isUpperCase()) } @Test fun otherUppercaseProperty() { - testOnNonJvm6And7 { - val romanNumberOne = '\u2160' - assertTrue(romanNumberOne.isUpperCase()) - assertFalse(romanNumberOne.isLetter()) - assertFalse(romanNumberOne.isLowerCase()) + val romanNumberOne = '\u2160' + assertTrue(romanNumberOne.isUpperCase()) + assertFalse(romanNumberOne.isLetter()) + assertFalse(romanNumberOne.isLowerCase()) - val circledLatinCapitalLetterZ = '\u24CF' - assertTrue(circledLatinCapitalLetterZ.isUpperCase()) - assertFalse(circledLatinCapitalLetterZ.isLetter()) - assertFalse(circledLatinCapitalLetterZ.isLowerCase()) - } + val circledLatinCapitalLetterZ = '\u24CF' + assertTrue(circledLatinCapitalLetterZ.isUpperCase()) + assertFalse(circledLatinCapitalLetterZ.isLetter()) + assertFalse(circledLatinCapitalLetterZ.isLowerCase()) } @Test diff --git a/libraries/stdlib/test/text/StringEncodingTest.kt b/libraries/stdlib/test/text/StringEncodingTest.kt index 355bd1328b3..1a35cc06109 100644 --- a/libraries/stdlib/test/text/StringEncodingTest.kt +++ b/libraries/stdlib/test/text/StringEncodingTest.kt @@ -6,7 +6,6 @@ package test.text import test.assertArrayContentEquals -import test.testOnNonJvm6And7 import kotlin.test.* // 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(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, 0xB3, 0x9A)) // 3-byte low-surrogate char - testDecoding( - false, - surrogateCodePointDecoding + surrogateCodePointDecoding, - bytes(0xED, 0xAF, 0xBF, /**/ 0xED, 0xB3, 0x9A) - ) // surrogate pair chars - testDecoding(false, "�z", bytes(0xEF, 0x7A)) // 3-byte char, second byte starts with 0 bit, third byte missing + 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 + surrogateCodePointDecoding, + bytes(0xED, 0xAF, 0xBF, /**/ 0xED, 0xB3, 0x9A) + ) // surrogate pair chars + 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(0xFD, 0x94, 0x80, 0x80, 0x80, 0x80)) // 6-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 - // Ill-Formed Sequences for Surrogates - testDecoding( - false, - surrogateCodePointDecoding + surrogateCodePointDecoding + truncatedSurrogateDecoding() + "A", - bytes(0xED, 0xA0, 0x80, /**/ 0xED, 0xBF, 0xBF, /**/ 0xED, 0xAF, /**/ 0x41) - ) - // Truncated Sequences - testDecoding(false, "����A", bytes(0xE1, 0x80, /**/ 0xE2, /**/ 0xF0, 0x91, 0x92, /**/ 0xF1, 0xBF, /**/ 0x41)) - } + // Ill-Formed Sequences for Surrogates + testDecoding( + false, + surrogateCodePointDecoding + surrogateCodePointDecoding + truncatedSurrogateDecoding() + "A", + bytes(0xED, 0xA0, 0x80, /**/ 0xED, 0xBF, 0xBF, /**/ 0xED, 0xAF, /**/ 0x41) + ) + // Truncated Sequences + testDecoding(false, "����A", bytes(0xE1, 0x80, /**/ 0xE2, /**/ 0xF0, 0x91, 0x92, /**/ 0xF1, 0xBF, /**/ 0x41)) 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(true, "z", bytes(0xEF, 0xAF, 0x7A), startIndex = 2, endIndex = 3) - testOnNonJvm6And7 { - testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF), startIndex = 0, endIndex = 3) - 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(0xEF, 0x7A), startIndex = 0, endIndex = 1) - testDecoding(true, "z", bytes(0xEF, 0x7A), startIndex = 1, endIndex = 2) - } + testDecoding(false, surrogateCodePointDecoding, bytes(0xED, 0xAF, 0xBF), startIndex = 0, endIndex = 3) + 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(0xEF, 0x7A), startIndex = 0, endIndex = 1) + testDecoding(true, "z", bytes(0xEF, 0x7A), startIndex = 1, endIndex = 2) testDecoding(true, "\uD83D\uDFDF", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 0, endIndex = 4) testDecoding(false, "��", bytes(0xF0, 0x9F, 0x9F, 0x9F), startIndex = 2, endIndex = 4) diff --git a/libraries/stdlib/test/text/StringNumberConversionTest.kt b/libraries/stdlib/test/text/StringNumberConversionTest.kt index 5e5f048d81e..6960ea316bb 100644 --- a/libraries/stdlib/test/text/StringNumberConversionTest.kt +++ b/libraries/stdlib/test/text/StringNumberConversionTest.kt @@ -5,7 +5,6 @@ package test.text -import test.* import kotlin.test.* class StringNumberConversionTest { @@ -439,7 +438,7 @@ internal class ConversionContext( } 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") } @@ -454,7 +453,7 @@ internal class ConversionWithRadixContext( val convertOrNull: (String, Int) -> 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)) } diff --git a/libraries/stdlib/wasm/test/testUtils.kt b/libraries/stdlib/wasm/test/testUtils.kt index ec6333e6c73..78d4c41031d 100644 --- a/libraries/stdlib/wasm/test/testUtils.kt +++ b/libraries/stdlib/wasm/test/testUtils.kt @@ -12,13 +12,6 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) { 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 testOnJs(action: () -> Unit) { } @@ -26,8 +19,6 @@ public actual fun testOnJs(action: () -> Unit) { } // TODO: See KT-24975 public actual val isFloat32RangeEnforced: Boolean = false -actual val supportsSuppressedExceptions: Boolean get() = true - public actual val supportsNamedCapturingGroup: Boolean get() = true public actual val supportsOctalLiteralInRegex: Boolean get() = true