Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More expressive error messages #36

Open
ujh opened this issue Sep 19, 2016 · 3 comments
Open

More expressive error messages #36

ujh opened this issue Sep 19, 2016 · 3 comments

Comments

@ujh
Copy link
Owner

ujh commented Sep 19, 2016

Enhance the error message format so that we can have a nicer error for the regular expression case. Right now it says:

Expected: \d
    but: was "abc"', src/core.rs:31

Something like Expected \d to match "abc" would be much nicer.

@joshburkart
Copy link

Great crate! I agree the messages could be improved a bit... I'm not sure that nice sentences can always be produced, though, without a large amount of effort... What if the example you mentioned produced the following instead?

Expected: MatchesRegex("\d")
     Got: "abc"

@joshburkart
Copy link

Also, in addition to perhaps tweaking how the matchers display themselves, one thought I had was to add a third (possibly optional) "Explanation" or "Details" section, in addition to "Expected" and "Got"... This might be nice in cases where it's not totally obvious why "expected" and "got" didn't match? For example, say we had a matcher for numerical vectors. It would be nice if the output of this:

let vector = vec![1., 1.000001, 0.99];
assert_that!(vector, is(almost_equal_to(1.).with_tol(1e-4)));

was perhaps

  Expected:   AlmostEqualTo(1., tol=1e-4)
       Got:   [1., 1.000001, 0.99]
   Details:   33% of values didn't match

Just thought I'd throw that out there...

@joshburkart
Copy link

The Swift Hamcrest implementation prints error messages like this:

assertThat(CGPoint(x: 5, y: 10), hasProperty("x", closeTo(5.0, 0.00001))) // ✓
assertThat(CGPoint(x: 5, y: 10), hasProperty("y", closeTo(0.0, 0.00001)))
// GOT: (5.0,10.0) (property value 10.0 (difference of 10.0)),
// EXPECTED: has property "y" with value within 1e-05 of 0.0

So the "explanation" is put in parentheses in the "Got" section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants