venantius / ultra

A Leiningen plugin for a superior development environment
Eclipse Public License 1.0
1.24k stars 35 forks source link

Better test reporting for logical expressions #58

Closed timothypratley closed 8 years ago

timothypratley commented 8 years ago

Instead of opaque failures: expected: (and (:name pirate) (or (empty? pirate) (:age pirate))) actual: nil

See what part of the logical expression does not meet your expectation: expected: (and (:name pirate) (or (empty? pirate) (:age pirate))) actual: (not (and "Edward Teach" (or false nil)))

image

venantius commented 8 years ago

I gave this some thought and I'm not sure I want it as the displayed value in the expected output. In the particular case of and, it's instructive to know that it actually evaluated to nil. I'd be open to having this sort of thing be provided as a hint though, akin to how Ultra offers hints for vector and list comparisons.

timothypratley commented 8 years ago

Good idea. Using a separate output is much clearer as it removes the need for negation. I've updated the pull request.

expected: (and (:name pirate) (or (empty? pirate) (:age pirate)))
  actual: nil

  values: (and "Edward Teach" (or false nil))

Also, it provides a pleasing solution to predicates:

expected: (odd? (+ 1 (inc 0)))
  actual: false

  values: (odd? 2)

Which is much better than the default behavior (not (odd? (+ 1 (inc 0)))) just wrapping a not around does not help the user at all, but seeing the actual and values is very clear.

venantius commented 8 years ago

Awesome, thanks.