assert-rs / predicates-rs

Boolean-valued predicate functions in Rust
docs.rs/predicates
Apache License 2.0
173 stars 29 forks source link

Output from predicates can be overwhelming with large buffers #106

Open epage opened 3 years ago

epage commented 3 years ago

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 commented 3 years ago

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

ajeetdsouza commented 3 years ago

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.

epage commented 3 years ago

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 commented 3 years ago

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.

ajeetdsouza commented 3 years ago

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

epage commented 3 years ago

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

ajeetdsouza commented 3 years ago

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