predicates-rs icon indicating copy to clipboard operation
predicates-rs copied to clipboard

Output from predicates can be overwhelming with large buffers

Open epage opened this issue 4 years ago • 7 comments

See https://github.com/assert-rs/assert_cmd/issues/121 for an example

The main question is how to resolve this in a way that is what people expect and works for them.

epage avatar May 27 '21 21:05 epage

I think having a cut off limit with an env variable should do the trick

epage avatar May 27 '21 21:05 epage

Putting my suggestion from the linked issue here too -- in the case of a large buffer, it may make sense to indent the whole thing slightly, so it stands out from the actual assertions.

Something like:

expected:
  some multiline output
  indented with
  2 spaces

While skimming through the output, it becomes easy to spot the error messages and differentiate them from the printed buffer.

ajeetdsouza avatar May 27 '21 21:05 ajeetdsouza

This is dependent on the library we use for the tree view because we don't know our indentation level.

We use treeline which doesn't have much activity https://lib.rs/crates/treeline

ptree also exists but seems a bit ... heavy weight https://lib.rs/crates/ptree

I'm assuming we'd reach out to treeline and, if they don't respond, will fork it.

epage avatar May 29 '21 20:05 epage

Before I forget, one downside of indenting everything, especially if the tree continues through that indentaton, is its a bit messier to take the output and copy/paste it somewhere.

epage avatar May 29 '21 21:05 epage

Perhaps you could output the tree as YAML? YAML has multiline strings, indentation, and is both user and machine readable.

ajeetdsouza avatar May 29 '21 21:05 ajeetdsouza

Its an interesting idea. The main problem is having a yaml generator that gives me control over formatting. Toml ones exist but its harder to find them for Yaml.

For example, with yaml-rust (the core of serde-yaml)

foo:
  bar:
    - 1
    - 2
    - 3
  word: |
    Hello
    World
    How
    Are
    You

Became

---
foo:
  bar:
    - 1
    - 2
    - 3
  word: "Hello\nWorld\nHow\nAre\nYou"

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cd4864755fcd4ef8912ea207d98b0c45

epage avatar May 30 '21 00:05 epage

You're right, Rust's YAML support is lacking. If we do this, we'll likely have to do the encoding ourselves.

ajeetdsouza avatar Jun 01 '21 18:06 ajeetdsouza