Author: ymandel Date: Wed Sep 25 13:04:25 2019 New Revision: 372918 URL: http://llvm.org/viewvc/llvm-project?rev=372918&view=rev Log: [libTooling][NFC] Switch StencilTest.cpp to use EXPECT_THAT_EXPECTED
Summary: Currently, some tests use homegrown matchers to handle `llvm::Expected` values. This revision standardizes on EXPECT_THAT_EXPECTED and `HasValue`. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67973 Modified: cfe/trunk/unittests/Tooling/StencilTest.cpp Modified: cfe/trunk/unittests/Tooling/StencilTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/StencilTest.cpp?rev=372918&r1=372917&r2=372918&view=diff ============================================================================== --- cfe/trunk/unittests/Tooling/StencilTest.cpp (original) +++ cfe/trunk/unittests/Tooling/StencilTest.cpp Wed Sep 25 13:04:25 2019 @@ -31,23 +31,6 @@ using stencil::dPrint; 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 @@ TEST_F(StencilTest, SingleStatement) { // 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 @@ TEST_F(StencilTest, SingleStatementCallO // 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits