[PATCH] D67973: [libTooling][NFC] Switch StencilTest.cpp to use EXPECT_THAT_EXPECTED
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 24 10:41:09 PDT 2019
ymandel created this revision.
ymandel added a reviewer: ilya-biryukov.
Herald added a project: clang.
Currently, some tests use homegrown matchers to handle `llvm::Expected`
values. This revision standardizes on EXPECT_THAT_EXPECTED and `HasValue`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67973
Files:
clang/unittests/Tooling/StencilTest.cpp
Index: clang/unittests/Tooling/StencilTest.cpp
===================================================================
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -31,23 +31,6 @@
using stencil::ifBound;
using stencil::text;
-// In tests, we can't directly match on llvm::Expected since its accessors
-// mutate the object. So, we collapse it to an Optional.
-static llvm::Optional<std::string> toOptional(llvm::Expected<std::string> V) {
- if (V)
- return *V;
- ADD_FAILURE() << "Losing error in conversion to IsSomething: "
- << llvm::toString(V.takeError());
- return llvm::None;
-}
-
-// A very simple matcher for llvm::Optional values.
-MATCHER_P(IsSomething, ValueMatcher, "") {
- if (!arg)
- return false;
- return ::testing::ExplainMatchResult(ValueMatcher, *arg, result_listener);
-}
-
// Create a valid translation-unit from a statement.
static std::string wrapSnippet(StringRef StatementCode) {
return ("struct S { int field; }; auto stencil_test_snippet = []{" +
@@ -151,8 +134,8 @@
// Invert the if-then-else.
auto Stencil = cat("if (!", node(Condition), ") ", statement(Else), " else ",
statement(Then));
- EXPECT_THAT(toOptional(Stencil.eval(StmtMatch->Result)),
- IsSomething(Eq("if (!true) return 0; else return 1;")));
+ EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result),
+ HasValue("if (!true) return 0; else return 1;"));
}
TEST_F(StencilTest, SingleStatementCallOperator) {
@@ -170,8 +153,8 @@
// Invert the if-then-else.
Stencil S = cat("if (!", node(Condition), ") ", statement(Else), " else ",
statement(Then));
- EXPECT_THAT(toOptional(S(StmtMatch->Result)),
- IsSomething(Eq("if (!true) return 0; else return 1;")));
+ EXPECT_THAT_EXPECTED(S(StmtMatch->Result),
+ HasValue("if (!true) return 0; else return 1;"));
}
TEST_F(StencilTest, UnboundNode) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67973.221561.patch
Type: text/x-patch
Size: 1992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190924/af86b5ed/attachment.bin>
More information about the cfe-commits
mailing list