]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3053] Added SKIP_IF to gtest_utils.h
authorThomas Markwalder <tmark@isc.org>
Thu, 14 Sep 2023 15:18:42 +0000 (11:18 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 15 Sep 2023 14:34:28 +0000 (14:34 +0000)
src/lib/testutils/gtest_utils.h
    Added macro SKIP_IF to work-around versions of googletest that
    do not have GTEST_SKIP

src/lib/testutils/gtest_utils.h

index e7b10b2812374c812af34badd3be340dd1f6434a..5801df442d0d0cb437a3ca6a565d42fe898323df 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2019-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -86,6 +86,34 @@ namespace test {
     } \
 } \
 
+/// @brief Skip a test without failure if the given expression is false.
+///
+/// SKIP_IF(exp) provides a means to exit a test without failing
+/// if the given expression is true.  This works around the lack of
+/// GTEST_SKIP prior to googletest 1.10.
+///
+/// @param expression logical expression to execute
+#ifndef GTEST_SKIP
+#define SKIP_IF(expression) \
+{ \
+    if (expression) { \
+        const auto info = ::testing::UnitTest::GetInstance()->current_test_info(); \
+        std::cerr << "SKIPPING: " << info->test_case_name() << ":" << info->name() \
+                  << ":" << #expression << " is true" << std::endl; \
+        return; \
+    } \
+}
+#else
+#define SKIP_IF(expression) \
+{ \
+    if (expression) { \
+        const auto info = ::testing::UnitTest::GetInstance()->current_test_info(); \
+        GTEST_SKIP() << "SKIPPING: " << info->test_case_name() << ":" << info->name() \
+                  << ":" << #expression << " is true"; \
+    } \
+}
+#endif
+
 }; // end of isc::test namespace
 }; // end of isc namespace