[clang-tools-extra] 824d2c9 - [NFC] [clang-tidy] [doc] document gtest support of statusor check (#180662)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 18 07:03:47 PST 2026


Author: Florian Mayer
Date: 2026-02-18T07:03:42-08:00
New Revision: 824d2c9b06a350ba0f5be96ac7bac893164d0299

URL: https://github.com/llvm/llvm-project/commit/824d2c9b06a350ba0f5be96ac7bac893164d0299
DIFF: https://github.com/llvm/llvm-project/commit/824d2c9b06a350ba0f5be96ac7bac893164d0299.diff

LOG: [NFC] [clang-tidy] [doc] document gtest support of statusor check (#180662)

Added: 
    

Modified: 
    clang-tools-extra/docs/clang-tidy/checks/abseil/unchecked-statusor-access.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/unchecked-statusor-access.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/unchecked-statusor-access.rst
index 8a766e8f6abe4..c56ff8c886e2c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/unchecked-statusor-access.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/unchecked-statusor-access.rst
@@ -93,7 +93,7 @@ known to have ok status. For example:
 Ensuring that the status is ok using common macros
 --------------------------------------------------
 
-The check is aware of common macros like ``ABSL_CHECK`` and ``ASSERT_THAT``.
+The check is aware of common macros like ``ABSL_CHECK`` or ``ABSL_CHECK_OK``.
 Those can be used to ensure that the status of a ``StatusOr<T>`` object
 is ok. For example:
 
@@ -104,6 +104,46 @@ is ok. For example:
      use(*x);
    }
 
+Ensuring that the status is ok using googletest macros
+------------------------------------------------------
+
+The check is aware of ``googletest`` (or ``gtest``) macros and matchers.
+Accessing the value of a ``StatusOr<T>`` object is considered safe if it
+is preceded by an ``ASSERT_`` macro that ensures the status is ok.
+For example:
+
+.. code:: cpp
+
+   TEST(MySuite, MyTest) {
+     absl::StatusOr<int> x = foo();
+     ASSERT_OK(x);
+     use(*x);
+   }
+
+   TEST(MySuite, MyOtherTest) {
+     absl::StatusOr<int> x = foo();
+     ASSERT_THAT(x, absl_testing::IsOk());
+     use(*x);
+   }
+
+The following ``googletest`` macros are supported:
+
+- ``ASSERT_OK(...)``
+- ``ASSERT_TRUE(...)``
+- ``ASSERT_FALSE(...)``
+- ``ASSERT_THAT(...)``
+
+The following matchers are supported:
+
+- ``IsOk()``
+- ``StatusIs(...)``
+- ``IsOkAndHolds(...)``
+- ``CanonicalStatusIs(...)``
+
+**Note**: ``EXPECT_`` macros (like ``EXPECT_OK`` or ``EXPECT_TRUE(x.ok())``)
+do **not** make subsequent accesses safe because they do not terminate the
+test execution.
+
 Ensuring that the status is ok, then accessing the value in a correlated branch
 -------------------------------------------------------------------------------
 


        


More information about the cfe-commits mailing list