Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

Custom output when RangeEquals fails

Open igtrnt opened this issue 2 years ago • 1 comments

Description I am comparing two arrays for point-wise equality and would like to have a simple custom error message. For instance, count of mismatched elements and a few first mismatches. How can this be achieved?

Additional context Currently I have the code below, and on error it dumps entire spans, and it's hard to see which elements do not match.

int n;
int* expected; // size [n]
int* result; // size [n]
REQUIRE_THAT(std::span(result, n), Catch::Matchers::RangeEquals(std::span(expected, n)));

igtrnt avatar Sep 23 '23 23:09 igtrnt

I was asking myself exactly the same question ! More generally, it would be good if this where possible for a home made matcher to change the error message upon failure. Currently both match and describe are supposed to be const.

hivert avatar Oct 29 '23 12:10 hivert