Skip to content

Multiline-friendly toString() #730

@cpovirk

Description

@cpovirk

One of the things we did in Truth a while back was to print values differently if they contain newlines. So, for example, you would see:

expected: foo
but was : bar

But you'd see:

expected:
    public class Foo {
      Foo() {}
    }
but was:
    public class Bar {
      Bar() {}
    }

I would speculate (but it's just speculation) that this might be a nice feature for AutoValue toString() implementations, too.

(Even in the case in which fields aren't multiline, a multiline toString() can be nice in some cases: I think Truth has gotten reports that AutoValue toString() (like, to be fair, almost all toString() implementations) makes it hard to see which field differs when there are a lot of fields. But of course one-line toString() is nice in plenty of cases, too, so I wouldn't advocate for always going multiline (nor, probably, for making it configurable). It's just a nice additional advantage in the cases in which multiline is already justified.)

(It's also possible that Truth should have more special handling of AutoValue types in some cases.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions