The MATCHER() and MATCHER_Pn() macros are convenient for creating new
matchers. They are much simpler to use than implementing
MatcherInterface directly. However, there's one thing that prevents a
matcher defined using MATCHER*() to be library-quality: the
description of the negation of the matcher doesn't look so nice.
For example, given:
MATCHER(IsEven, "") { return (arg % 2) == 0; }
the assertion
EXPECT_THAT(x, IsEven());
can print a message like:
Value of: x
Expected: is even
Actual: 5
which is good. However,
EXPECT_THAT(x, Not(IsEven()));
can print something like:
Value of: x
Expected: not (is even)
Actual: 6
The "not (is even)" message isn't as good as a custom-defined matcher
can generate ("is not even" or perhaps "is odd").
It will be a lot of hassle to implement MatcherInterface just so that
we can get a better negative description message. Therefore I propose
to extend the MATCHER* format string to allow (optionally) specifying
the negative description. One possible scheme is to use "%-" as the
divider for the positive and the negative descriptions:
MATCHER(IsEven, "is even%-is not even") { ... }
If either side of "%-" is empty, the default description will be used.
Therefore the above is equivalent to:
MATCHER(IsEven, "%-is not even") { ... }
(Note that we already reserve "%" as a meta character in MATCHER*'s
format spec string.)
Original issue reported on code.google.com by zhanyong...@gmail.com on 24 Aug 2009 at 6:13
Original issue reported on code.google.com by
zhanyong...@gmail.com
on 24 Aug 2009 at 6:13