From: Fangrui Song Date: Wed, 14 Dec 2022 06:35:39 +0000 (+0000) Subject: [Testing/Support] llvm::Optional => std::optional X-Git-Tag: upstream/17.0.6~23907 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5bdf25bc38baf33eb354a3dfb6959dce0aa30a85;p=platform%2Fupstream%2Fllvm.git [Testing/Support] llvm::Optional => std::optional SupportHelpers.h supports both for now to ease migration. --- diff --git a/llvm/include/llvm/Testing/Support/Error.h b/llvm/include/llvm/Testing/Support/Error.h index 14bac9f..f6634d5 100644 --- a/llvm/include/llvm/Testing/Support/Error.h +++ b/llvm/include/llvm/Testing/Support/Error.h @@ -84,7 +84,7 @@ private: template class ErrorMatchesMono : public testing::MatcherInterface { public: - explicit ErrorMatchesMono(Optional> Matcher) + explicit ErrorMatchesMono(std::optional> Matcher) : Matcher(std::move(Matcher)) {} bool MatchAndExplain(const ErrorHolder &Holder, @@ -126,7 +126,7 @@ public: } private: - Optional> Matcher; + std::optional> Matcher; }; class ErrorMessageMatches diff --git a/llvm/include/llvm/Testing/Support/SupportHelpers.h b/llvm/include/llvm/Testing/Support/SupportHelpers.h index 2745e06..afcad6f 100644 --- a/llvm/include/llvm/Testing/Support/SupportHelpers.h +++ b/llvm/include/llvm/Testing/Support/SupportHelpers.h @@ -64,18 +64,24 @@ public: : ValueMatcher(ValueMatcher) {} template - operator ::testing::Matcher &>() const { + operator ::testing::Matcher &>() const { return ::testing::MakeMatcher( new Impl(::testing::SafeMatcherCast(ValueMatcher))); } template - class Impl : public ::testing::MatcherInterface &> { + operator ::testing::Matcher &>() const { + return ::testing::MakeMatcher( + new Impl>(::testing::SafeMatcherCast(ValueMatcher))); + } + + template > + class Impl : public ::testing::MatcherInterface { public: explicit Impl(const ::testing::Matcher &ValueMatcher) : ValueMatcher(ValueMatcher) {} - bool MatchAndExplain(const llvm::Optional &Input, + bool MatchAndExplain(const O &Input, testing::MatchResultListener *L) const override { return Input && ValueMatcher.MatchAndExplain(*Input, L); } @@ -98,7 +104,7 @@ private: }; } // namespace detail -/// Matches an llvm::Optional with a value that conforms to an inner matcher. +/// Matches an std::optional with a value that conforms to an inner matcher. /// To match std::nullopt you could use Eq(std::nullopt). template detail::ValueIsMatcher ValueIs(const InnerMatcher &ValueMatcher) { diff --git a/llvm/lib/Testing/Support/Annotations.cpp b/llvm/lib/Testing/Support/Annotations.cpp index 0f9fcfe..16b57cb 100644 --- a/llvm/lib/Testing/Support/Annotations.cpp +++ b/llvm/lib/Testing/Support/Annotations.cpp @@ -27,8 +27,8 @@ Annotations::Annotations(llvm::StringRef Text) { auto Require = [Text](bool Assertion, const char *Msg) { require(Assertion, Msg, Text); }; - llvm::Optional Name; - llvm::Optional Payload; + std::optional Name; + std::optional Payload; llvm::SmallVector OpenRanges; Code.reserve(Text.size()); diff --git a/llvm/unittests/Support/MatchersTest.cpp b/llvm/unittests/Support/MatchersTest.cpp index d07e82d9..d7d638a 100644 --- a/llvm/unittests/Support/MatchersTest.cpp +++ b/llvm/unittests/Support/MatchersTest.cpp @@ -18,8 +18,8 @@ using ::testing::Not; namespace { TEST(MatchersTest, Optional) { - EXPECT_THAT(llvm::Optional(std::nullopt), Not(llvm::ValueIs(_))); - EXPECT_THAT(llvm::Optional(10), llvm::ValueIs(10)); - EXPECT_THAT(llvm::Optional(10), llvm::ValueIs(AllOf(Lt(11), Gt(9)))); + EXPECT_THAT(std::optional(std::nullopt), Not(llvm::ValueIs(_))); + EXPECT_THAT(std::optional(10), llvm::ValueIs(10)); + EXPECT_THAT(std::optional(10), llvm::ValueIs(AllOf(Lt(11), Gt(9)))); } } // namespace