Skip to content

Combination of isEqualsTo not enforcing typing, error message not indicating explicit types, and transform/single not supporting show differences makes it really hard to diagnose some failures #566

@TheKeeperOfPie

Description

@TheKeeperOfPie

Consider an Okio FakeFileSystem where I'm asserting the presence of a file. In the failing case, I want it to print what files were actually on the filesystem. I'm achieving that by using assertThat(fakeFileSystem.allPaths) + transform, so that the error prints allPaths while asserting on the actual files.

My full assertion is

assertThat(fakeFileSystem.allPaths)
  .transform { it.filter { fakeFileSystem.metadata(it).isRegularFile } }
  .single()
  .transform { it.relativeTo("/".toPath()) }
  .isEqualTo("grandparent/parent/actualFile.json")

with the error message being

expected [single]:<["grandparent/parent/actualFile.json"]> but was:<[grandparent/parent/actualFile.json]> ([/grandparent, /grandparent/parent, /grandparent/parent/actualFile.json])
org.opentest4j.AssertionFailedError: expected [single]:<["grandparentparent/actualFile.json"]> but was:<[grandparentparent/actualFile.json]> ([/grandparent, /grandparentparent, /grandparentparent/actualFile.json])
	at app//com.example.ExampleTest$test$1.invokeSuspend(ExampleTest.kt:150)
        ...

It took me a long time to understand that expected [single]:<["grandparent/parent/actualFile.json"]> but was <[grandparent/parent/actualFile.json]> differs by the double quotes, meaning the type is different and that I'm actually passing a string inside of an Okio Path object.

This is compounded by the fact that I'm new to the library and thus not used to looking for quote difference, and that there's no "show differences" option here like a plain assert. Not sure if anything can be done since Assert is out T, but this is a really easy mistake to make and very difficult to understand what went wrong.

Due to the signal of isEqualsTo, I sorta just assumed during debugging that it wasn't a typing issue, since I did not expect out T, and that lead me to chasing a lot of red herrings rather than the actual problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions