From c7afbb34584af3292ee3f44b35d916075c64080f Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 14 Aug 2024 00:51:08 -0400 Subject: [PATCH] testing ASSERT_OK and ASSERT_OK_AND_ASSIGN macros --- src/test/core/testing.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/core/testing.h b/src/test/core/testing.h index 1a878f9b..b1577256 100644 --- a/src/test/core/testing.h +++ b/src/test/core/testing.h @@ -9,11 +9,21 @@ #define EXPECT_OK(expr) EXPECT_EQ((expr), absl::OkStatus()) +#define ASSERT_OK(expr) ASSERT_EQ((expr), absl::OkStatus()) + +#define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \ + if (auto rexpr_value = (rexpr); rexpr_value.ok()) { \ + lhs = std::move(rexpr_value).value(); \ + } else { \ + FAIL() << "error: " << rexpr_value.status(); \ + } + namespace yaze { namespace test { // StatusIs is a matcher that matches a status that has the same code and // message as the expected status. +MATCHER_P(StatusIs, status, "") { return arg.code() == status; } MATCHER_P(StatusIs, status, "") { return arg.code() == status; }