You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2016/08/14 04:20:38 UTC
[3/3] kudu git commit: Add regex string match assert helper macros
Add regex string match assert helper macros
These delegate to gmock but are easier to remember than:
ASSERT_THAT(str, testing::ContainsRegex(pattern))
Change-Id: I05d869479f4032d584a83b455979073c7707d9e7
Reviewed-on: http://gerrit.cloudera.org:8080/3962
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/bcc4bbf1
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/bcc4bbf1
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/bcc4bbf1
Branch: refs/heads/master
Commit: bcc4bbf1c8584d547602b02e380c151f71e3b42e
Parents: b489f6e
Author: Mike Percy <mp...@apache.org>
Authored: Fri Aug 12 13:30:03 2016 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Sun Aug 14 04:19:59 2016 +0000
----------------------------------------------------------------------
src/kudu/util/test_macros.h | 64 +++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/bcc4bbf1/src/kudu/util/test_macros.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_macros.h b/src/kudu/util/test_macros.h
index 8ef7af5..e7950a9 100644
--- a/src/kudu/util/test_macros.h
+++ b/src/kudu/util/test_macros.h
@@ -17,37 +17,38 @@
#ifndef KUDU_UTIL_TEST_MACROS_H
#define KUDU_UTIL_TEST_MACROS_H
+#include <gmock/gmock.h>
#include <string>
// ASSERT_NO_FATAL_FAILURE is just too long to type.
#define NO_FATALS ASSERT_NO_FATAL_FAILURE
#define ASSERT_OK(status) do { \
- Status _s = status; \
- if (_s.ok()) { \
- SUCCEED(); \
- } else { \
- FAIL() << "Bad status: " << _s.ToString(); \
- } \
- } while (0);
+ Status _s = status; \
+ if (_s.ok()) { \
+ SUCCEED(); \
+ } else { \
+ FAIL() << "Bad status: " << _s.ToString(); \
+ } \
+} while (0);
#define EXPECT_OK(status) do { \
- Status _s = status; \
- if (_s.ok()) { \
- SUCCEED(); \
- } else { \
- ADD_FAILURE() << "Bad status: " << _s.ToString(); \
- } \
- } while (0);
+ Status _s = status; \
+ if (_s.ok()) { \
+ SUCCEED(); \
+ } else { \
+ ADD_FAILURE() << "Bad status: " << _s.ToString(); \
+ } \
+} while (0);
// Like the above, but doesn't record successful
// tests.
-#define ASSERT_OK_FAST(status) do { \
- Status _s = status; \
- if (!_s.ok()) { \
- FAIL() << "Bad status: " << _s.ToString(); \
- } \
- } while (0);
+#define ASSERT_OK_FAST(status) do { \
+ Status _s = status; \
+ if (!_s.ok()) { \
+ FAIL() << "Bad status: " << _s.ToString(); \
+ } \
+} while (0);
#define ASSERT_STR_CONTAINS(str, substr) do { \
std::string _s = (str); \
@@ -55,19 +56,36 @@
FAIL() << "Expected to find substring '" << (substr) \
<< "'. Got: '" << _s << "'"; \
} \
- } while (0);
+} while (0);
+
+// Substring regular expressions in extended regex (POSIX) syntax.
+#define ASSERT_STR_MATCHES(str, pattern) \
+ ASSERT_THAT(str, testing::ContainsRegex(pattern))
+
+// Batched substring regular expressions in extended regex (POSIX) syntax.
+#define ASSERT_STRINGS_MATCH(strings, pattern) do { \
+ const auto& _strings = (strings); \
+ const auto& _pattern = (pattern); \
+ int _str_idx = 0; \
+ for (const auto& str : _strings) { \
+ ASSERT_STR_MATCHES(str, _pattern) \
+ << "string " << _str_idx << ": pattern " << _pattern \
+ << " does not match string " << str; \
+ _str_idx++; \
+ } \
+} while (0)
#define ASSERT_FILE_EXISTS(env, path) do { \
std::string _s = path; \
ASSERT_TRUE(env->FileExists(_s)) \
<< "Expected file to exist: " << _s; \
- } while (0);
+} while (0);
#define ASSERT_FILE_NOT_EXISTS(env, path) do { \
std::string _s = path; \
ASSERT_FALSE(env->FileExists(_s)) \
<< "Expected file not to exist: " << _s; \
- } while (0);
+} while (0);
#define CURRENT_TEST_NAME() \
::testing::UnitTest::GetInstance()->current_test_info()->name()