Skip to content

Commit

Permalink
Update isTrue/isFalse failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton authored and evant committed Oct 29, 2024
1 parent 89dcda1 commit 161b334
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions assertk/src/commonMain/kotlin/assertk/assertions/boolean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ 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 == true) return
fail(true, actual)
expected("to be true but was $actual")
}

/**
Expand All @@ -19,5 +18,5 @@ fun Assert<Boolean?>.isTrue() = given { actual ->
*/
fun Assert<Boolean?>.isFalse() = given { actual ->
if (actual == false) return
fail(false, actual)
expected("to be false but was $actual")
}
2 changes: 1 addition & 1 deletion assertk/src/commonTest/kotlin/test/assertk/TableTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class TableTest {
assertEquals(
"""The following assertion failed
|${"\t"}on row:(a=<false>)
|${"\t"}expected:<[tru]e> but was:<[fals]e>
|${"\t"}expected to be true but was false
""".trimMargin(),
error.message
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class BooleanTest {
val error = assertFailsWith<AssertionError> {
assertThat(false).isTrue()
}
assertEquals("expected:<[tru]e> but was:<[fals]e>", error.message)
assertEquals("expected to be true but was false", 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)
assertEquals("expected to be true but was null", error.message)
}
//endregion

Expand All @@ -42,15 +42,15 @@ class BooleanTest {
val error = assertFailsWith<AssertionError> {
assertThat(true).isFalse()
}
assertEquals("expected:<[fals]e> but was:<[tru]e>", error.message)
assertEquals("expected to be false but was true", 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)
assertEquals("expected to be false but was null", error.message)
}
//endregion
}

0 comments on commit 161b334

Please sign in to comment.