Repository: willowtreeapps/assertk (kotlin)

Issue:
Relax bounds of built-in value-asserting functions.
I'm migrating a couple thousand test cases from Truth, and another thing that is coming up similar to https://github.com/willowtreeapps/assertk/issues/393#issuecomment-2428206350 is that calls to `isTrue()` need to become `isNotNull().isTrue()` on nullable subjects. In general this makes sense! However, the fact that I can call `.isEqualTo(true)` _without_ the `isNotNull()` check just feels bad. It's shorter! Why wouldn't I _always_ then do that?

I fully understand and am justifying calls to `isNotNull()` before things like `startsWith()` which operate on the actual value and therefore need to null-check it first. But `isTrue()` and `isFalse()` seem like they should be equivalent to `isEqualTo(true)` and `isEqualTo(false)`, just maybe with a better message. That makes me think they should operate on `Boolean?` and not just `Boolean`.

Pull request:
This behavior brings it more line with how '==' behaves in the language.

Closes #550.

Patch:
diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/boolean.kt b/assertk/src/commonMain/kotlin/assertk/assertions/boolean.kt
index bc07d790..90545767 100644
--- a/assertk/src/commonMain/kotlin/assertk/assertions/boolean.kt
+++ b/assertk/src/commonMain/kotlin/assertk/assertions/boolean.kt
@@ -2,21 +2,22 @@ package assertk.assertions
 
 import assertk.Assert
 import assertk.assertions.support.expected
+import assertk.assertions.support.fail
 
 /**
  * Asserts the boolean is true.
  * @see [isFalse]
  */
-fun Assert<Boolean>.isTrue() = given { actual ->
-    if (actual) return
-    expected("to be true")
+fun Assert<Boolean?>.isTrue() = given { actual ->
+    if (actual == true) return
+    fail(true, actual)
 }
 
 /**
  * Asserts the boolean is false.
  * @see [isTrue]
  */
-fun Assert<Boolean>.isFalse() = given { actual ->
-    if (!actual) return
-    expected("to be false")
+fun Assert<Boolean?>.isFalse() = given { actual ->
+    if (actual == false) return
+    fail(false, actual)
 }


Test patch:
diff --git a/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt
index bc62282a..c93e8aa9 100644
--- a/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt
+++ b/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt
@@ -88,7 +88,7 @@ class TableTest {
         assertEquals(
             """The following assertion failed
 	          |${"\t"}on row:(a=<false>)
-	          |${"\t"}expected to be true
+	          |${"\t"}expected:<[tru]e> but was:<[fals]e>
             """.trimMargin(),
             error.message
         )
diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt
index e811d1e5..50ccf477 100644
--- a/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt
+++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt
@@ -19,7 +19,15 @@ class BooleanTest {
         val error = assertFailsWith<AssertionError> {
             assertThat(false).isTrue()
         }
-        assertEquals("expected to be true", error.message)
+        assertEquals("expected:<[tru]e> but was:<[fals]e>", error.message)
+    }
+
+    @Test
+    fun isTrue_null_value_fails() {
+        val error = assertFailsWith<AssertionError> {
+            assertThat(null as Boolean?).isTrue()
+        }
+        assertEquals("expected:<true> but was:<null>", error.message)
     }
     //endregion
 
@@ -34,7 +42,15 @@ class BooleanTest {
         val error = assertFailsWith<AssertionError> {
             assertThat(true).isFalse()
         }
-        assertEquals("expected to be false", error.message)
+        assertEquals("expected:<[fals]e> but was:<[tru]e>", error.message)
+    }
+
+    @Test
+    fun isFalse_null_value_fails() {
+        val error = assertFailsWith<AssertionError> {
+            assertThat(null as Boolean?).isFalse()
+        }
+        assertEquals("expected:<false> but was:<null>", error.message)
     }
     //endregion
 }