mettle icon indicating copy to clipboard operation
mettle copied to clipboard

Combinatoric matchers produce confusing output in some cases

Open jimporter opened this issue 5 years ago • 0 comments

If you use a combinatoric matcher (e.g. all) and one of the sub-matchers returns a match_result that causes the matcher to fail, the "actual" value reported is whatever that match_result declared. This is generally wrong, since that value is probably only relevant to one of the sub-matchers, and doesn't show the entire value. For example:

struct thing {
  std::string name;
  std::vector<int> values;
};

expect(thing, all(
  filter([](thing &x) { return x.name; }, equal_to("name")),
  filter([](thing &x) { return x.values}, array(1, 2, 3))
));

This might print:

    expected: all of("name", [1, 2, 3])
    actual:   "bad"

The easy way to fix this would be for combinatoric matchers to return bools all the time, so that the full object is printed. However, there might be a better way that lets us see all the match_results. Maybe we should stop short-circuiting the combinatoric matchers too?

jimporter avatar Sep 02 '20 04:09 jimporter