From a2c31ce94617caa7e7157921ddbe010c61a135fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 28 Mar 2026 17:22:46 +0100 Subject: [PATCH 1/2] feat(suite): Display failed exception assertions on two lines --- suite/src/commonMain/kotlin/assertions/Exceptions.kt | 4 ++-- suite/src/commonTest/kotlin/assertions/ExceptionsTest.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/suite/src/commonMain/kotlin/assertions/Exceptions.kt b/suite/src/commonMain/kotlin/assertions/Exceptions.kt index 82d1477..e18a51f 100644 --- a/suite/src/commonMain/kotlin/assertions/Exceptions.kt +++ b/suite/src/commonMain/kotlin/assertions/Exceptions.kt @@ -46,8 +46,8 @@ inline fun checkThrows(block: () -> Any?): T { } catch (e: Throwable) { // Simplifiable in Kotlin 2.2.20: https://youtrack.jetbrains.com/issue/KT-54363 when (e) { is T -> return e - else -> throw AssertionError("Expected to throw ${T::class}, but the operation threw the exception $e (see cause below for details)", e) + else -> throw AssertionError("Expected to throw ${T::class}\nbut the operation threw the exception $e (see cause below for details)", e) } } - throw AssertionError("Expected to throw ${T::class}, but the operation was successful and returned: $result") + throw AssertionError("Expected to throw ${T::class}\nbut the operation was successful and returned: $result") } diff --git a/suite/src/commonTest/kotlin/assertions/ExceptionsTest.kt b/suite/src/commonTest/kotlin/assertions/ExceptionsTest.kt index 72622b1..65eee02 100644 --- a/suite/src/commonTest/kotlin/assertions/ExceptionsTest.kt +++ b/suite/src/commonTest/kotlin/assertions/ExceptionsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ val ExceptionAssertionsTest by preparedSuite { error("This should go through the 'checkThrows' call") } } catch (e: AssertionError) { - check(e.message matches "Expected to throw .*IllegalArgumentException.*, but the operation threw the exception .*IllegalStateException: This should go through the 'checkThrows' call \\(see cause below for details\\)") + check(e.message matches "Expected to throw .*IllegalArgumentException.*\nbut the operation threw the exception .*IllegalStateException: This should go through the 'checkThrows' call \\(see cause below for details\\)") check(e.cause?.message == "This should go through the 'checkThrows' call") } } @@ -44,7 +44,7 @@ val ExceptionAssertionsTest by preparedSuite { val a = 5 } } catch (e: AssertionError) { - check(e.message matches "Expected to throw .*IllegalArgumentException.*, but the operation was successful and returned: .*Unit") + check(e.message matches "Expected to throw .*IllegalArgumentException.*\nbut the operation was successful and returned: .*Unit") } } -- 2.51.2 From ea498f5aff0794e3fbe5ff8f00b4336b3a8c58cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 28 Mar 2026 17:30:31 +0100 Subject: [PATCH 2/2] feat(compat-arrow): Display failed Raise assertions on two lines --- .../src/commonMain/kotlin/core/EnsureRaises.kt | 8 ++++---- .../src/commonTest/kotlin/EnsureRaisesTest.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compat/compat-arrow/src/commonMain/kotlin/core/EnsureRaises.kt b/compat/compat-arrow/src/commonMain/kotlin/core/EnsureRaises.kt index 5c157c6..aa6b6d4 100644 --- a/compat/compat-arrow/src/commonMain/kotlin/core/EnsureRaises.kt +++ b/compat/compat-arrow/src/commonMain/kotlin/core/EnsureRaises.kt @@ -36,11 +36,11 @@ inline fun checkRaises(expected: Failure, block: Raise.() -> Any either(block).fold( ifLeft = { if (it != expected) - throw AssertionError("Expected to fail with $expected, but failed with $it") + throw AssertionError("Expected to fail with $expected\nbut failed with $it") // else: successful case }, ifRight = { - throw AssertionError("Expected to fail with $expected, but the operation was successful and returned $it") + throw AssertionError("Expected to fail with $expected\nbut the operation was successful and returned $it") }, ) } @@ -62,11 +62,11 @@ inline fun checkRaises(block: Raise.() -> Any?) { either(block).fold( ifLeft = { if (it !is Failure) - throw AssertionError("Expected to fail with ${Failure::class}, but failed with $it") + throw AssertionError("Expected to fail with ${Failure::class}\nbut failed with $it") // else: successful case }, ifRight = { - throw AssertionError("Expected to fail with ${Failure::class}, but the operation was successful and returned $it") + throw AssertionError("Expected to fail with ${Failure::class}\nbut the operation was successful and returned $it") }, ) } diff --git a/compat/compat-arrow/src/commonTest/kotlin/EnsureRaisesTest.kt b/compat/compat-arrow/src/commonTest/kotlin/EnsureRaisesTest.kt index 1555eea..4780c61 100644 --- a/compat/compat-arrow/src/commonTest/kotlin/EnsureRaisesTest.kt +++ b/compat/compat-arrow/src/commonTest/kotlin/EnsureRaisesTest.kt @@ -37,7 +37,7 @@ val CheckRaisesTest by preparedSuite { 5 } } - check(e.message matches "Expected to fail with .*(Any|Object).*, but the operation was successful and returned 5") + check(e.message matches "Expected to fail with .*(Any|Object).*\nbut the operation was successful and returned 5") } test("Throws when the wrong thing is raised") { @@ -46,7 +46,7 @@ val CheckRaisesTest by preparedSuite { raise(6) } } - check(e.message matches "Expected to fail with 5, but failed with 6") + check(e.message matches "Expected to fail with 5\nbut failed with 6") } test("Throws when nothing is raised") { @@ -55,7 +55,7 @@ val CheckRaisesTest by preparedSuite { 5 } } - check(e.message matches "Expected to fail with .*(Any|Object).*, but the operation was successful and returned 5") + check(e.message matches "Expected to fail with .*(Any|Object).*\nbut the operation was successful and returned 5") } test("Throws when the wrong thing is raised") { @@ -64,7 +64,7 @@ val CheckRaisesTest by preparedSuite { raise(6) } } - check(e.message matches "Expected to fail with 5, but failed with 6") + check(e.message matches "Expected to fail with 5\nbut failed with 6") } } -- 2.51.2