[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
Wed Sep 25 13:02:39 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372918: [libTooling][NFC] Switch StencilTest.cpp to use EXPECT_THAT_EXPECTED (authored by ymandel, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67973?vs=221561&id=221822#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67973/new/

https://reviews.llvm.org/D67973

Files:
  cfe/trunk/unittests/Tooling/StencilTest.cpp


Index: cfe/trunk/unittests/Tooling/StencilTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/StencilTest.cpp
+++ cfe/trunk/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.221822.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190925/adad79dc/attachment.bin>


More information about the cfe-commits mailing list