https://kotlinlang.org logo
#kotest
Title
# kotest
m

mat

12/11/2023, 10:02 PM
Hey all, how do I force kotest to show ' characters around strings in failure output? I'm dealing with strings that can have several newlines at the end. For example:
s

sam

12/12/2023, 2:29 AM
Something we need to improve really. The
Print
typeclass could do with an overhaul. PR?
m

mat

12/12/2023, 12:48 PM
I should be able to take a look at the code there this weekend at the latest. Could you explain what places I need to look at to change this?
s

sam

12/13/2023, 2:00 AM
If you look for the
interface Print
and then look at the implementations, that's what does it
👍 1
m

mat

12/14/2023, 5:57 PM
Alright, I have made a reproduction of the issue. Wil now try and find the cause:
Copy code
test("TestShouldBeEqual") {
        "test\n\n" shouldBeEqual "\n"
    }
    test("TestShouldBe") {
        "test\n\n" shouldBe "\n"
    }
The test that uses
shouldBe
shows a nice error message:
Copy code
io.kotest.assertions.AssertionFailedError: expected:<"
"> but was:<"test

">
The test that uses
shouldBeEqual
shows this worse error message:
Copy code
java.lang.AssertionError: test

 should be equal to 

	at FakeTest$1$1.invokeSuspend(FakeTest.kt:7)
Note how the nice error is from a kotest assertion, and the ugly one is from a java lang assertion. I believe that this is the cause.
I have found the implementation difference that causes this: In
shouldBe
, the
Matcher
system is used to print via the
Print
typeclass (Via
shouldBe
should
,
invokeMatcher
,
expected.print()
). In
shouldBeEqual
a MatcherResult is created directly using string interpolation. (eg:
"$value should be equal to $expected"
). This, of course, will not call upon the typeclass. I can make the change in the file, but I cannot figure out how to test these changes. I'll move to the dev channel to ask there and will report back here if I was successful.