assert-rs / predicates-rs

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

Show faulty line in DifferencePredicate #112

Closed Chewie closed 3 years ago

Chewie commented 3 years ago

Heya,

The regular assert_eq! macro provides the line containing the assert in its output:

thread 'main' panicked at 'assertion failed:  `(left == right)`
  left: `4`,
 right: `2`, tests/test.rs:112:5

This information can be parsed by editors like Vim to fill the quickfix list automatically and jump to the error, which is very helpful.

Unfortunately, the DifferencePredicate doesn't show this information:

---- test_no_yaml stdout ----
thread 'main' panicked at 'Unexpected stdout, failed diff var original
├── original: No test case found. Exuting.

├── diff: 
--- value   expected
+++ value   actual
@@ -1 +1 @@
-No test case found. Exuting.
+No test case found. Exiting.

└── var as str: No test case found. Exiting.

Would it be possible to add this information to the output?

Chewie commented 3 years ago

I've been playing with similar and it's companion similar-asserts as a replacement of differences.rs, and the result is very clean. Maybe the predicate could make use of this crate?

epage commented 3 years ago

This crate aims to be the low level mechanism for implementing crates like that, like assert_that or assert_cmd.

To get this functionality, it either needs to come via a macro or the recent https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1460-2020-08-27 attribute

For my crates, I've created https://github.com/assert-rs/assert_cmd/issues/133 and https://github.com/assert-rs/assert_fs/issues/68