[PATCH] D74898: [Error/unittests] Add a FailedWithMessage gtest matcher

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 06:40:00 PST 2020


labath created this revision.
labath added reviewers: sammccall, dblaikie, jhenderson.
Herald added a project: LLVM.
labath added a child revision: D74899: Use new FailedWithMessage matcher in DWARFDebugLineTest.cpp.
labath added a comment.

You can take a look at D74899 <https://reviews.llvm.org/D74899> to see how this would look in action. I've converted one file with a very complex set of error assertions to ensure that this can handle a variety of use cases.


We already have a "Failed" matcher, which can be used to check any
property of the Error object. However, most frequently one just wants to
check the error message, and while this is possible with the "Failed"
matcher, it is also very convoluted
(Failed<ErrorInfoBase>(testing::Property(&ErrorInfoBase::message, "the
message"))).

Now, one can just write: FailedWithMessage("the message"). I expect that
most of the usages will remain this simple, but the argument of the
matcher is not limited to simple strings -- the argument of the matcher
can be any other matcher, so one can write more complicated assertions
if needed (FailedWithMessage(ContainsRegex("foo|bar"))). If one wants to
match multiple error messages, he can pass multiple arguments to the
matcher.

If one wants to match the message list as a whole (perhaps to check the
message count), I've also included a FailedWithMessageArray matcher,
which takes a single matcher receiving a vector of error message
strings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74898

Files:
  llvm/include/llvm/Testing/Support/Error.h
  llvm/unittests/Support/ErrorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74898.245636.patch
Type: text/x-patch
Size: 4228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200220/018908f4/attachment.bin>


More information about the llvm-commits mailing list