diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt index bd5f9a4fc71..ddf6ac098e1 100644 --- a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt @@ -10,35 +10,35 @@ fun box(): String { val s = J::s // Check that correct reflection objects are created - assert(i !is KMutableProperty<*>, "Fail i class: ${i.javaClass}") - assert(s is KMutableProperty<*>, "Fail s class: ${s.javaClass}") + assert(i !is KMutableProperty<*>) { "Fail i class: ${i.javaClass}" } + assert(s is KMutableProperty<*>) { "Fail s class: ${s.javaClass}" } // Check that no Method objects are created for such properties - assert(i.javaGetter == null, "Fail i getter") - assert(s.javaGetter == null, "Fail s getter") - assert(s.javaSetter == null, "Fail s setter") + assert(i.javaGetter == null) { "Fail i getter" } + assert(s.javaGetter == null) { "Fail s getter" } + assert(s.javaSetter == null) { "Fail s setter" } // Check that correct Field objects are created val ji = i.javaField!! val js = s.javaField!! - assert(Modifier.isFinal(ji.getModifiers()), "Fail i final") - assert(!Modifier.isFinal(js.getModifiers()), "Fail s final") + assert(Modifier.isFinal(ji.getModifiers())) { "Fail i final" } + assert(!Modifier.isFinal(js.getModifiers())) { "Fail s final" } // Check that those Field objects work as expected val a = J(42, "abc") - assert(ji.get(a) == 42, "Fail ji get") - assert(js.get(a) == "abc", "Fail js get") + assert(ji.get(a) == 42) { "Fail ji get" } + assert(js.get(a) == "abc") { "Fail js get" } js.set(a, "def") - assert(js.get(a) == "def", "Fail js set") - assert(a.s == "def", "Fail js access") + assert(js.get(a) == "def") { "Fail js set" } + assert(a.s == "def") { "Fail js access" } // Check that valid Kotlin reflection objects are created by those Field objects val ki = ji.kotlin as KProperty1 val ks = js.kotlin as KMutableProperty1 - assert(ki.get(a) == 42, "Fail ki get") - assert(ks.get(a) == "def", "Fail ks get") + assert(ki.get(a) == 42) { "Fail ki get" } + assert(ks.get(a) == "def") { "Fail ks get" } ks.set(a, "ghi") - assert(ks.get(a) == "ghi", "Fail ks set") + assert(ks.get(a) == "ghi") { "Fail ks set" } return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/constructor.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/constructor.kt index a8675dd7064..3523def22a6 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/constructor.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/constructor.kt @@ -11,14 +11,14 @@ class Secondary { } fun check(f: KFunction) { - assert(f.javaMethod == null, "Fail f method") - assert(f.javaConstructor != null, "Fail f constructor") + assert(f.javaMethod == null) { "Fail f method" } + assert(f.javaConstructor != null) { "Fail f constructor" } val c = f.javaConstructor!! - assert(c.kotlinFunction != null, "Fail m function") + assert(c.kotlinFunction != null) { "Fail m function" } val ff = c.kotlinFunction!! - assert(f == ff, "Fail f != ff") + assert(f == ff) { "Fail f != ff" } } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt index ae4d00a1c69..520fc873034 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/extensionProperty.kt @@ -19,9 +19,9 @@ fun box(): String { assertEquals(setter, Class.forName("ExtensionPropertyKt").getMethod("setExt", javaClass(), javaClass())) val k = K(42L) - assert(getter.invoke(null, k) == 42.0, "Fail k getter") + assert(getter.invoke(null, k) == 42.0) { "Fail k getter" } setter.invoke(null, k, -239.0) - assert(getter.invoke(null, k) == -239.0, "Fail k setter") + assert(getter.invoke(null, k) == -239.0) { "Fail k setter" } return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/functions.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/functions.kt index 2adf3f89de1..b385de6e60f 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/functions.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/functions.kt @@ -8,14 +8,14 @@ fun bar(s: String): Int = s.length() fun String.baz(): Int = this.length() fun check(f: KFunction) { - assert(f.javaConstructor == null, "Fail f constructor") - assert(f.javaMethod != null, "Fail f method") + assert(f.javaConstructor == null) { "Fail f constructor" } + assert(f.javaMethod != null) { "Fail f method" } val m = f.javaMethod!! - assert(m.kotlinFunction != null, "Fail m function") + assert(m.kotlinFunction != null) { "Fail m function" } val ff = m.kotlinFunction!! - assert(f == ff, "Fail f != ff") + assert(f == ff) { "Fail f != ff" } } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt index e39bb09d767..e3b867fab78 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/memberProperty.kt @@ -6,7 +6,7 @@ class K(var value: Long) fun box(): String { val p = K::value - assert(p.javaField != null, "Fail p field") + assert(p.javaField != null) { "Fail p field" } val getter = p.javaGetter!! val setter = p.javaSetter!! @@ -15,9 +15,9 @@ fun box(): String { assertEquals(setter, javaClass().getMethod("setValue", javaClass())) val k = K(42L) - assert(getter.invoke(k) == 42L, "Fail k getter") + assert(getter.invoke(k) == 42L) { "Fail k getter" } setter.invoke(k, -239L) - assert(getter.invoke(k) == -239L, "Fail k setter") + assert(getter.invoke(k) == -239L) { "Fail k setter" } return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt index 2925f3ead89..e1b8ba66e9a 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt @@ -6,7 +6,7 @@ var topLevel = "123" fun box(): String { val p = ::topLevel - assert(p.javaField != null, "Fail p field") + assert(p.javaField != null) { "Fail p field" } val field = p.javaField!! val className = field.getDeclaringClass().getName() assertEquals("TopLevelPropertyKt", className) @@ -17,9 +17,9 @@ fun box(): String { assertEquals(getter, Class.forName("TopLevelPropertyKt").getMethod("getTopLevel")) assertEquals(setter, Class.forName("TopLevelPropertyKt").getMethod("setTopLevel", javaClass())) - assert(getter.invoke(null) == "123", "Fail k getter") + assert(getter.invoke(null) == "123") { "Fail k getter" } setter.invoke(null, "456") - assert(getter.invoke(null) == "456", "Fail k setter") + assert(getter.invoke(null) == "456") { "Fail k setter" } return "OK" } diff --git a/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.B.kt b/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.B.kt index d57b275fa83..1cce6203cee 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.B.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.B.kt @@ -8,5 +8,5 @@ fun main(args: Array) { val annotationClass = javaClass() val annotation = klass.getAnnotation(annotationClass)!! val value = annotation.value - require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", "Annotation value: $value") + require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", { "Annotation value: $value" }) } \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt index fb6e5b64d97..71018bafc65 100644 --- a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt +++ b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt @@ -20,7 +20,7 @@ public fun assert(value: Boolean) { * Throws an [AssertionError] with an optional [message] if the [value] is false * and runtime assertions have been enabled on the JVM using the *-ea* JVM option. */ -@Deprecated("Use assert with lazy message instead.", ReplaceWith("assert(value) { message }")) +@Deprecated("Use assert with lazy message instead.", ReplaceWith("assert(value) { message }"), DeprecationLevel.ERROR) public fun assert(value: Boolean, message: Any = "Assertion failed") { @Suppress("DEPRECATION") if (ASSERTIONS_ENABLED) { diff --git a/libraries/stdlib/src/kotlin/util/Preconditions.kt b/libraries/stdlib/src/kotlin/util/Preconditions.kt index 8e183bc5d6e..388318750ae 100644 --- a/libraries/stdlib/src/kotlin/util/Preconditions.kt +++ b/libraries/stdlib/src/kotlin/util/Preconditions.kt @@ -16,7 +16,7 @@ public fun require(value: Boolean): Unit = require(value) { "Failed requirement" * * @sample test.collections.PreconditionsTest.failingRequireWithMessage */ -@Deprecated("Use require with lazy message instead.", ReplaceWith("require(value) { message }")) +@Deprecated("Use require with lazy message instead.", ReplaceWith("require(value) { message }"), DeprecationLevel.ERROR) public fun require(value: Boolean, message: Any = "Failed requirement"): Unit { if (!value) { throw IllegalArgumentException(message.toString()) @@ -46,7 +46,7 @@ public fun requireNotNull(value: T?): T = requireNotNull(value) { "Requi * * @sample test.collections.PreconditionsTest.requireNotNull */ -@Deprecated("Use requireNotNull with lazy message instead.", ReplaceWith("requireNotNull(value) { message }")) +@Deprecated("Use requireNotNull with lazy message instead.", ReplaceWith("requireNotNull(value) { message }"), DeprecationLevel.ERROR) public fun requireNotNull(value: T?, message: Any = "Required value was null"): T { if (value == null) { throw IllegalArgumentException(message.toString()) @@ -80,7 +80,7 @@ public fun check(value: Boolean): Unit = check(value) { "Check failed" } * * @sample test.collections.PreconditionsTest.failingCheckWithMessage */ -@Deprecated("Use check with lazy message instead.", ReplaceWith("check(value) { message }")) +@Deprecated("Use check with lazy message instead.", ReplaceWith("check(value) { message }"), DeprecationLevel.ERROR) public fun check(value: Boolean, message: Any = "Check failed"): Unit { if (!value) { throw IllegalStateException(message.toString()) @@ -111,7 +111,7 @@ public fun checkNotNull(value: T?): T = checkNotNull(value) { "Required * * @sample test.collections.PreconditionsTest.checkNotNull */ -@Deprecated("Use checkNotNull with lazy message instead.", ReplaceWith("checkNotNull(value) { message }")) +@Deprecated("Use checkNotNull with lazy message instead.", ReplaceWith("checkNotNull(value) { message }"), DeprecationLevel.ERROR) public fun checkNotNull(value: T?, message: Any = "Required value was null"): T { if (value == null) { throw IllegalStateException(message.toString()) diff --git a/libraries/stdlib/test/PreconditionsTest.kt b/libraries/stdlib/test/PreconditionsTest.kt index 766e93b3ba8..a62746d4963 100644 --- a/libraries/stdlib/test/PreconditionsTest.kt +++ b/libraries/stdlib/test/PreconditionsTest.kt @@ -20,17 +20,6 @@ class PreconditionsTest() { assertNotNull(error.getMessage()) } - @test fun passingRequireWithMessage() { - require(true, "Hello") - } - - @test fun failingRequireWithMessage() { - val error = assertFailsWith(IllegalArgumentException::class) { - require(false, "Hello") - } - assertEquals("Hello", error.getMessage()) - } - @test fun failingRequireWithLazyMessage() { val error = assertFailsWith(IllegalArgumentException::class) { require(false) { "Hello" } @@ -53,17 +42,6 @@ class PreconditionsTest() { assertNotNull(error.getMessage()) } - @test fun passingCheckWithMessage() { - check(true, "Hello") - } - - @test fun failingCheckWithMessage() { - val error = assertFailsWith(IllegalStateException::class) { - check(false, "Hello") - } - assertEquals("Hello", error.getMessage()) - } - @test fun failingCheckWithLazyMessage() { val error = assertFailsWith(IllegalStateException::class) { check(false) { "Hello" } @@ -144,12 +122,12 @@ class PreconditionsTest() { } @test fun passingAssertWithMessage() { - assert(true, "Hello") + assert(true) { "Hello" } } @test fun failingAssertWithMessage() { val error = assertFails { - assert(false, "Hello") + assert(false) { "Hello" } } if (error is AssertionError) { assertEquals("Hello", error.getMessage()) diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index e8416ca6ac4..c6f5a1968e8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -65,9 +65,9 @@ class KotlinGradleIT: BaseGradleIT() { project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) { assertSuccessful() val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().find(output) - assert(matches != null && matches.groups.size() == 3, "Used memory after build is not reported by plugin") + assert(matches != null && matches.groups.size() == 3) { "Used memory after build is not reported by plugin" } val reportedGrowth = matches!!.groups.get(2)!!.value.removePrefix("+").toInt() - assert(reportedGrowth <= 700, "Used memory growth $reportedGrowth > 700") + assert(reportedGrowth <= 700) { "Used memory growth $reportedGrowth > 700" } } }