From 28bc6de9894285085430ee7d5e5f15cf4544b802 Mon Sep 17 00:00:00 2001 From: Igor Sugak Date: Thu, 19 Mar 2015 17:32:43 -0700 Subject: [PATCH] rocksdb: print status error message when (ASSERT|EXPECT)_OK fails Summary: Modified rocksdb status assertions ASSERT_OK and EXPECT_OK to print error message from Status::ToString() when failed. Test Plan: Modify a test to fail status assertions ASSERT_OK and EXPECT_OK and notice an error message that came from Status::ToString() Reviewers: meyering, sdong, yhchiang, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D35469 --- util/testharness.cc | 9 +++++++++ util/testharness.h | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/util/testharness.cc b/util/testharness.cc index 96df1eb2e..603f6f6e1 100644 --- a/util/testharness.cc +++ b/util/testharness.cc @@ -13,6 +13,15 @@ namespace rocksdb { namespace test { +::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) { + if (s.ok()) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() << s_expr << std::endl + << s.ToString(); + } +} + std::string TmpDir(Env* env) { std::string dir; Status s = env->GetTestDirectory(&dir); diff --git a/util/testharness.h b/util/testharness.h index 1600ff3e1..b212b1e3a 100644 --- a/util/testharness.h +++ b/util/testharness.h @@ -25,10 +25,12 @@ std::string TmpDir(Env* env = Env::Default()); // runs may be able to vary the seed. int RandomSeed(); -#define ASSERT_OK(s) ASSERT_TRUE(((s).ok())) -#define ASSERT_NOK(s) ASSERT_FALSE(((s).ok())) -#define EXPECT_OK(s) EXPECT_TRUE(((s).ok())) -#define EXPECT_NOK(s) EXPECT_FALSE(((s).ok())) +::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s); + +#define ASSERT_OK(s) ASSERT_PRED_FORMAT1(rocksdb::test::AssertStatus, s) +#define ASSERT_NOK(s) ASSERT_FALSE((s).ok()) +#define EXPECT_OK(s) EXPECT_PRED_FORMAT1(rocksdb::test::AssertStatus, s) +#define EXPECT_NOK(s) EXPECT_FALSE((s).ok()) } // namespace test } // namespace rocksdb