[all-commits] [llvm/llvm-project] b55c58: [Error/unittests] Add a FailedWithMessage gtest ma...
Pavel Labath via All-commits
all-commits at lists.llvm.org
Fri Feb 21 06:29:55 PST 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: b55c58a2d569f2d92333b05c1a7a00114d75e0a6
https://github.com/llvm/llvm-project/commit/b55c58a2d569f2d92333b05c1a7a00114d75e0a6
Author: Pavel Labath <pavel at labath.sk>
Date: 2020-02-21 (Fri, 21 Feb 2020)
Changed paths:
M llvm/include/llvm/Testing/Support/Error.h
M llvm/unittests/Support/ErrorTest.cpp
Log Message:
-----------
[Error/unittests] Add a FailedWithMessage gtest matcher
Summary:
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.
Reviewers: sammccall, dblaikie, jhenderson
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74898
More information about the All-commits
mailing list