As a newcomer to Rust, I'm happy to see a built-in test runner (cargo test
), but I'm used to better assertion output in other languages.
Consider this assertion:
debug_assert_eq!(vec![1, 2, 3], vec![1, 2, 4]);
which produces this output:
thread ‘tests::derp::test_vector_match’ panicked at ‘assertion failed: `(left == right)` (left: `[1, 2, 3]`, right: `[1, 2, 4]`)’, src/lib.rs:10
That's not great. A few specific problems:
- The part I care about is far to the right.
- If the expected and actual values were on separate lines they could be aligned horizontally for better visual diffing.
- The output is all one color. Cargo uses green and red above for passing/failing tests, so it seems like some color could be used here too, to make the failed assertion stand out.
I'd like to see something like this:
thread ‘tests::derp::test_vector_match’ panicked at ‘assertion failed: (left == right)
expected: [1, 2, 3]
actual: [1, 2, 4]
in src/lib.rs:10
I'd be happy to use a library for this, the solution doesn't have to be in Rust itself.
PS: I would have liked to ask this Q on stackoverflow, but it could be construed as a request for library suggestions, which is not allowed there.
PPS: For an unfair comparison to RSpec, see this blog post: The output of unit tests in Rust could be better | by Jared Beck | Medium