From 82dfd5bb6d6097b8215fb66637a830f3fc0e8781 Mon Sep 17 00:00:00 2001 From: Eva Tatarka Date: Tue, 5 Dec 2023 13:03:15 -0800 Subject: [PATCH] remove error-level deprecations --- .../src/commonMain/kotlin/assertk/assert.kt | 20 ------- .../src/commonMain/kotlin/assertk/failure.kt | 6 --- .../kotlin/test/assertk/AssertLambdaTest.kt | 54 ------------------- .../jvmMain/kotlin/assertk/assertions/any.kt | 28 ---------- 4 files changed, 108 deletions(-) delete mode 100644 assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt diff --git a/assertk/src/commonMain/kotlin/assertk/assert.kt b/assertk/src/commonMain/kotlin/assertk/assert.kt index dd166f1f..548938ae 100644 --- a/assertk/src/commonMain/kotlin/assertk/assert.kt +++ b/assertk/src/commonMain/kotlin/assertk/assert.kt @@ -1,12 +1,8 @@ package assertk -import assertk.assertions.isFailure -import assertk.assertions.isSuccess import assertk.assertions.support.display import assertk.assertions.support.show -import kotlin.DeprecationLevel.ERROR import kotlin.reflect.KProperty0 -import kotlin.runCatching /** * Marks the assertion DSL. @@ -175,22 +171,6 @@ fun Assert.all(body: Assert.() -> Unit) { } } -/** - * Asserts on the given block returning an `Assert>`. You can test that it returns a value or throws an exception. - * - * ``` - * assertThat { 1 + 1 }.isSuccess().isPositive() - * - * assertThat { - * throw Exception("error") - * }.isFailure().hasMessage("error") - * ``` - * - * @see assertFailure - */ -@Deprecated("Use assertThat(result) or assertFailure", ReplaceWith("assertThat(runCatching(f))"), ERROR) -inline fun assertThat(f: () -> T): Assert> = assertThat(runCatching(f)) - /** * Runs all assertions in the given lambda and reports any failures. */ diff --git a/assertk/src/commonMain/kotlin/assertk/failure.kt b/assertk/src/commonMain/kotlin/assertk/failure.kt index ddce92a3..24825ae8 100644 --- a/assertk/src/commonMain/kotlin/assertk/failure.kt +++ b/assertk/src/commonMain/kotlin/assertk/failure.kt @@ -157,12 +157,6 @@ fun fail(error: AssertionError): Nothing { internal val NONE: Any = Any() -// TODO Delete this before 1.0. -@Deprecated("For binary compatibility", level = HIDDEN) -fun fail(message: String, expected: Any? = NONE, actual: Any? = NONE): Nothing { - fail(message, expected, actual, null) -} - /** * Fail the test with the given message. */ diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt deleted file mode 100644 index d3f32334..00000000 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package test.assertk - -import assertk.assertThat -import assertk.assertions.hasMessage -import assertk.assertions.isEqualTo -import assertk.assertions.isFailure -import assertk.assertions.isSuccess -import test.assertk.assertions.valueOrFail -import kotlin.test.Test -import kotlin.test.assertEquals - -@Suppress("DEPRECATION_ERROR") -class AssertLambdaTest { - - @Test - fun successful_assert_lambda_returns_success() { - assertEquals(Result.success(2), assertThat { 1 + 1 }.valueOrFail) - } - - @Test - fun successful_assert_lambda_returning_null_returns_success() { - assertEquals(Result.success(null), assertThat { null }.valueOrFail) - } - - @Test - fun failing_assert_lambda_returns_failure() { - val e = Exception("error") - assertEquals(Result.failure(e), assertThat { throw e }.valueOrFail) - } - - @Test - fun returnedValue_works_in_coroutine_test() = runTest { - assertThat { - asyncReturnValue() - }.isSuccess().isEqualTo(1) - } - - @Test - fun returnedValue_exception_works_in_coroutine_test() = runTest { - assertThat { - asyncThrows() - }.isFailure().hasMessage("test") - } - - @Suppress("RedundantSuspendModifier") - private suspend fun asyncReturnValue(): Int { - return 1 - } - - @Suppress("RedundantSuspendModifier") - private suspend fun asyncThrows() { - throw Exception("test") - } -} \ No newline at end of file diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt index 6d770b34..b9a166ab 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt @@ -7,8 +7,6 @@ import assertk.all import assertk.assertions.support.appendName import assertk.assertions.support.expected import assertk.assertions.support.show -import java.lang.reflect.InvocationTargetException -import kotlin.reflect.KCallable import kotlin.reflect.KClass import kotlin.reflect.KProperty1 import kotlin.reflect.full.IllegalCallableAccessException @@ -68,32 +66,6 @@ fun Assert.isNotInstanceOf(jclass: Class) = given { actual - expected("to not be instance of:${show(jclass)}") } -/** - * Returns an assert that asserts on the given property. - * @param callable The function to get the property value out of the value of the current assert. The name of this - * callable will be shown in failure messages. - * - * ``` - * assertThat(person).prop(Person::name).isEqualTo("Sue") - * ``` - * - * @see prop - */ -@Deprecated( - "Use an overload with explicit name and extract", - ReplaceWith("this.prop(\"NAME\") { callable.call(it) }", "assertk.assertions.prop"), - level = DeprecationLevel.ERROR -) -@Suppress("SwallowedException") -fun Assert.prop(callable: KCallable

) = prop(callable.name) { - try { - callable.call(it) - } catch (e: InvocationTargetException) { - // unwrap cause for a more helpful error message. - throw e.cause!! - } -} - /** * Like [isEqualTo] but reports exactly which properties differ. Only supports data classes. Note: you should * _not_ use this if your data class has a custom [Any.equals] since it can be misleading.